Skip to content

Commit

Permalink
add test for cssVariables (#927)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasoppermann authored Apr 23, 2024
1 parent 8a3b62c commit 47d17c7
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
49 changes: 49 additions & 0 deletions src/formats/cssVariables.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import {cssVariables} from './cssVariables'
import {getMockFormatterArguments} from '../test-utilities'
import {format} from 'prettier'

describe('Format: css/variables', () => {
it('Formats tokens', () => {
const input = getMockFormatterArguments()
const expectedOutput = format(
`:root {
--red: transformedValue;
}`,
{
parser: 'css',
printWidth: 500,
},
)
expect(cssVariables(input)).toStrictEqual(expectedOutput)
})

it('Formats tokens with custom selectors', () => {
const input = getMockFormatterArguments({
options: {
selector: `[data-color-mode="dark"]`,
},
})
const expectedOutput = format(
` [data-color-mode="dark"] {
--red: transformedValue;
}`,
{parser: 'css', printWidth: 500},
)
expect(cssVariables(input)).toStrictEqual(expectedOutput)
})

it('Formats tokens with only options.selector', () => {
const input = getMockFormatterArguments({
options: {
selector: `[data-color-mode="dark"]`,
},
})
const expectedOutput = format(
`[data-color-mode="dark"]{
--red: transformedValue;
}`,
{parser: 'css', printWidth: 500},
)
expect(cssVariables(input)).toStrictEqual(expectedOutput)
})
})
4 changes: 2 additions & 2 deletions src/formats/cssVariables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import type {LineFormatting} from 'style-dictionary/types/FormatHelpers'
const {fileHeader, formattedVariables} = StyleDictionary.formatHelpers

/**
* @description Converts `StyleDictionary.dictionary.tokens` to css with prefers dark and light section
* @description Converts `StyleDictionary.dictionary.tokens` to csssection
* @param arguments [FormatterArguments](https://github.com/amzn/style-dictionary/blob/main/types/Format.d.ts)
* @param arguments.options outputReferences `boolean`, selector `string`, selectorLight `string`, selectorDark `string`
* @param arguments.options outputReferences `boolean`, selector `string`
* @returns formatted `string`
*/
export const cssVariables: StyleDictionary.Formatter = ({dictionary, options = {}, file}: FormatterArguments) => {
Expand Down

0 comments on commit 47d17c7

Please sign in to comment.