Skip to content

Commit

Permalink
all integration tests refactored
Browse files Browse the repository at this point in the history
  • Loading branch information
florin01hyma committed Nov 8, 2024
1 parent 811ca8b commit ede35be
Show file tree
Hide file tree
Showing 12 changed files with 393 additions and 300 deletions.
15 changes: 9 additions & 6 deletions test/integration/color-modifier-references.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import StyleDictionary from 'style-dictionary';
import { expect } from 'chai';
import { promises } from 'node:fs';
import path from 'node:path';
import { cleanup, init } from './utils.js';
import { cleanup, init, excerpt } from './utils.js';

const outputDir = 'test/integration/tokens/';
const outputFileName = 'vars.css';
Expand Down Expand Up @@ -43,14 +43,17 @@ describe('typography references', () => {

it('supports references inside color modifiers', async () => {
const file = await promises.readFile(outputFilePath, 'utf-8');
expect(file).to.include(
`--sdAlpha: 0.3;
--sdColor: #ffffff4d;`,
);
const content = excerpt(file, { before: ':root {', after: '--sdModifier' });
const normalizeWhitespace = (str: string) => str.replace(/^\s+/gm, ''); // Remove leading spaces/tabs
const expectedOutput = `--sdAlpha: 0.3;
--sdColor: #ffffff4d;`;
expect(normalizeWhitespace(content)).to.equal(normalizeWhitespace(expectedOutput));
});

it('supports color modifier that is a reference itself, containing another reference', async () => {
const file = await promises.readFile(outputFilePath, 'utf-8');
expect(file).to.include(`--sdColor2: #0000004d;`);
const content = excerpt(file, { before: '--sdModifier: [object Object];', after: '}' });
const expectedOutput = `--sdColor2: #0000004d;`;
expect(content).to.equal(expectedOutput);
});
});
73 changes: 37 additions & 36 deletions test/integration/cross-file-refs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type StyleDictionary from 'style-dictionary';
import { expect } from 'chai';
import { promises } from 'node:fs';
import path from 'node:path';
import { cleanup, init } from './utils.js';
import { cleanup, excerpt, init } from './utils.js';

const outputDir = 'test/integration/tokens/';
const outputFileName = 'vars.css';
Expand Down Expand Up @@ -43,40 +43,41 @@ describe('cross file references', () => {

it('supports cross file references e.g. expanding typography', async () => {
const file = await promises.readFile(outputFilePath, 'utf-8');
expect(file).to.include(`
--sdTypoFontWeight: 400;
--sdTypoFontStyle: italic;
--sdPrimaryFont: Inter;
--sdFontWeight: 800;
--sdLineHeight: 1.5;
--sdTypo2FontFamily: Inter;
--sdTypo2FontWeight: 800;
--sdTypo2LineHeight: 1.5;
--sdTypo2FontSize: 8px;
--sdDimensionScale: 2;
--sdDimensionXs: 4px;
--sdTestCompositeFancyCardColor: #fff;
--sdTestCompositeFancyCardBorderRadius: 18px;
--sdTestCompositeFancyCardBorderColor: #999;
--sdTestCompositeCardColor: #fff;
--sdTestCompositeCardBorderRadius: 18px;
--sdTestCompositeCardBorderColor: #999;
--sdTestTypographyFancyTextFontFamily: Arial;
--sdTestTypographyFancyTextFontSize: 25px;
--sdTestTypographyFancyTextLineHeight: 32px;
--sdTestTypographyFancyTextFontWeight: 700;
--sdTestTypographyTextFontFamily: Arial;
--sdTestTypographyTextFontSize: 25px;
--sdTestTypographyTextLineHeight: 32px;
--sdTestTypographyTextFontWeight: 700;
--sdWeightWeight: 400;
--sdWeightStyle: italic;
--sdTypoAliasFontWeight: 400;
--sdTypoAliasFontStyle: italic;
--sdTypo3FontFamily: Inter;
--sdTypo3FontWeight: 800;
--sdTypo3LineHeight: 1.5;
--sdTypo3FontSize: 8px;
`);
const content = excerpt(file, { before: ':root {', after: '}' });
const normalizeWhitespace = (str: string) => str.replace(/^\s+/gm, ''); // Remove leading spaces/tabs
const expectedOutput = `--sdTypoFontWeight: 400;
--sdTypoFontStyle: italic;
--sdPrimaryFont: Inter;
--sdFontWeight: 800;
--sdLineHeight: 1.5;
--sdTypo2FontFamily: Inter;
--sdTypo2FontWeight: 800;
--sdTypo2LineHeight: 1.5;
--sdTypo2FontSize: 8px;
--sdDimensionScale: 2;
--sdDimensionXs: 4px;
--sdTestCompositeFancyCardColor: #fff;
--sdTestCompositeFancyCardBorderRadius: 18px;
--sdTestCompositeFancyCardBorderColor: #999;
--sdTestCompositeCardColor: #fff;
--sdTestCompositeCardBorderRadius: 18px;
--sdTestCompositeCardBorderColor: #999;
--sdTestTypographyFancyTextFontFamily: Arial;
--sdTestTypographyFancyTextFontSize: 25px;
--sdTestTypographyFancyTextLineHeight: 32px;
--sdTestTypographyFancyTextFontWeight: 700;
--sdTestTypographyTextFontFamily: Arial;
--sdTestTypographyTextFontSize: 25px;
--sdTestTypographyTextLineHeight: 32px;
--sdTestTypographyTextFontWeight: 700;
--sdWeightWeight: 400;
--sdWeightStyle: italic;
--sdTypoAliasFontWeight: 400;
--sdTypoAliasFontStyle: italic;
--sdTypo3FontFamily: Inter;
--sdTypo3FontWeight: 800;
--sdTypo3LineHeight: 1.5;
--sdTypo3FontSize: 8px;`;
expect(normalizeWhitespace(content)).to.equal(normalizeWhitespace(expectedOutput));
});
});
6 changes: 4 additions & 2 deletions test/integration/custom-group.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import StyleDictionary from 'style-dictionary';
import { getTransforms, register } from '../../src/index.js';
import { promises } from 'node:fs';
import path from 'node:path';
import { cleanup } from './utils.js';
import { cleanup, excerpt } from './utils.js';

const outputDir = 'test/integration/tokens/';
const outputFileName = 'vars.css';
Expand Down Expand Up @@ -53,6 +53,8 @@ describe('custom transform group', () => {
await before();

const file = await promises.readFile(outputFilePath, 'utf-8');
expect(file).to.include(`--length: 24;`);
const content = excerpt(file, { before: ':root {', after: '}' });
const expectedOutput = `--length: 24;`;
expect(content).to.equal(expectedOutput);
});
});
14 changes: 7 additions & 7 deletions test/integration/exclude-parent-keys.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect } from 'chai';
import { promises } from 'node:fs';
import path from 'node:path';
import { cleanup, init } from './utils.js';
import { cleanup, excerpt, init } from './utils.js';

const outputDir = 'test/integration/tokens/';
const outputFileName = 'vars.css';
Expand Down Expand Up @@ -52,11 +52,11 @@ describe('exclude parent keys', () => {
await init(cfg, transformOpts);
await cleanup();
const file = await promises.readFile(outputFilePath, 'utf-8');
expect(file).to.include(
`
--sdCoreColor: #FFFFFF;
--sdSemanticColor: #FFFFFF;
--sdButtonColor: #FFFFFF;`,
);
const content = excerpt(file, { before: ':root {', after: '}' });
const normalizeWhitespace = (str: string) => str.replace(/^\s+/gm, ''); // Remove leading spaces/tabs
const expectedOutput = `--sdCoreColor: #FFFFFF;
--sdSemanticColor: #FFFFFF;
--sdButtonColor: #FFFFFF;`;
expect(normalizeWhitespace(content)).to.equal(normalizeWhitespace(expectedOutput));
});
});
Loading

0 comments on commit ede35be

Please sign in to comment.