An open source design system that's fully customizable and agent ready
TypeScript
test(cli): global-local's heaviest tests are split by case (#9746)
Christopher Chedeau58c5b8ab4c8c
diff --git a/packages/cli/test/global-local.test.mjs b/packages/cli/test/global-local.test.mjsindex 83410c77ae..e702107930 100644--- a/packages/cli/test/global-local.test.mjs+++ b/packages/cli/test/global-local.test.mjs@@ -877,13 +877,14 @@ describe.skipIf(!POSIX)().toBe('warn');});- it('the skill outlives the CLI installed for the computer: it repeats the step that installed it, and doctor names it too', () => {- for (const [layout, step] of /** @type {const} */ ([- // The npm layout is a prefix in the home folder, so the step names it.- ['npm', 'npm i -g --prefix ~/.npm-global @astryxdesign/cli'],- ['pnpm', 'pnpm add -g @astryxdesign/cli'],- ['bun', 'bun add -g @astryxdesign/cli'],- ])) {+ // One test for each layout: each starts the CLI three times.+ for (const [layout, step] of /** @type {const} */ ([+ // The npm layout is a prefix in the home folder, so the step names it.+ ['npm', 'npm i -g --prefix ~/.npm-global @astryxdesign/cli'],+ ['pnpm', 'pnpm add -g @astryxdesign/cli'],+ ['bun', 'bun add -g @astryxdesign/cli'],+ ])) {+ it(`the skill outlives the CLI installed for the computer (${layout}): it repeats the step that installed it, and doctor names it too`, () => {const pc = computer();let g;if (layout === 'bun') {@@ -959,8 +960,8 @@ describe.skipIf(!POSIX)();}pc.path.shift();- }- });+ });+ }// Volta's command is a shim of its own, not a link into the package, so// the search-path scan cannot trace it; an astryx on the search path that@@ -1753,15 +1754,38 @@ describe.skipIf(!POSIX)(});});- it("from a tool folder inside a project (as G36), discover and doctor point an integration installed for the computer at the project's folder, where its command adds it for good; with no project, discover names no command", () => {+ /**+ * The global npm copy on the search path, with `@acme/widgets` installed+ * beside it for the computer.+ */+ function computerWithWidgets() {const pc = computer();const g = globalCli('npm', '9.0.0', {root: pc.home});acmeWidgets(path.resolve(g.dir, '..', '..', '..'), {topic: 'acme-deploying',});pc.path.unshift(g.binDir);+ /** @param {string} cwd */+ const integrationsCheck = cwd =>+ JSON.parse(+ run(g.bin, ['doctor', '--json'], {cwd, pc}).stdout,+ ).data.checks.find(+ (/** @type {any} */ c) => c.id === 'computer-integrations',+ );+ return {pc, g, integrationsCheck};+ }++ /** A project with Core and the CLI, installed with npm. */+ function npmProject() {const dir = makeProject({core: '9.0.0', cli: '9.0.0'});writeJson(path.join(dir, 'package-lock.json'), {lockfileVersion: 3});+ return dir;+ }++ // As G36, in four cases; each runs the CLI at most twice.+ it("from a tool folder inside a project (as G36), discover and doctor point an integration installed for the computer at the project's folder", () => {+ const {pc, g, integrationsCheck} = computerWithWidgets();+ const dir = npmProject();const tool = path.join(dir, 'tools', 'codegen');writeJson(path.join(tool, 'package.json'), {name: 'codegen'});const discover = JSON.parse(@@ -1779,16 +1803,12 @@ describe.skipIf(!POSIX)(source: 'installed for this computer',},]);- const integrationsCheck = (/** @type {string} */ cwd) =>- JSON.parse(- run(g.bin, ['doctor', '--json'], {cwd, pc}).stdout,- ).data.checks.find(- (/** @type {any} */ c) => c.id === 'computer-integrations',- );expect(integrationsCheck(tool).fix).toBe(DOCTOR_RUN_FROM_PROJECT);+ });- // Followed: from the project's folder, the command adds it there, and- // once it is installed nothing is offered any more.+ it("from the project's folder (as G36), discover and doctor give the command that adds an integration installed for the computer", () => {+ const {pc, g, integrationsCheck} = computerWithWidgets();+ const dir = npmProject();const fromProject = JSON.parse(run(g.bin, ['discover', '--json'], {cwd: dir, pc}).stdout,);@@ -1798,6 +1818,11 @@ describe.skipIf(!POSIX)(expect(integrationsCheck(dir).fix).toBe('To use one in this project, run `npm install @acme/widgets`.',);+ });++ it('once the project installs it (as G36), discover and doctor no longer offer an integration installed for the computer', () => {+ const {pc, g, integrationsCheck} = computerWithWidgets();+ const dir = npmProject();const pkg = JSON.parse(fs.readFileSync(path.join(dir, 'package.json'), 'utf8'),);@@ -1811,7 +1836,10 @@ describe.skipIf(!POSIX)();expect(notOfficial(after)).toEqual([]);expect(integrationsCheck(dir)).not.toHaveProperty('fix');+ });+ it('with no project (as G36), discover names no command for an integration installed for the computer', () => {+ const {pc, g} = computerWithWidgets();// A folder that installs Core but belongs to no project.const alone = tempDir('alone');writeJson(path.join(alone, 'package.json'), {name: 'alone'});