-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #455 from bcgov/feature/test-design-tokens-build
Design tokens test for expected output files
- Loading branch information
Showing
2 changed files
with
57 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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`); | ||
} | ||
}); |