@primer/primitives 7.17.0-rc.086cd658 → 7.17.0-rc.61b28bca

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (133) hide show
  1. package/package.json +1 -1
  2. package/src/filters/isBorder.test.ts +18 -0
  3. package/src/filters/isColor.test.ts +22 -0
  4. package/src/filters/isColorWithAlpha.test.ts +34 -0
  5. package/src/filters/isColorWithMix.test.ts +108 -0
  6. package/src/filters/isDeprecated.test.ts +56 -0
  7. package/src/filters/isDimension.test.ts +22 -0
  8. package/src/filters/isDuration.test.ts +22 -0
  9. package/src/filters/isFontFamily.test.ts +22 -0
  10. package/src/filters/isFontWeight.test.ts +22 -0
  11. package/src/filters/isFromFile.test.ts +34 -0
  12. package/src/filters/isShadow.test.ts +18 -0
  13. package/src/filters/isSource.test.ts +44 -0
  14. package/src/filters/isTypography.test.ts +18 -0
  15. package/src/formats/cssCustomMedia.test.ts +11 -0
  16. package/src/formats/cssThemed.test.ts +87 -0
  17. package/src/formats/cssWrapMediaQuery.test.ts +170 -0
  18. package/src/formats/javascriptCommonJs.test.ts +43 -0
  19. package/src/formats/javascriptEsm.test.ts +41 -0
  20. package/src/formats/jsonNestedPrefixed.test.ts +73 -0
  21. package/src/formats/jsonOneDimensional.test.ts +56 -0
  22. package/src/formats/typescriptExportDefinition.test.ts +178 -0
  23. package/src/formats/utilities/jsonToFlat.test.ts +47 -0
  24. package/src/formats/utilities/jsonToNestedValue.test.ts +39 -0
  25. package/src/formats/utilities/prefixTokens.test.ts +38 -0
  26. package/src/parsers/w3cJsonParser.test.ts +35 -0
  27. package/src/schemas/alphaValueSchema.test.ts +24 -0
  28. package/src/schemas/baseTokenSchema.test.ts +17 -0
  29. package/src/schemas/borderTokenSchema.test.ts +53 -0
  30. package/src/schemas/collectionSchema.test.ts +58 -0
  31. package/src/schemas/colorHexValueSchema.test.ts +26 -0
  32. package/src/schemas/colorTokenSchema.test.ts +27 -0
  33. package/src/schemas/dimensionTokenSchema.test.ts +28 -0
  34. package/src/schemas/dimensionValueSchema.test.ts +21 -0
  35. package/src/schemas/durationTokenSchema.test.ts +58 -0
  36. package/src/schemas/durationValueSchema.test.ts +25 -0
  37. package/src/schemas/fontFamilyTokenSchema.test.ts +82 -0
  38. package/src/schemas/fontWeightTokenSchema.test.ts +88 -0
  39. package/src/schemas/fontWeightValue.test.ts +17 -0
  40. package/src/schemas/numberTokenSchema.test.ts +82 -0
  41. package/src/schemas/referenceValueSchema.test.ts +20 -0
  42. package/src/schemas/schema.test.ts +33 -0
  43. package/src/schemas/scopeTokenSchema.test.ts +29 -0
  44. package/src/schemas/shadowTokenSchema.test.ts +163 -0
  45. package/src/schemas/stringTokenSchema.test.ts +81 -0
  46. package/src/schemas/tokenNameSchema.test.ts +33 -0
  47. package/src/schemas/typographyTokenSchema.test.ts +58 -0
  48. package/src/schemas/validTokenTypeSchema.test.ts +32 -0
  49. package/src/schemas/viewportRangeTokenSchema.test.ts +59 -0
  50. package/src/transformers/borderToCss.test.ts +58 -0
  51. package/src/transformers/colorToHex.test.ts +27 -0
  52. package/src/transformers/colorToHexAlpha.test.ts +30 -0
  53. package/src/transformers/colorToHexMix.test.ts +83 -0
  54. package/src/transformers/colorToRgbAlpha.test.ts +33 -0
  55. package/src/transformers/colorToRgbaFloat.test.ts +168 -0
  56. package/src/transformers/dimensionToPixelUnitless.test.ts +93 -0
  57. package/src/transformers/dimensionToRem.test.ts +81 -0
  58. package/src/transformers/durationToCss.test.ts +56 -0
  59. package/src/transformers/fontFamilyToCss.test.ts +71 -0
  60. package/src/transformers/fontWeightToNumbers.test.ts +117 -0
  61. package/src/transformers/jsonDeprecated.test.ts +31 -0
  62. package/src/transformers/namePathToCamelCase.test.ts +74 -0
  63. package/src/transformers/namePathToDotNotation.test.ts +74 -0
  64. package/src/transformers/namePathToFigma.test.ts +74 -0
  65. package/src/transformers/namePathToKebabCase.test.ts +74 -0
  66. package/src/transformers/namePathToSlashNotation.test.ts +74 -0
  67. package/src/transformers/shadowToCss.test.ts +175 -0
  68. package/src/transformers/typographyToCss.test.ts +164 -0
  69. package/src/transformers/utilities/alpha.test.ts +28 -0
  70. package/src/transformers/utilities/checkRequiredTokenProperties.test.ts +28 -0
  71. package/src/transformers/utilities/getTokenValue.test.ts +18 -0
  72. package/src/transformers/utilities/hexToRgbaFloat.test.ts +66 -0
  73. package/src/transformers/utilities/invalidTokenError.test.ts +21 -0
  74. package/src/transformers/utilities/isRgbaFloat.test.ts +20 -0
  75. package/src/transformers/utilities/rgbaFloatToHex.test.ts +16 -0
  76. package/src/utilities/getFlag.test.ts +31 -0
  77. package/src/utilities/joinFriendly.test.ts +15 -0
  78. package/src/utilities/toCamelCase.test.ts +27 -0
  79. package/src/utilities/treeWalker.test.ts +51 -0
  80. package/src/utilities/upperCaseFirstCharacter.test.ts +19 -0
  81. package/tokens-v2-private/css/tokens/base/size/size.css +1 -1
  82. package/tokens-v2-private/css/tokens/base/typography/typography.css +1 -1
  83. package/tokens-v2-private/css/tokens/functional/size/border.css +1 -1
  84. package/tokens-v2-private/css/tokens/functional/size/breakpoints.css +1 -1
  85. package/tokens-v2-private/css/tokens/functional/size/size-coarse.css +1 -1
  86. package/tokens-v2-private/css/tokens/functional/size/size-fine.css +1 -1
  87. package/tokens-v2-private/css/tokens/functional/size/size.css +1 -1
  88. package/tokens-v2-private/css/tokens/functional/typography/typography.css +1 -1
  89. package/tokens-v2-private/js/module/tokens/base/size/size.js +1 -1
  90. package/tokens-v2-private/js/module/tokens/base/typography/typography.js +1 -1
  91. package/tokens-v2-private/js/module/tokens/functional/size/border.js +1 -1
  92. package/tokens-v2-private/js/module/tokens/functional/size/breakpoints.js +1 -1
  93. package/tokens-v2-private/js/module/tokens/functional/size/size-coarse.js +1 -1
  94. package/tokens-v2-private/js/module/tokens/functional/size/size-fine.js +1 -1
  95. package/tokens-v2-private/js/module/tokens/functional/size/size.js +1 -1
  96. package/tokens-v2-private/js/module/tokens/functional/size/viewport.js +1 -1
  97. package/tokens-v2-private/js/module/tokens/functional/typography/typography.js +1 -1
  98. package/tokens-v2-private/js/tokens/base/size/size.js +1 -1
  99. package/tokens-v2-private/js/tokens/base/typography/typography.js +1 -1
  100. package/tokens-v2-private/js/tokens/functional/size/border.js +1 -1
  101. package/tokens-v2-private/js/tokens/functional/size/breakpoints.js +1 -1
  102. package/tokens-v2-private/js/tokens/functional/size/size-coarse.js +1 -1
  103. package/tokens-v2-private/js/tokens/functional/size/size-fine.js +1 -1
  104. package/tokens-v2-private/js/tokens/functional/size/size.js +1 -1
  105. package/tokens-v2-private/js/tokens/functional/size/viewport.js +1 -1
  106. package/tokens-v2-private/js/tokens/functional/typography/typography.js +1 -1
  107. package/tokens-v2-private/scss/tokens/base/size/size.scss +1 -1
  108. package/tokens-v2-private/scss/tokens/base/typography/typography.scss +1 -1
  109. package/tokens-v2-private/scss/tokens/functional/size/border.scss +1 -1
  110. package/tokens-v2-private/scss/tokens/functional/size/breakpoints.scss +1 -1
  111. package/tokens-v2-private/scss/tokens/functional/size/size-coarse.scss +1 -1
  112. package/tokens-v2-private/scss/tokens/functional/size/size-fine.scss +1 -1
  113. package/tokens-v2-private/scss/tokens/functional/size/size.scss +1 -1
  114. package/tokens-v2-private/scss/tokens/functional/size/viewport.scss +1 -1
  115. package/tokens-v2-private/scss/tokens/functional/typography/typography.scss +1 -1
  116. package/tokens-v2-private/ts/tokens/base/size/size.d.ts +1 -1
  117. package/tokens-v2-private/ts/tokens/base/size/size.js +1 -1
  118. package/tokens-v2-private/ts/tokens/base/typography/typography.d.ts +1 -1
  119. package/tokens-v2-private/ts/tokens/base/typography/typography.js +1 -1
  120. package/tokens-v2-private/ts/tokens/functional/size/border.d.ts +1 -1
  121. package/tokens-v2-private/ts/tokens/functional/size/border.js +1 -1
  122. package/tokens-v2-private/ts/tokens/functional/size/breakpoints.d.ts +1 -1
  123. package/tokens-v2-private/ts/tokens/functional/size/breakpoints.js +1 -1
  124. package/tokens-v2-private/ts/tokens/functional/size/size-coarse.d.ts +1 -1
  125. package/tokens-v2-private/ts/tokens/functional/size/size-coarse.js +1 -1
  126. package/tokens-v2-private/ts/tokens/functional/size/size-fine.d.ts +1 -1
  127. package/tokens-v2-private/ts/tokens/functional/size/size-fine.js +1 -1
  128. package/tokens-v2-private/ts/tokens/functional/size/size.d.ts +1 -1
  129. package/tokens-v2-private/ts/tokens/functional/size/size.js +1 -1
  130. package/tokens-v2-private/ts/tokens/functional/size/viewport.d.ts +1 -1
  131. package/tokens-v2-private/ts/tokens/functional/size/viewport.js +1 -1
  132. package/tokens-v2-private/ts/tokens/functional/typography/typography.d.ts +1 -1
  133. package/tokens-v2-private/ts/tokens/functional/typography/typography.js +1 -1
@@ -0,0 +1,170 @@
1
+ import {cssWrapMediaQuery} from './cssWrapMediaQuery'
2
+ import {getMockDictionary, getMockFormatterArguments, getMockToken} from '../test-utilities'
3
+ import {format} from 'prettier'
4
+
5
+ describe('Format: tokens nested in media query', () => {
6
+ it('Wraps in screen if no media query defined', () => {
7
+ const input = getMockFormatterArguments()
8
+ const expectedOutput = format(
9
+ ` @media screen {
10
+ :root {
11
+ --red: transformedValue;
12
+ }
13
+ }`,
14
+ {parser: 'css', printWidth: 500},
15
+ )
16
+ expect(cssWrapMediaQuery(input)).toStrictEqual(expectedOutput)
17
+ })
18
+
19
+ it('Wraps in screen if no matching media query is found', () => {
20
+ const input = getMockFormatterArguments({
21
+ options: {
22
+ mediaQuery: {
23
+ 'size-fine.css': '(pointer: fine)',
24
+ },
25
+ },
26
+ file: {
27
+ destination: 'size-coarse.css',
28
+ options: {
29
+ showFileHeader: false,
30
+ },
31
+ },
32
+ })
33
+ const expectedOutput = format(
34
+ ` @media screen {
35
+ :root {
36
+ --red: transformedValue;
37
+ }
38
+ }`,
39
+ {parser: 'css', printWidth: 500},
40
+ )
41
+ expect(cssWrapMediaQuery(input)).toStrictEqual(expectedOutput)
42
+ })
43
+
44
+ it('Wraps in defined media query if files match', () => {
45
+ const input = getMockFormatterArguments({
46
+ options: {
47
+ mediaQuery: {
48
+ 'size-fine.css': '(pointer: fine)',
49
+ },
50
+ },
51
+ file: {
52
+ destination: 'size-fine.css',
53
+ options: {
54
+ showFileHeader: false,
55
+ },
56
+ },
57
+ })
58
+ const expectedOutput = format(
59
+ ` @media (pointer: fine) {
60
+ :root {
61
+ --red: transformedValue;
62
+ }
63
+ }`,
64
+ {parser: 'css', printWidth: 500},
65
+ )
66
+ expect(cssWrapMediaQuery(input)).toStrictEqual(expectedOutput)
67
+ })
68
+
69
+ it('Show comment if option.description is true', () => {
70
+ const input = getMockFormatterArguments({
71
+ dictionary: getMockDictionary({
72
+ tokens: {
73
+ subgroup: {
74
+ red: getMockToken({
75
+ name: 'red',
76
+ value: 'transformedValue',
77
+ comment: 'This is a description',
78
+ }),
79
+ },
80
+ },
81
+ }),
82
+ options: {
83
+ mediaQuery: {
84
+ 'size-fine.css': '(pointer: fine)',
85
+ },
86
+ descriptions: true,
87
+ },
88
+ file: {
89
+ destination: 'size-fine.css',
90
+ options: {
91
+ showFileHeader: false,
92
+ },
93
+ },
94
+ })
95
+
96
+ const expectedOutput = format(
97
+ ` @media (pointer: fine) {
98
+ :root {
99
+ --red: transformedValue; /* This is a description */
100
+ }
101
+ }`,
102
+ {parser: 'css', printWidth: 500},
103
+ )
104
+ expect(cssWrapMediaQuery(input)).toStrictEqual(expectedOutput)
105
+ })
106
+
107
+ it('Hides comment if option.description is false or not set', () => {
108
+ const input = getMockFormatterArguments({
109
+ dictionary: getMockDictionary({
110
+ tokens: {
111
+ subgroup: {
112
+ red: getMockToken({
113
+ name: 'red',
114
+ value: 'transformedValue',
115
+ comment: 'This is a description',
116
+ }),
117
+ },
118
+ },
119
+ }),
120
+ options: {
121
+ mediaQuery: {
122
+ 'size-fine.css': '(pointer: fine)',
123
+ },
124
+ descriptions: false,
125
+ },
126
+ file: {
127
+ destination: 'size-fine.css',
128
+ options: {
129
+ showFileHeader: false,
130
+ },
131
+ },
132
+ })
133
+
134
+ const inputUnset = getMockFormatterArguments({
135
+ dictionary: getMockDictionary({
136
+ tokens: {
137
+ subgroup: {
138
+ red: getMockToken({
139
+ name: 'red',
140
+ value: 'transformedValue',
141
+ comment: 'This is a description',
142
+ }),
143
+ },
144
+ },
145
+ }),
146
+ options: {
147
+ mediaQuery: {
148
+ 'size-fine.css': '(pointer: fine)',
149
+ },
150
+ },
151
+ file: {
152
+ destination: 'size-fine.css',
153
+ options: {
154
+ showFileHeader: false,
155
+ },
156
+ },
157
+ })
158
+
159
+ const expectedOutput = format(
160
+ ` @media (pointer: fine) {
161
+ :root {
162
+ --red: transformedValue;
163
+ }
164
+ }`,
165
+ {parser: 'css', printWidth: 500},
166
+ )
167
+ expect(cssWrapMediaQuery(input)).toStrictEqual(expectedOutput)
168
+ expect(cssWrapMediaQuery(inputUnset)).toStrictEqual(expectedOutput)
169
+ })
170
+ })
@@ -0,0 +1,43 @@
1
+ import {javascriptCommonJs} from './javascriptCommonJs'
2
+ import {getMockFormatterArguments} from '../test-utilities'
3
+ import {format} from 'prettier'
4
+
5
+ describe('Format: CommonJs', () => {
6
+ it('Formats tokens adding prefix', () => {
7
+ const input = getMockFormatterArguments({
8
+ platform: {
9
+ prefix: 'test',
10
+ },
11
+ })
12
+
13
+ const expectedOutput = format(
14
+ `exports.default = {
15
+ test: {
16
+ tokens: {
17
+ subgroup: {
18
+ red: "transformedValue",
19
+ },
20
+ },
21
+ },
22
+ };`,
23
+ {parser: 'typescript', printWidth: 500},
24
+ )
25
+
26
+ expect(javascriptCommonJs(input)).toBe(expectedOutput)
27
+ })
28
+
29
+ it('Formats tokens without prefix', () => {
30
+ const input = getMockFormatterArguments()
31
+ const expectedOutput = format(
32
+ `exports.default = {
33
+ tokens: {
34
+ subgroup: {
35
+ red: "transformedValue",
36
+ },
37
+ },
38
+ };`,
39
+ {parser: 'typescript', printWidth: 500},
40
+ )
41
+ expect(javascriptCommonJs(input)).toStrictEqual(expectedOutput)
42
+ })
43
+ })
@@ -0,0 +1,41 @@
1
+ import {javascriptEsm} from './javascriptEsm'
2
+ import {getMockFormatterArguments} from '../test-utilities'
3
+ import {format} from 'prettier'
4
+
5
+ describe('Format: ESM', () => {
6
+ it('Formats tokens adding prefix', () => {
7
+ const input = getMockFormatterArguments({
8
+ platform: {
9
+ prefix: 'test',
10
+ },
11
+ })
12
+ const expectedOutput = format(
13
+ `export default {
14
+ test: {
15
+ tokens: {
16
+ subgroup: {
17
+ red: "transformedValue",
18
+ },
19
+ },
20
+ },
21
+ };`,
22
+ {parser: 'typescript', printWidth: 500},
23
+ )
24
+ expect(javascriptEsm(input)).toStrictEqual(expectedOutput)
25
+ })
26
+
27
+ it('Formats tokens without prefix', () => {
28
+ const input = getMockFormatterArguments()
29
+ const expectedOutput = format(
30
+ `export default {
31
+ tokens: {
32
+ subgroup: {
33
+ red: "transformedValue",
34
+ },
35
+ },
36
+ };`,
37
+ {parser: 'typescript', printWidth: 500},
38
+ )
39
+ expect(javascriptEsm(input)).toStrictEqual(expectedOutput)
40
+ })
41
+ })
@@ -0,0 +1,73 @@
1
+ import {jsonNestedPrefixed} from './jsonNestedPrefixed'
2
+ import {getMockFormatterArguments} from '../test-utilities'
3
+ import {format} from 'prettier'
4
+
5
+ describe('Format: Json nested with prefixes', () => {
6
+ test('Formats tokens with prefix', () => {
7
+ const input = getMockFormatterArguments({
8
+ platform: {
9
+ prefix: 'test',
10
+ },
11
+ })
12
+
13
+ const expectedOutput = format(
14
+ `{
15
+ "test": {
16
+ "tokens": {
17
+ "subgroup": {
18
+ "red": "transformedValue"
19
+ }
20
+ }
21
+ }
22
+ }`,
23
+ {parser: 'json', printWidth: 500},
24
+ )
25
+
26
+ expect(jsonNestedPrefixed(input)).toBe(expectedOutput)
27
+ })
28
+
29
+ test('Formats tokens without prefix', () => {
30
+ const input = getMockFormatterArguments()
31
+ const expectedOutput = format(
32
+ `{
33
+ "tokens": {
34
+ "subgroup": {
35
+ "red": "transformedValue"
36
+ }
37
+ }
38
+ }`,
39
+ {parser: 'json', printWidth: 500},
40
+ )
41
+ expect(jsonNestedPrefixed(input)).toStrictEqual(expectedOutput)
42
+ })
43
+
44
+ test('Formats tokens without verbose setting', () => {
45
+ const input = getMockFormatterArguments({
46
+ options: {
47
+ outputVerbose: true,
48
+ },
49
+ })
50
+ const expectedOutput = format(
51
+ `{
52
+ "tokens": {
53
+ "subgroup": {
54
+ "red": {
55
+ "name": "red",
56
+ "path": ["tokens", "subgroup", "red"],
57
+ "original": {
58
+ "value": "originalValue",
59
+ "attributes": {}
60
+ },
61
+ "filePath": "file.json",
62
+ "isSource": true,
63
+ "value": "transformedValue",
64
+ "attributes": {}
65
+ }
66
+ }
67
+ }
68
+ }`,
69
+ {parser: 'json', printWidth: 500},
70
+ )
71
+ expect(jsonNestedPrefixed(input)).toStrictEqual(expectedOutput)
72
+ })
73
+ })
@@ -0,0 +1,56 @@
1
+ import {jsonOneDimensional} from './jsonOneDimensional'
2
+ import {getMockDictionary, getMockFormatterArguments, getMockToken} from '../test-utilities'
3
+ import {format} from 'prettier'
4
+
5
+ describe('Format: Json One Dimensional', () => {
6
+ const dictionary = getMockDictionary({
7
+ tokens: {
8
+ subgroup: {
9
+ red: getMockToken({
10
+ name: 'tokens-subgroup-red',
11
+ path: ['tokens', 'subgroup', 'red'],
12
+ }),
13
+ },
14
+ },
15
+ })
16
+
17
+ test('Formats tokens as object', () => {
18
+ const input = getMockFormatterArguments({
19
+ dictionary,
20
+ options: {outputVerbose: true},
21
+ })
22
+
23
+ const expectedOutput = format(
24
+ `{
25
+ "tokens-subgroup-red": {
26
+ "name": "tokens-subgroup-red",
27
+ "path": ["tokens", "subgroup", "red"],
28
+ "original": {
29
+ "value": "originalValue",
30
+ "attributes": {}
31
+ },
32
+ "filePath": "file.json",
33
+ "isSource": true,
34
+ "value": "transformedValue",
35
+ "attributes": {}
36
+ }
37
+ }`,
38
+ {parser: 'json', printWidth: 500},
39
+ )
40
+ expect(jsonOneDimensional(input)).toStrictEqual(expectedOutput)
41
+ })
42
+
43
+ test('Formats tokens as values only', () => {
44
+ const input = getMockFormatterArguments({
45
+ dictionary,
46
+ })
47
+
48
+ const expectedOutput = format(
49
+ `{
50
+ "tokens-subgroup-red": "transformedValue"
51
+ }`,
52
+ {parser: 'json', printWidth: 500},
53
+ )
54
+ expect(jsonOneDimensional(input)).toStrictEqual(expectedOutput)
55
+ })
56
+ })
@@ -0,0 +1,178 @@
1
+ import {typescriptExportDefinition} from './typescriptExportDefinition'
2
+ import {getMockFormatterArguments, getMockDictionary, getMockToken} from '../test-utilities'
3
+ import {format} from 'prettier'
4
+
5
+ describe('Format: TypeScript definitions', () => {
6
+ const dictionary = getMockDictionary({
7
+ tokens: {
8
+ subgroup: {
9
+ red: getMockToken({
10
+ $type: 'color',
11
+ value: '#FF0000',
12
+ }),
13
+ stringValue: getMockToken({
14
+ value: '#FF0000',
15
+ }),
16
+ border: getMockToken({
17
+ $type: 'border',
18
+ value: {
19
+ color: '#FF0000',
20
+ style: 'solid',
21
+ width: '1px',
22
+ },
23
+ }),
24
+ numberValue: getMockToken({
25
+ value: 20,
26
+ }),
27
+ booleanValue: getMockToken({
28
+ value: true,
29
+ }),
30
+ },
31
+ },
32
+ })
33
+
34
+ it('Formats dimension tokens', () => {
35
+ const input = getMockFormatterArguments({
36
+ dictionary: getMockDictionary({
37
+ tokens: {
38
+ subgroup: {
39
+ size: {
40
+ px: getMockToken({
41
+ $type: 'dimension',
42
+ value: '100px',
43
+ }),
44
+ rem: getMockToken({
45
+ $type: 'dimension',
46
+ value: '10rem',
47
+ }),
48
+ em: getMockToken({
49
+ $type: 'dimension',
50
+ value: '10em',
51
+ }),
52
+ },
53
+ },
54
+ },
55
+ }),
56
+ })
57
+ const expectedOutput = format(
58
+ `/**
59
+ * @description size in px
60
+ */
61
+ type SizePx = \`\${number}px\`
62
+
63
+ /**
64
+ * @description size in rem
65
+ */
66
+ type SizeRem = \`\${number}rem\`
67
+
68
+ /**
69
+ * @description size in em
70
+ */
71
+ type SizeEm = \`\${number}em\`
72
+
73
+ export type tokens = {
74
+ tokens: {
75
+ subgroup: {
76
+ size: {
77
+ px: SizePx;
78
+ rem: SizeRem;
79
+ em: SizeEm;
80
+ };
81
+ };
82
+ };
83
+ };`,
84
+ {parser: 'typescript', printWidth: 500},
85
+ )
86
+
87
+ expect(typescriptExportDefinition(input)).toStrictEqual(expectedOutput)
88
+ })
89
+
90
+ it('Formats tokens adding prefix', () => {
91
+ const input = getMockFormatterArguments({
92
+ dictionary,
93
+ platform: {
94
+ prefix: 'test',
95
+ },
96
+ })
97
+ const expectedOutput = format(
98
+ `/**
99
+ * @description hex string (6 or 8-digit)
100
+ */
101
+ type ColorHex = string;
102
+
103
+ /**
104
+ * @description a css border string
105
+ * @format color | style | width
106
+ */
107
+ type Border = \`\${ColorHex} \${string} \${string}\`;
108
+
109
+ export type tokens = {
110
+ test: {
111
+ tokens: {
112
+ subgroup: {
113
+ red: ColorHex;
114
+ stringValue: string;
115
+ border: Border;
116
+ numberValue: number;
117
+ booleanValue: "boolean";
118
+ };
119
+ };
120
+ };
121
+ };`,
122
+ {parser: 'typescript', printWidth: 500},
123
+ )
124
+
125
+ expect(typescriptExportDefinition(input)).toStrictEqual(expectedOutput)
126
+ })
127
+
128
+ it('Formats tokens without prefix', () => {
129
+ const input = getMockFormatterArguments({dictionary})
130
+ const expectedOutput = format(
131
+ `/**
132
+ * @description hex string (6 or 8-digit)
133
+ */
134
+ type ColorHex = string;
135
+
136
+ /**
137
+ * @description a css border string
138
+ * @format color | style | width
139
+ */
140
+ type Border = \`\${ColorHex} \${string} \${string}\`;
141
+
142
+ export type tokens = {
143
+ tokens: {
144
+ subgroup: {
145
+ red: ColorHex;
146
+ stringValue: string;
147
+ border: Border;
148
+ numberValue: number;
149
+ booleanValue: "boolean";
150
+ };
151
+ };
152
+ };`,
153
+ {parser: 'typescript', printWidth: 500},
154
+ )
155
+ expect(typescriptExportDefinition(input)).toStrictEqual(expectedOutput)
156
+ })
157
+
158
+ it('throws an invalidTokenValue error if a token has an invalid value for the defined type', () => {
159
+ const input = getMockFormatterArguments({
160
+ dictionary: getMockDictionary({
161
+ // @ts-expect-error: Because of invalid token
162
+ tokens: {
163
+ subgroup: {
164
+ color: {
165
+ name: 'color token name',
166
+ value: 'rgb(100,200,255)',
167
+ $type: 'color',
168
+ },
169
+ },
170
+ },
171
+ }),
172
+ })
173
+
174
+ expect(() => {
175
+ typescriptExportDefinition(input)
176
+ }).toThrowError('Invalid token: "color token name" with type "color" can not have a value of "rgb(100,200,255)"')
177
+ })
178
+ })
@@ -0,0 +1,47 @@
1
+ import {getMockToken} from '../../test-utilities'
2
+ import {jsonToFlat} from './jsonToFlat'
3
+
4
+ describe('Utilities: jsonToFlat', () => {
5
+ const tokens = [
6
+ getMockToken({
7
+ value: '#111',
8
+ $type: 'color',
9
+ path: ['parent', 'subparent', 'child1'],
10
+ name: 'parent-subparent-child1',
11
+ }),
12
+ getMockToken({
13
+ value: '#222',
14
+ $type: 'color',
15
+ path: ['parent', 'subparent', 'child2'],
16
+ name: 'parent-subparent-child2',
17
+ }),
18
+ ]
19
+
20
+ it('it returns only value property as value of object if return Object is false', () => {
21
+ expect(jsonToFlat(tokens, false)['parent-subparent-child1']).toBe('#111')
22
+ expect(jsonToFlat(tokens, false)).toStrictEqual({
23
+ 'parent-subparent-child1': '#111',
24
+ 'parent-subparent-child2': '#222',
25
+ })
26
+ })
27
+
28
+ it('it returns objects as value of object if return Object is true', () => {
29
+ expect(jsonToFlat(tokens, true)['parent-subparent-child1']).toEqual({
30
+ value: '#111',
31
+ $type: 'color',
32
+ path: ['parent', 'subparent', 'child1'],
33
+ name: 'parent-subparent-child1',
34
+ attributes: {},
35
+ filePath: 'file.json',
36
+ isSource: true,
37
+ original: {
38
+ attributes: {},
39
+ value: 'originalValue',
40
+ },
41
+ })
42
+ })
43
+
44
+ it('it returns only value property as value of object if return Object is undefined', () => {
45
+ expect(jsonToFlat(tokens, undefined)['parent-subparent-child1']).toBe('#111')
46
+ })
47
+ })
@@ -0,0 +1,39 @@
1
+ import {jsonToNestedValue} from './jsonToNestedValue'
2
+
3
+ describe('Utilities: jsonToNestedValue', () => {
4
+ const obj = {
5
+ parent: {
6
+ subparent: {
7
+ child1: {
8
+ value: '#111',
9
+ $type: 'color',
10
+ },
11
+ child2: {
12
+ value: '#222',
13
+ $type: 'color',
14
+ },
15
+ },
16
+ otherSubparent: {
17
+ text: 'hello',
18
+ number: 42,
19
+ noValue: {
20
+ string: 'string',
21
+ number: 12,
22
+ },
23
+ },
24
+ },
25
+ }
26
+
27
+ it('it returns only value property as value of object', () => {
28
+ expect(jsonToNestedValue(obj.parent.subparent.child1)).toBe('#111')
29
+ expect(jsonToNestedValue(obj['parent']['subparent'])).toStrictEqual({child1: '#111', child2: '#222'})
30
+ })
31
+
32
+ it('it returns only values if final child is no object', () => {
33
+ const transformedObj = obj
34
+ // @ts-expect-error: fake token for test causes error
35
+ transformedObj['parent']['subparent'] = {child1: '#111', child2: '#222'}
36
+
37
+ expect(jsonToNestedValue(obj)).toStrictEqual(transformedObj)
38
+ })
39
+ })
@@ -0,0 +1,38 @@
1
+ import {getMockToken} from '../../test-utilities'
2
+ import {prefixTokens} from './prefixTokens'
3
+
4
+ describe('Utilities: prefixTokens', () => {
5
+ const tokens = {
6
+ colors: getMockToken({
7
+ name: 'token',
8
+ value: 'value',
9
+ }),
10
+ }
11
+
12
+ it('it adds prefix to token array', () => {
13
+ const platform = {
14
+ prefix: 'pumpkin',
15
+ }
16
+ const expectedOutput = {
17
+ [platform.prefix]: tokens,
18
+ }
19
+
20
+ expect(prefixTokens(tokens, platform)).toStrictEqual(expectedOutput)
21
+ })
22
+
23
+ it('it returns original token array if prefix is undefined', () => {
24
+ const platform = {
25
+ prefix: undefined,
26
+ }
27
+ const expectedOutput = tokens
28
+
29
+ expect(prefixTokens(tokens, platform)).toStrictEqual(expectedOutput)
30
+ })
31
+
32
+ it('it returns original token array if platform is undefined', () => {
33
+ const platform = undefined
34
+ const expectedOutput = tokens
35
+
36
+ expect(prefixTokens(tokens, platform)).toStrictEqual(expectedOutput)
37
+ })
38
+ })