From 3417c18ce071cf221822de0e61cc25ecb03ef101 Mon Sep 17 00:00:00 2001 From: Lukas Oppermann Date: Thu, 12 Sep 2024 10:42:36 +0200 Subject: [PATCH] fix for integreation test racing conditions (#1054) --- integration/baseline.test.ts | 98 ++++++----- integration/integration.test.ts | 292 ++++++++++++++++---------------- 2 files changed, 199 insertions(+), 191 deletions(-) diff --git a/integration/baseline.test.ts b/integration/baseline.test.ts index 56956b68e..97f2ca862 100644 --- a/integration/baseline.test.ts +++ b/integration/baseline.test.ts @@ -3,58 +3,62 @@ import fs from 'fs' describe('PrimerStyleDictionary', () => { const basePath = `./integration` - const extendedSD = PrimerStyleDictionary.extend({ - source: [`${basePath}/tokens/**/*.json5`], - platforms: { - css: { - prefix: 'PREFIX', - transformGroup: 'css', - buildPath: `${basePath}/build/css/`, - files: [ - { - options: { - showFileHeader: false, + const buildPath = `${basePath}/build/baseline` + + beforeAll(() => { + const extendedSD = PrimerStyleDictionary.extend({ + source: [`${basePath}/tokens/**/*.json5`], + platforms: { + css: { + prefix: 'PREFIX', + transformGroup: 'css', + buildPath: `${buildPath}/css/`, + files: [ + { + options: { + showFileHeader: false, + }, + destination: 'variables.css', + format: 'css/variables', }, - destination: 'variables.css', - format: 'css/variables', - }, - ], - }, - json: { - prefix: 'PREFIX', - buildPath: `${basePath}/build/json/`, - files: [ - { - options: { - showFileHeader: false, + ], + }, + json: { + prefix: 'PREFIX', + buildPath: `${buildPath}/json/`, + files: [ + { + options: { + showFileHeader: false, + }, + destination: 'variables.json', + format: 'json', }, - destination: 'variables.json', - format: 'json', - }, - ], - }, - jsonFlat: { - prefix: 'PREFIX', - buildPath: `${basePath}/build/json/`, - transforms: ['name/cti/pascal'], - files: [ - { - options: { - showFileHeader: false, + ], + }, + jsonFlat: { + prefix: 'PREFIX', + buildPath: `${buildPath}/json/`, + transforms: ['name/cti/pascal'], + files: [ + { + options: { + showFileHeader: false, + }, + destination: 'flat.json', + format: 'json/flat', }, - destination: 'flat.json', - format: 'json/flat', - }, - ], + ], + }, }, - }, - }) + }) - extendedSD.cleanAllPlatforms() - extendedSD.buildAllPlatforms() + extendedSD.cleanAllPlatforms() + extendedSD.buildAllPlatforms() + }) it('runs baseline css/variables format', () => { - const output = fs.readFileSync(`${basePath}/build/css/variables.css`, 'utf8') + const output = fs.readFileSync(`${buildPath}/css/variables.css`, 'utf8') const expectedOutput = `:root { --prefix-base-color-aqua-blue-500: #2C29FF; /* The primary color for interactive elements. */ --prefix-fg-color-link-rest-01: #2C29FF; @@ -64,7 +68,7 @@ describe('PrimerStyleDictionary', () => { }) it('runs baseline json format', () => { - const output = fs.readFileSync(`${basePath}/build/json/variables.json`, 'utf8') + const output = fs.readFileSync(`${buildPath}/json/variables.json`, 'utf8') const expectedOutput = `{ "base": { "color": { @@ -116,7 +120,7 @@ describe('PrimerStyleDictionary', () => { }) it('runs baseline flat json format', () => { - const output = fs.readFileSync(`${basePath}/build/json/flat.json`, 'utf8') + const output = fs.readFileSync(`${buildPath}/json/flat.json`, 'utf8') const expectedOutput = `{ "PrefixBaseColorAquaBlue500": "#2C29FF", "PrefixFgColorLinkRest01": "#2C29FF" diff --git a/integration/integration.test.ts b/integration/integration.test.ts index d43c15634..7d440243a 100644 --- a/integration/integration.test.ts +++ b/integration/integration.test.ts @@ -3,155 +3,159 @@ import fs from 'fs' describe('PrimerStyleDictionary', () => { const basePath = `./integration` - const extendedSD = PrimerStyleDictionary.extend({ - source: [`${basePath}/tokens/**/*.json5`], - platforms: { - advancedCss: { - prefix: 'PREFIX', - transforms: [ - 'name/pathToKebabCase', - 'color/hex', - 'color/hexMix', - 'dimension/rem', - 'duration/css', - 'shadow/css', - 'border/css', - 'typography/css', - 'fontFamily/css', - 'fontWeight/number', - ], - buildPath: `${basePath}/build/css/`, - files: [ - { - options: { - showFileHeader: false, + const buildPath = `${basePath}/build/integreation` + + beforeAll(() => { + const extendedSD = PrimerStyleDictionary.extend({ + source: [`${basePath}/tokens/**/*.json5`], + platforms: { + advancedCss: { + prefix: 'PREFIX', + transforms: [ + 'name/pathToKebabCase', + 'color/hex', + 'color/hexMix', + 'dimension/rem', + 'duration/css', + 'shadow/css', + 'border/css', + 'typography/css', + 'fontFamily/css', + 'fontWeight/number', + ], + buildPath: `${buildPath}/css/`, + files: [ + { + options: { + showFileHeader: false, + }, + destination: 'advanced.css', + format: 'css/advanced', }, - destination: 'advanced.css', - format: 'css/advanced', - }, - ], - }, - commonJs: { - prefix: 'PREFIX', - transforms: [ - 'color/hex', - 'color/hexMix', - 'dimension/rem', - 'shadow/css', - 'border/css', - 'typography/css', - 'fontFamily/css', - 'fontWeight/number', - ], - buildPath: `${basePath}/build/js/`, - files: [ - { - options: { - showFileHeader: false, + ], + }, + commonJs: { + prefix: 'PREFIX', + transforms: [ + 'color/hex', + 'color/hexMix', + 'dimension/rem', + 'shadow/css', + 'border/css', + 'typography/css', + 'fontFamily/css', + 'fontWeight/number', + ], + buildPath: `${buildPath}/js/`, + files: [ + { + options: { + showFileHeader: false, + }, + destination: 'common.js', + format: 'javascript/commonJs', }, - destination: 'common.js', - format: 'javascript/commonJs', - }, - ], - }, - javascriptEsm: { - prefix: 'PREFIX', - buildPath: `${basePath}/build/js/`, - transforms: [ - 'color/hex', - 'color/hexMix', - 'dimension/rem', - 'shadow/css', - 'border/css', - 'typography/css', - 'fontFamily/css', - 'fontWeight/number', - ], - files: [ - { - options: { - showFileHeader: false, + ], + }, + javascriptEsm: { + prefix: 'PREFIX', + buildPath: `${buildPath}/js/`, + transforms: [ + 'color/hex', + 'color/hexMix', + 'dimension/rem', + 'shadow/css', + 'border/css', + 'typography/css', + 'fontFamily/css', + 'fontWeight/number', + ], + files: [ + { + options: { + showFileHeader: false, + }, + destination: 'esm.mjs', + format: 'javascript/esm', }, - destination: 'esm.mjs', - format: 'javascript/esm', - }, - ], - }, - jsonFigma: { - prefix: 'PREFIX', - buildPath: `${basePath}/build/json/`, - transforms: [ - 'color/rgbaFloat', - 'name/pathToFigma', - 'figma/attributes', - 'fontFamily/figma', - 'float/pixelUnitless', - 'dimension/pixelUnitless', - 'fontWeight/number', - ], - files: [ - { - options: { - showFileHeader: false, + ], + }, + jsonFigma: { + prefix: 'PREFIX', + buildPath: `${buildPath}/json/`, + transforms: [ + 'color/rgbaFloat', + 'name/pathToFigma', + 'figma/attributes', + 'fontFamily/figma', + 'float/pixelUnitless', + 'dimension/pixelUnitless', + 'fontWeight/number', + ], + files: [ + { + options: { + showFileHeader: false, + }, + destination: 'figma.json', + format: 'json/figma', }, - destination: 'figma.json', - format: 'json/figma', - }, - ], - }, - jsonNestedPrefixed: { - prefix: 'PREFIX', - buildPath: `${basePath}/build/json/`, - transforms: [ - 'color/hex', - 'color/hexMix', - 'dimension/rem', - 'shadow/css', - 'border/css', - 'typography/css', - 'fontFamily/css', - 'fontWeight/number', - ], - files: [ - { - options: { - showFileHeader: false, + ], + }, + jsonNestedPrefixed: { + prefix: 'PREFIX', + buildPath: `${buildPath}/json/`, + transforms: [ + 'color/hex', + 'color/hexMix', + 'dimension/rem', + 'shadow/css', + 'border/css', + 'typography/css', + 'fontFamily/css', + 'fontWeight/number', + ], + files: [ + { + options: { + showFileHeader: false, + }, + destination: 'nested.json', + format: 'json/nested-prefixed', }, - destination: 'nested.json', - format: 'json/nested-prefixed', - }, - ], - }, - tsDefinition: { - prefix: 'PREFIX', - buildPath: `${basePath}/build/js/`, - transforms: [ - 'color/hex', - 'shadow/css', - 'border/css', - 'dimension/rem', - 'typography/css', - 'fontFamily/css', - 'fontWeight/number', - ], - files: [ - { - options: { - showFileHeader: false, + ], + }, + tsDefinition: { + prefix: 'PREFIX', + buildPath: `${buildPath}/js/`, + transforms: [ + 'color/hex', + 'shadow/css', + 'border/css', + 'dimension/rem', + 'typography/css', + 'fontFamily/css', + 'fontWeight/number', + ], + files: [ + { + options: { + showFileHeader: false, + }, + destination: 'definitions.d.ts', + format: 'typescript/export-definition', }, - destination: 'definitions.d.ts', - format: 'typescript/export-definition', - }, - ], + ], + }, }, - }, - }) + }) - extendedSD.cleanAllPlatforms() - extendedSD.buildAllPlatforms() + extendedSD.cleanAllPlatforms() + extendedSD.buildAllPlatforms() + }) it('runs css/advanced format', () => { - const output = fs.readFileSync(`${basePath}/build/css/advanced.css`, 'utf8') + const output = fs.readFileSync(`${buildPath}/css/advanced.css`, 'utf8') const expectedOutput = `:root { --PREFIX-base-color-aquaBlue-500: #2c29ff; /* The primary color for interactive elements. */ --PREFIX-fgColor-link-rest-01: #2c29ff; @@ -161,7 +165,7 @@ describe('PrimerStyleDictionary', () => { }) it('runs commonJs format', () => { - const output = fs.readFileSync(`${basePath}/build/js/common.js`, 'utf8') + const output = fs.readFileSync(`${buildPath}/js/common.js`, 'utf8') const expectedOutput = `module.exports = { PREFIX: { base: { @@ -181,7 +185,7 @@ describe('PrimerStyleDictionary', () => { }) it('runs esm format', () => { - const output = fs.readFileSync(`${basePath}/build/js/esm.mjs`, 'utf8') + const output = fs.readFileSync(`${buildPath}/js/esm.mjs`, 'utf8') const expectedOutput = `export default { PREFIX: { base: { @@ -201,7 +205,7 @@ describe('PrimerStyleDictionary', () => { }) it('runs figma format', () => { - const output = fs.readFileSync(`${basePath}/build/json/figma.json`, 'utf8') + const output = fs.readFileSync(`${buildPath}/json/figma.json`, 'utf8') const expectedOutput = `[ { "name": "PREFIX/base/color/aquaBlue/500", @@ -237,7 +241,7 @@ describe('PrimerStyleDictionary', () => { }) it('runs json-nested-prefixed format', () => { - const output = fs.readFileSync(`${basePath}/build/json/nested.json`, 'utf8') + const output = fs.readFileSync(`${buildPath}/json/nested.json`, 'utf8') const expectedOutput = `{ "PREFIX": { "base": { @@ -257,7 +261,7 @@ describe('PrimerStyleDictionary', () => { }) it('runs ts definition format', () => { - const output = fs.readFileSync(`${basePath}/build/js/definitions.d.ts`, 'utf8') + const output = fs.readFileSync(`${buildPath}/js/definitions.d.ts`, 'utf8') const expectedOutput = `/** * @description hex string (6 or 8-digit) */