An open source design system that's fully customizable and agent ready
TypeScript
fix(cli): swizzle leaves out browser test harnesses (#10230)
Cindy Zhang8b6b810602f1
diff --git a/.changeset/swizzle-skips-spec-harnesses.md b/.changeset/swizzle-skips-spec-harnesses.mdnew file mode 100644index 0000000000..f369846923--- /dev/null+++ b/.changeset/swizzle-skips-spec-harnesses.md@@ -0,0 +1,7 @@+---+'@astryxdesign/cli': patch+---++[fix] `swizzle` no longer copies a component's browser test harnesses (`*.spec.ts`, `*.spec.tsx`, such as Item's `ItemMarkerColumns.a11y.chromium.spec.ts`) when the installed Core source holds them: `@astryxdesign/core` 0.7.5 and earlier, or Core's repository source. They import Playwright and an unpublished test package, so a project that swizzled such a component failed to type-check or build. Core 0.7.6 and later ship no harnesses, so swizzling from them is unchanged.++@cixzhangdiff --git a/packages/cli/api/swizzle/copy/copy.mjs b/packages/cli/api/swizzle/copy/copy.mjsindex 710886a3c1..20e21ebb69 100644--- a/packages/cli/api/swizzle/copy/copy.mjs+++ b/packages/cli/api/swizzle/copy/copy.mjs@@ -342,7 +342,11 @@ function confineWrite(target, cwd, options) {/** @param {string} file */function isExcludedFromCopy(file) {return (- file.includes('.test.') || file.includes('.doc.') || file === 'README.md'+ file.includes('.test.') ||+ file.includes('.doc.') ||+ file === 'README.md' ||+ // Browser test harnesses import dev-only packages a consumer cannot resolve.+ /\.spec\.[cm]?[jt]sx?$/.test(file));}diff --git a/packages/cli/api/swizzle/copy/copy.test.mjs b/packages/cli/api/swizzle/copy/copy.test.mjsindex bd9777ced9..7f6b3a1245 100644--- a/packages/cli/api/swizzle/copy/copy.test.mjs+++ b/packages/cli/api/swizzle/copy/copy.test.mjs@@ -276,3 +276,26 @@ describe('swizzle.copy — private attribute owner modules (spec:AST-110 FR4)',SLOW,);});++describe('swizzle.copy — browser test harnesses', () => {+ afterEach(() => {+ fs.rmSync(path.join(REPO, OUT), {recursive: true, force: true});+ });++ it('leaves out a component folder\'s *.spec.ts harnesses, which import dev-only packages', async () => {+ const harness = path.join(+ REPO,+ 'packages/core/src/Item/ItemMarkerColumns.a11y.chromium.spec.ts',+ );+ expect(fs.existsSync(harness)).toBe(true);+ const r = await swizzle('Item', {cwd: REPO, output: './' + OUT});+ expect(r.data.files.filter(f => /\.spec\.[cm]?[jt]sx?$/.test(f))).toEqual([]);+ expect(+ fs.existsSync(+ path.join(REPO, OUT, 'Item', 'ItemMarkerColumns.a11y.chromium.spec.ts'),+ ),+ ).toBe(false);+ // The component's own source still comes along.+ expect(r.data.files).toContain('Item.tsx');+ }, SLOW);+});