|
| 1 | +/* |
| 2 | + * Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with |
| 5 | + * the License. A copy of the License is located at |
| 6 | + * |
| 7 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | + * |
| 9 | + * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR |
| 10 | + * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions |
| 11 | + * and limitations under the License. |
| 12 | + */ |
| 13 | +import { expect } from 'chai'; |
| 14 | +import formats from '../../lib/common/formats.js'; |
| 15 | +import createFormatArgs from '../../lib/utils/createFormatArgs.js'; |
| 16 | +import { convertTokenData } from '../../lib/utils/convertTokenData.js'; |
| 17 | +import { formats as formatsEnum } from '../../lib/enums/formats.js'; |
| 18 | + |
| 19 | +const { javascriptEsm } = formatsEnum; |
| 20 | + |
| 21 | +const file = { |
| 22 | + destination: '__output/', |
| 23 | + format: javascriptEsm, |
| 24 | + options: { |
| 25 | + flat: true, |
| 26 | + }, |
| 27 | + filter: { |
| 28 | + type: 'color', |
| 29 | + }, |
| 30 | +}; |
| 31 | + |
| 32 | +const tokens = { |
| 33 | + colors: { |
| 34 | + red: { |
| 35 | + 500: { |
| 36 | + value: '#ff0000', |
| 37 | + type: 'color', |
| 38 | + path: ['colors', 'red', '500'], |
| 39 | + filePath: 'tokens.json', |
| 40 | + attributes: { |
| 41 | + foo: 'bar', |
| 42 | + }, |
| 43 | + name: 'ColorsRed500', |
| 44 | + }, |
| 45 | + }, |
| 46 | + }, |
| 47 | + dimensions: { |
| 48 | + xs: { |
| 49 | + value: '15px', |
| 50 | + type: 'dimension', |
| 51 | + path: ['dimension', 'xs'], |
| 52 | + filePath: 'tokens.json', |
| 53 | + attributes: { |
| 54 | + foo: 'bar', |
| 55 | + }, |
| 56 | + name: 'DimensionXs', |
| 57 | + }, |
| 58 | + }, |
| 59 | +}; |
| 60 | + |
| 61 | +const format = formats[javascriptEsm]; |
| 62 | + |
| 63 | +describe('formats', () => { |
| 64 | + describe(javascriptEsm, () => { |
| 65 | + it('should be a valid JS file and match snapshot', async () => { |
| 66 | + await expect( |
| 67 | + await format( |
| 68 | + createFormatArgs({ |
| 69 | + dictionary: { tokens, allTokens: convertTokenData(tokens, { output: 'array' }) }, |
| 70 | + file, |
| 71 | + platform: {}, |
| 72 | + }), |
| 73 | + {}, |
| 74 | + file, |
| 75 | + ), |
| 76 | + ).to.matchSnapshot(); |
| 77 | + }); |
| 78 | + }); |
| 79 | +}); |
0 commit comments