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

Design tokens test for expected output files #455

Merged
merged 3 commits into from
Aug 19, 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
39 changes: 22 additions & 17 deletions packages/design-tokens/README.md
Original file line number Diff line number Diff line change
@@ -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)

Expand All @@ -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
```
44 changes: 35 additions & 9 deletions packages/design-tokens/build-output.test.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,49 @@
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 {
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) {
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`);
}
});