|
| 1 | +const ruleTester = require("../../ruletester"); |
| 2 | +import * as rule from "./tokens-warn"; |
| 3 | + |
| 4 | +const getWarnMessage = (tokenName: string) => |
| 5 | + `${tokenName} is an old CSS token. About half of our tokens have been replaced with newer ones. To find a suitable replacement token, check our new documentation https://staging-v6.patternfly.org/tokens/all-patternfly-tokens.`; |
| 6 | + |
| 7 | +ruleTester.run("tokens-warn", rule, { |
| 8 | + valid: [ |
| 9 | + // token existing in V6 |
| 10 | + { |
| 11 | + code: `import c_about_modal_box from '@patternfly/react-tokens/dist/esm/c_about_modal_box';`, |
| 12 | + }, |
| 13 | + // token existing in V6 |
| 14 | + { |
| 15 | + code: `import { c_about_modal_box } from '@patternfly/react-tokens';`, |
| 16 | + }, |
| 17 | + ], |
| 18 | + invalid: [ |
| 19 | + { |
| 20 | + code: `import { global_info_color_100 } from '@patternfly/react-tokens';`, |
| 21 | + output: `import { global_info_color_100 } from '@patternfly/react-tokens';`, |
| 22 | + errors: [ |
| 23 | + { |
| 24 | + message: getWarnMessage("global_info_color_100"), |
| 25 | + type: "ImportSpecifier", |
| 26 | + }, |
| 27 | + ], |
| 28 | + }, |
| 29 | + // with alias |
| 30 | + { |
| 31 | + code: `import { global_info_color_100 as infoColor } from '@patternfly/react-tokens';`, |
| 32 | + output: `import { global_info_color_100 as infoColor } from '@patternfly/react-tokens';`, |
| 33 | + errors: [ |
| 34 | + { |
| 35 | + message: getWarnMessage("global_info_color_100"), |
| 36 | + type: "ImportSpecifier", |
| 37 | + }, |
| 38 | + ], |
| 39 | + }, |
| 40 | + { |
| 41 | + // named import - esm |
| 42 | + code: `import { global_info_color_100 } from '@patternfly/react-tokens/dist/esm/global_info_color_100';`, |
| 43 | + output: `import { global_info_color_100 } from '@patternfly/react-tokens/dist/esm/global_info_color_100';`, |
| 44 | + errors: [ |
| 45 | + { |
| 46 | + message: getWarnMessage("global_info_color_100"), |
| 47 | + type: "ImportSpecifier", |
| 48 | + }, |
| 49 | + ], |
| 50 | + }, |
| 51 | + { |
| 52 | + // named import - js |
| 53 | + code: `import { global_info_color_100 } from '@patternfly/react-tokens/dist/js/global_info_color_100';`, |
| 54 | + output: `import { global_info_color_100 } from '@patternfly/react-tokens/dist/js/global_info_color_100';`, |
| 55 | + errors: [ |
| 56 | + { |
| 57 | + message: getWarnMessage("global_info_color_100"), |
| 58 | + type: "ImportSpecifier", |
| 59 | + }, |
| 60 | + ], |
| 61 | + }, |
| 62 | + { |
| 63 | + // default import - esm |
| 64 | + code: `import global_info_color_100 from '@patternfly/react-tokens/dist/esm/global_info_color_100';`, |
| 65 | + output: `import global_info_color_100 from '@patternfly/react-tokens/dist/esm/global_info_color_100';`, |
| 66 | + errors: [ |
| 67 | + { |
| 68 | + message: getWarnMessage("global_info_color_100"), |
| 69 | + type: "ImportDeclaration", |
| 70 | + }, |
| 71 | + ], |
| 72 | + }, |
| 73 | + { |
| 74 | + // default import - js |
| 75 | + code: `import global_info_color_100 from '@patternfly/react-tokens/dist/js/global_info_color_100';`, |
| 76 | + output: `import global_info_color_100 from '@patternfly/react-tokens/dist/js/global_info_color_100';`, |
| 77 | + errors: [ |
| 78 | + { |
| 79 | + message: getWarnMessage("global_info_color_100"), |
| 80 | + type: "ImportDeclaration", |
| 81 | + }, |
| 82 | + ], |
| 83 | + }, |
| 84 | + { |
| 85 | + // default import with custom name |
| 86 | + code: `import someToken from '@patternfly/react-tokens/dist/esm/global_info_color_100';`, |
| 87 | + output: `import someToken from '@patternfly/react-tokens/dist/esm/global_info_color_100';`, |
| 88 | + errors: [ |
| 89 | + { |
| 90 | + message: getWarnMessage("global_info_color_100"), |
| 91 | + type: "ImportDeclaration", |
| 92 | + }, |
| 93 | + ], |
| 94 | + }, |
| 95 | + ], |
| 96 | +}); |
0 commit comments