Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

all integration tests refactored #331

Merged
merged 2 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 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,16 @@ 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, { start: ':root {', end: '--sdModifier' });
const expectedOutput = `--sdAlpha: 0.3;
--sdColor: #ffffff4d;`;
expect(content).to.equal(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, { start: '--sdModifier: [object Object];', end: '}' });
const expectedOutput = `--sdColor2: #0000004d;`;
expect(content).to.equal(expectedOutput);
});
});
72 changes: 36 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,40 @@ 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, { start: ':root {', end: '}' });
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(content).to.equal(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, { start: ':root {', end: '}' });
const expectedOutput = `--length: 24;`;
expect(content).to.equal(expectedOutput);
});
});
13 changes: 6 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,10 @@ 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, { start: ':root {', end: '}' });
const expectedOutput = `--sdCoreColor: #FFFFFF;
--sdSemanticColor: #FFFFFF;
--sdButtonColor: #FFFFFF;`;
expect(content).to.equal(expectedOutput);
});
});
208 changes: 105 additions & 103 deletions test/integration/expand-composition.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';
import { expandTypesMap } from '../../src/index.js';

const outputDir = 'test/integration/tokens/';
Expand Down Expand Up @@ -63,119 +63,121 @@ describe('expand composition tokens', () => {
);

const file = await promises.readFile(outputFilePath, 'utf-8');
expect(file).to.include(
`
--sdCompositionSize: 24px;
--sdCompositionOpacity: 0.5;
--sdCompositionFontSize: 96px;
--sdCompositionFontFamily: Roboto;
--sdCompositionFontWeight: 700;
--sdCompositionHeaderFontFamily: Roboto;
--sdCompositionHeaderFontSize: 96px;
--sdCompositionHeaderFontWeight: 700;
--sdCompositionHeaderLineHeight: 1.25;
--sdCompositionHeaderLetterSpacing: 1.25em;
--sdTypography: italic 800 26px/1.25 Arial;
--sdFontWeightRefWeight: 800;
--sdFontWeightRefStyle: italic;
--sdBorder: 4px solid #FFFF00;
--sdShadowSingle: inset 0 4px 10px 0 rgba(0,0,0,0.4);
--sdShadowDouble: inset 0 4px 10px 0 rgba(0,0,0,0.4), 0 8px 12px 5px rgba(0,0,0,0.4);
--sdRef: italic 800 26px/1.25 Arial;`,
);
const content = excerpt(file, {
start: ':root {',
end: '--sdDeepRef: italic 800 26px/1.25 Arial;',
});
const expectedOutput = `--sdCompositionSize: 24px;
--sdCompositionOpacity: 0.5;
--sdCompositionFontSize: 96px;
--sdCompositionFontFamily: Roboto;
--sdCompositionFontWeight: 700;
--sdCompositionHeaderFontFamily: Roboto;
--sdCompositionHeaderFontSize: 96px;
--sdCompositionHeaderFontWeight: 700;
--sdCompositionHeaderLineHeight: 1.25;
--sdCompositionHeaderLetterSpacing: 1.25em;
--sdTypography: italic 800 26px/1.25 Arial;
--sdFontWeightRefWeight: 800;
--sdFontWeightRefStyle: italic;
--sdBorder: 4px solid #FFFF00;
--sdShadowSingle: inset 0 4px 10px 0 rgba(0,0,0,0.4);
--sdShadowDouble: inset 0 4px 10px 0 rgba(0,0,0,0.4), 0 8px 12px 5px rgba(0,0,0,0.4);
--sdRef: italic 800 26px/1.25 Arial;`;
expect(content).to.equal(expectedOutput);
});

it('optionally can transform typography, border and shadow tokens', async () => {
const file = await promises.readFile(outputFilePath, 'utf-8');
expect(file).to.include(
`
--sdCompositionSize: 24px;
--sdCompositionOpacity: 0.5;
--sdCompositionFontSize: 96px;
--sdCompositionFontFamily: Roboto;
--sdCompositionFontWeight: 700;
--sdCompositionHeaderFontFamily: Roboto;
--sdCompositionHeaderFontSize: 96px;
--sdCompositionHeaderFontWeight: 700;
--sdCompositionHeaderLineHeight: 1.25;
--sdCompositionHeaderLetterSpacing: 1.25em;
--sdTypographyFontFamily: Arial;
--sdTypographyFontWeight: 800;
--sdTypographyLineHeight: 1.25;
--sdTypographyFontSize: 26px;
--sdTypographyLetterSpacing: 1.25em;
--sdTypographyParagraphSpacing: 0;
--sdTypographyParagraphIndent: 0;
--sdTypographyTextDecoration: none;
--sdTypographyTextCase: none;
--sdTypographyFontStyle: italic;
--sdFontWeightRefWeight: 800;
--sdFontWeightRefStyle: italic;
--sdBorderColor: #ffff00;
--sdBorderWidth: 4px;
--sdBorderStyle: solid;
--sdShadowSingleBlur: 10px;
--sdShadowSingleSpread: 0;
--sdShadowSingleColor: rgba(0, 0, 0, 0.4);
--sdShadowSingleType: innerShadow;
--sdShadowSingleOffsetX: 0;
--sdShadowSingleOffsetY: 4px;
--sdShadowDouble1Blur: 10px;
--sdShadowDouble1Spread: 0;
--sdShadowDouble1Color: rgba(0, 0, 0, 0.4);
--sdShadowDouble1Type: innerShadow;
--sdShadowDouble1OffsetX: 0;
--sdShadowDouble1OffsetY: 4px;
--sdShadowDouble2Blur: 12px;
--sdShadowDouble2Spread: 5px;
--sdShadowDouble2Color: rgba(0, 0, 0, 0.4);
--sdShadowDouble2OffsetX: 0;
--sdShadowDouble2OffsetY: 8px;`,
);
const content = excerpt(file, { start: ':root {', end: '--sdRefFontFamily: Arial;' });
const expectedOutput = `--sdCompositionSize: 24px;
--sdCompositionOpacity: 0.5;
--sdCompositionFontSize: 96px;
--sdCompositionFontFamily: Roboto;
--sdCompositionFontWeight: 700;
--sdCompositionHeaderFontFamily: Roboto;
--sdCompositionHeaderFontSize: 96px;
--sdCompositionHeaderFontWeight: 700;
--sdCompositionHeaderLineHeight: 1.25;
--sdCompositionHeaderLetterSpacing: 1.25em;
--sdTypographyFontFamily: Arial;
--sdTypographyFontWeight: 800;
--sdTypographyLineHeight: 1.25;
--sdTypographyFontSize: 26px;
--sdTypographyLetterSpacing: 1.25em;
--sdTypographyParagraphSpacing: 0;
--sdTypographyParagraphIndent: 0;
--sdTypographyTextDecoration: none;
--sdTypographyTextCase: none;
--sdTypographyFontStyle: italic;
--sdFontWeightRefWeight: 800;
--sdFontWeightRefStyle: italic;
--sdBorderColor: #ffff00;
--sdBorderWidth: 4px;
--sdBorderStyle: solid;
--sdShadowSingleBlur: 10px;
--sdShadowSingleSpread: 0;
--sdShadowSingleColor: rgba(0, 0, 0, 0.4);
--sdShadowSingleType: innerShadow;
--sdShadowSingleOffsetX: 0;
--sdShadowSingleOffsetY: 4px;
--sdShadowDouble1Blur: 10px;
--sdShadowDouble1Spread: 0;
--sdShadowDouble1Color: rgba(0, 0, 0, 0.4);
--sdShadowDouble1Type: innerShadow;
--sdShadowDouble1OffsetX: 0;
--sdShadowDouble1OffsetY: 4px;
--sdShadowDouble2Blur: 12px;
--sdShadowDouble2Spread: 5px;
--sdShadowDouble2Color: rgba(0, 0, 0, 0.4);
--sdShadowDouble2OffsetX: 0;
--sdShadowDouble2OffsetY: 8px;`;
expect(content).to.equal(expectedOutput);
});

it('handles references and deep references for expandable values', async () => {
const file = await promises.readFile(outputFilePath, 'utf-8');
expect(file).to.include(
`
--sdRefFontFamily: Arial;
--sdRefFontWeight: 800;
--sdRefLineHeight: 1.25;
--sdRefFontSize: 26px;
--sdRefLetterSpacing: 1.25em;
--sdRefParagraphSpacing: 0;
--sdRefParagraphIndent: 0;
--sdRefTextDecoration: none;
--sdRefTextCase: none;
--sdRefFontStyle: italic;
--sdDeepRefFontFamily: Arial;
--sdDeepRefFontWeight: 800;
--sdDeepRefLineHeight: 1.25;
--sdDeepRefFontSize: 26px;
--sdDeepRefLetterSpacing: 1.25em;
--sdDeepRefParagraphSpacing: 0;
--sdDeepRefParagraphIndent: 0;
--sdDeepRefTextDecoration: none;
--sdDeepRefTextCase: none;
--sdDeepRefFontStyle: italic;`,
);
const content = excerpt(file, {
start: '--sdShadowDouble2OffsetY: 8px;',
end: '--sdDeepRefShadowMulti1Blur: 10px;',
});
const expectedOutput = `--sdRefFontFamily: Arial;
--sdRefFontWeight: 800;
--sdRefLineHeight: 1.25;
--sdRefFontSize: 26px;
--sdRefLetterSpacing: 1.25em;
--sdRefParagraphSpacing: 0;
--sdRefParagraphIndent: 0;
--sdRefTextDecoration: none;
--sdRefTextCase: none;
--sdRefFontStyle: italic;
--sdDeepRefFontFamily: Arial;
--sdDeepRefFontWeight: 800;
--sdDeepRefLineHeight: 1.25;
--sdDeepRefFontSize: 26px;
--sdDeepRefLetterSpacing: 1.25em;
--sdDeepRefParagraphSpacing: 0;
--sdDeepRefParagraphIndent: 0;
--sdDeepRefTextDecoration: none;
--sdDeepRefTextCase: none;
--sdDeepRefFontStyle: italic;`;
expect(content).to.equal(expectedOutput);
});

it('handles references for multi-shadow value', async () => {
const file = await promises.readFile(outputFilePath, 'utf-8');
expect(file).to.include(
`
--sdDeepRefShadowMulti1Blur: 10px;
--sdDeepRefShadowMulti1Spread: 0;
--sdDeepRefShadowMulti1Color: rgba(0, 0, 0, 0.4);
--sdDeepRefShadowMulti1Type: innerShadow;
--sdDeepRefShadowMulti1OffsetX: 0;
--sdDeepRefShadowMulti1OffsetY: 4px;
--sdDeepRefShadowMulti2Blur: 12px;
--sdDeepRefShadowMulti2Spread: 5px;
--sdDeepRefShadowMulti2Color: rgba(0, 0, 0, 0.4);
--sdDeepRefShadowMulti2OffsetX: 0;
--sdDeepRefShadowMulti2OffsetY: 8px;`,
);
const content = excerpt(file, { start: '--sdDeepRefFontStyle: italic;', end: '}' });
const expectedOutput = `--sdDeepRefShadowMulti1Blur: 10px;
--sdDeepRefShadowMulti1Spread: 0;
--sdDeepRefShadowMulti1Color: rgba(0, 0, 0, 0.4);
--sdDeepRefShadowMulti1Type: innerShadow;
--sdDeepRefShadowMulti1OffsetX: 0;
--sdDeepRefShadowMulti1OffsetY: 4px;
--sdDeepRefShadowMulti2Blur: 12px;
--sdDeepRefShadowMulti2Spread: 5px;
--sdDeepRefShadowMulti2Color: rgba(0, 0, 0, 0.4);
--sdDeepRefShadowMulti2OffsetX: 0;
--sdDeepRefShadowMulti2OffsetY: 8px;`;
expect(content).to.equal(expectedOutput);
});
});
Loading
Loading