From da46f8c2fd7ef711586f7824728c4cba4ccdca27 Mon Sep 17 00:00:00 2001 From: Tyler Krys Date: Mon, 19 Aug 2024 13:22:34 -0700 Subject: [PATCH 1/3] Update README to include test information --- packages/design-tokens/README.md | 39 ++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/packages/design-tokens/README.md b/packages/design-tokens/README.md index 6390f1b4..2de7e78b 100644 --- a/packages/design-tokens/README.md +++ b/packages/design-tokens/README.md @@ -1,6 +1,6 @@ -# Design Tokens for BC Design System +# Design Tokens for B.C. Design System -[![Lifecycle:Experimental](https://img.shields.io/badge/Lifecycle-Experimental-339999)](https://github.com/bcgov/repomountie/blob/master/doc/lifecycle-badges.md) +[![Lifecycle:Maturing](https://img.shields.io/badge/Lifecycle-Maturing-007EC6)](https://github.com/bcgov/repomountie/blob/master/doc/lifecycle-badges.md) This package is used to export and publish design tokens from Figma to npm for the B.C. Design System. The tokens generated by this package are available for install from npm: [@bcgov/design-tokens](https://www.npmjs.com/package/@bcgov/design-tokens) @@ -25,23 +25,28 @@ See `dist/README.md` for how to use the design tokens in your project. 5. Manually update the package version in `dist/package.json`. 6. Run `npm run publish-npm-package` to publish the contents of `dist` to npm. +## Test the build script + +A Node.js test script is included to confirm that the build script runs as intended: `npm run test` + ## Folder structure ``` . -├── CHANGELOG.md - log of notable changes by version -├── README.md - this file -├── build - output of build script from style-dictionary -├── build-output.js - build script -├── dist - published to npm as @bcgov/design-tokens -│   ├── README.md - instructions for using @bcgov/design-tokens -│   ├── cjs - CommonJS tokens -│   ├── cjs-prefixed - CommonJS tokens with "bcds" added -│   ├── css - CSS tokens -│   ├── css-prefixed - CSS tokens with "bcds" added -│   ├── js - ECMAScript Module (ESM) tokens -│   ├── js-prefixed - ESM tokens with "bcds" added -│   └── package.json - package.json for @bcgov/design-tokens -├── input - raw design tokens JSON data from Tokens Studio for Figma -└── package.json - package.json for tokens transformation pipeline +├── CHANGELOG.md - log of notable changes by version +├── README.md - this file +├── build - output of build script from style-dictionary +├── build-output.js - build script +├── build-output.test.js - test suite for build script +├── dist - published to npm as @bcgov/design-tokens +│   ├── README.md - instructions for using @bcgov/design-tokens +│   ├── cjs - CommonJS tokens +│   ├── cjs-prefixed - CommonJS tokens with "bcds" added +│   ├── css - CSS tokens +│   ├── css-prefixed - CSS tokens with "bcds" added +│   ├── js - ECMAScript Module (ESM) tokens +│   ├── js-prefixed - ESM tokens with "bcds" added +│   └── package.json - package.json for @bcgov/design-tokens +├── input - raw design tokens JSON data from Tokens Studio for Figma +└── package.json - package.json for tokens transformation pipeline ``` From 12c5f8fa1721122ce80514bdc49cc66a11a9a706 Mon Sep 17 00:00:00 2001 From: Tyler Krys Date: Mon, 19 Aug 2024 13:24:30 -0700 Subject: [PATCH 2/3] Test for build removes contents of build directory before script is run --- packages/design-tokens/build-output.test.js | 22 ++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/packages/design-tokens/build-output.test.js b/packages/design-tokens/build-output.test.js index 8b9f1165..7567b0c2 100644 --- a/packages/design-tokens/build-output.test.js +++ b/packages/design-tokens/build-output.test.js @@ -5,16 +5,20 @@ import assert from "node:assert"; test("build-output.js should complete without errors", async () => { try { await new Promise((resolve, reject) => { - // Execute the build script using Node.js - exec("node build-output.js", (error, stdout, stderr) => { - // If there was an error, the test should fail - if (error) { - console.error("Error executing build-output.js:", stderr); - return reject(new Error("build-output.js threw an error")); + // Execute the `build` script from package.json, removing the build + // directory contents before running build-output.js. + exec( + "rm -rf build/cjs* && rm -rf build/css* && rm -rf build/js* && node build-output.js", + (error, stdout, stderr) => { + // If there was an error, the test should fail. + if (error) { + console.error("Error executing build-output.js:", stderr); + return reject(new Error("build-output.js threw an error")); + } + console.log("build-output.js executed successfully:", stdout); + resolve(); } - console.log("build-output.js executed successfully:", stdout); - resolve(); - }); + ); }); assert.ok(true); } catch (error) { From 8e58de39da3766fd2f3adcfb2e020e567fc454be Mon Sep 17 00:00:00 2001 From: Tyler Krys Date: Mon, 19 Aug 2024 13:27:47 -0700 Subject: [PATCH 3/3] Add test to check for the presence of expected output files --- packages/design-tokens/build-output.test.js | 22 +++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/packages/design-tokens/build-output.test.js b/packages/design-tokens/build-output.test.js index 7567b0c2..d8884ef3 100644 --- a/packages/design-tokens/build-output.test.js +++ b/packages/design-tokens/build-output.test.js @@ -1,6 +1,8 @@ import { exec } from "child_process"; +import { existsSync } from "fs"; import { test } from "node:test"; import assert from "node:assert"; +import { join } from "path"; test("build-output.js should complete without errors", async () => { try { @@ -25,3 +27,23 @@ test("build-output.js should complete without errors", async () => { assert.fail(error.message); } }); + +test("output files should exist after running build-output.js", async () => { + const outputFiles = [ + "build/css/variables.css", + "build/css-prefixed/variables.css", + "build/js/index.js", + "build/js/index.d.ts", + "build/js-prefixed/index.js", + "build/js-prefixed/index.d.ts", + "build/cjs/index.js", + "build/cjs/index.d.ts", + "build/cjs-prefixed/index.js", + "build/cjs-prefixed/index.d.ts", + ]; + + for (const file of outputFiles) { + const filePath = join(process.cwd(), file); + assert.ok(existsSync(filePath), `Expected file ${file} to exist`); + } +});