Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

test(cli): pack-check builds its ocean theme fixture once per file (#9813)

Christopher Chedeau93484190b635
diff --git a/packages/cli/api/integration/pack-check.test.mjs b/packages/cli/api/integration/pack-check.test.mjs
index c8a21e516b..fe6883e31e 100644
--- a/packages/cli/api/integration/pack-check.test.mjs
+++ b/packages/cli/api/integration/pack-check.test.mjs
@@ -201,6 +201,49 @@ describe('verify-only generated CSS header normalization', () => {
});
});
+/**
+ * The files `theme build` writes for the ocean fixture, by name. The build
+ * writes the same bytes in any folder, so the file builds once and each
+ * fixture gets a copy.
+ * @type {Map<string, Buffer> | null}
+ */
+let builtOcean = null;
+
+/**
+ * Put the ocean theme's built files beside its source in `oceanDir`.
+ * @param {string} oceanDir
+ */
+function writeBuiltOcean(oceanDir) {
+ if (builtOcean != null) {
+ for (const [file, bytes] of builtOcean) {
+ fs.writeFileSync(path.join(oceanDir, file), bytes);
+ }
+ return;
+ }
+ const sources = new Set(fs.readdirSync(oceanDir));
+ const built = spawnSync(
+ process.execPath,
+ [
+ path.join(process.cwd(), 'packages/cli/clients/cli/bin/astryx.mjs'),
+ 'theme',
+ 'build',
+ 'themes/ocean/oceanTheme.ts',
+ ],
+ {cwd: tmpDir, encoding: 'utf-8', timeout: 30_000},
+ );
+ if (built.status !== 0) {
+ throw new Error(
+ `Could not build the theme fixture: ${built.stderr || built.stdout}`,
+ );
+ }
+ builtOcean = new Map(
+ fs
+ .readdirSync(oceanDir)
+ .filter(file => !sources.has(file))
+ .map(file => [file, fs.readFileSync(path.join(oceanDir, file))]),
+ );
+}
+
/**
* Write a minimal integration package into tmpDir.
* Returns the package directory.
@@ -249,21 +292,7 @@ export default {type: 'theme', name: 'ocean', displayName: 'Ocean', description:
`,
);
if (themeExports) {
- const built = spawnSync(
- process.execPath,
- [
- path.join(process.cwd(), 'packages/cli/clients/cli/bin/astryx.mjs'),
- 'theme',
- 'build',
- 'themes/ocean/oceanTheme.ts',
- ],
- {cwd: tmpDir, encoding: 'utf-8', timeout: 30_000},
- );
- if (built.status !== 0) {
- throw new Error(
- `Could not build the theme fixture: ${built.stderr || built.stdout}`,
- );
- }
+ writeBuiltOcean(path.join(root, 'ocean'));
}
}
if (components) {