Skip to content

Commit 58c5b8a

Browse files
authored
test(cli): global-local's heaviest tests are split by case (#9746)
test(cli): global-local's heaviest tests are split by case Two tests in global-local.test.mjs started the CLI 9 and 13 times each: the skill test looped over three install layouts, and the tool folder test checked four cases in a row. Each CLI start costs about 0.6 s of CPU, so on a busy machine those tests ran past the 30 s limit. The skill test is now one test for each layout, with 3 starts each. The tool folder test is now four tests, one for each case, with at most 4 starts each. Every assertion is kept, and the file starts the CLI as many times as before.
1 parent 9ee4282 commit 58c5b8a

1 file changed

Lines changed: 46 additions & 18 deletions

File tree

‎packages/cli/test/global-local.test.mjs‎

Lines changed: 46 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -877,13 +877,14 @@ describe.skipIf(!POSIX)(
877877
).toBe('warn');
878878
});
879879

880-
it('the skill outlives the CLI installed for the computer: it repeats the step that installed it, and doctor names it too', () => {
881-
for (const [layout, step] of /** @type {const} */ ([
882-
// The npm layout is a prefix in the home folder, so the step names it.
883-
['npm', 'npm i -g --prefix ~/.npm-global @astryxdesign/cli'],
884-
['pnpm', 'pnpm add -g @astryxdesign/cli'],
885-
['bun', 'bun add -g @astryxdesign/cli'],
886-
])) {
880+
// One test for each layout: each starts the CLI three times.
881+
for (const [layout, step] of /** @type {const} */ ([
882+
// The npm layout is a prefix in the home folder, so the step names it.
883+
['npm', 'npm i -g --prefix ~/.npm-global @astryxdesign/cli'],
884+
['pnpm', 'pnpm add -g @astryxdesign/cli'],
885+
['bun', 'bun add -g @astryxdesign/cli'],
886+
])) {
887+
it(`the skill outlives the CLI installed for the computer (${layout}): it repeats the step that installed it, and doctor names it too`, () => {
887888
const pc = computer();
888889
let g;
889890
if (layout === 'bun') {
@@ -959,8 +960,8 @@ describe.skipIf(!POSIX)(
959960
);
960961
}
961962
pc.path.shift();
962-
}
963-
});
963+
});
964+
}
964965

965966
// Volta's command is a shim of its own, not a link into the package, so
966967
// the search-path scan cannot trace it; an astryx on the search path that
@@ -1753,15 +1754,38 @@ describe.skipIf(!POSIX)(
17531754
});
17541755
});
17551756

1756-
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", () => {
1757+
/**
1758+
* The global npm copy on the search path, with `@acme/widgets` installed
1759+
* beside it for the computer.
1760+
*/
1761+
function computerWithWidgets() {
17571762
const pc = computer();
17581763
const g = globalCli('npm', '9.0.0', {root: pc.home});
17591764
acmeWidgets(path.resolve(g.dir, '..', '..', '..'), {
17601765
topic: 'acme-deploying',
17611766
});
17621767
pc.path.unshift(g.binDir);
1768+
/** @param {string} cwd */
1769+
const integrationsCheck = cwd =>
1770+
JSON.parse(
1771+
run(g.bin, ['doctor', '--json'], {cwd, pc}).stdout,
1772+
).data.checks.find(
1773+
(/** @type {any} */ c) => c.id === 'computer-integrations',
1774+
);
1775+
return {pc, g, integrationsCheck};
1776+
}
1777+
1778+
/** A project with Core and the CLI, installed with npm. */
1779+
function npmProject() {
17631780
const dir = makeProject({core: '9.0.0', cli: '9.0.0'});
17641781
writeJson(path.join(dir, 'package-lock.json'), {lockfileVersion: 3});
1782+
return dir;
1783+
}
1784+
1785+
// As G36, in four cases; each runs the CLI at most twice.
1786+
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", () => {
1787+
const {pc, g, integrationsCheck} = computerWithWidgets();
1788+
const dir = npmProject();
17651789
const tool = path.join(dir, 'tools', 'codegen');
17661790
writeJson(path.join(tool, 'package.json'), {name: 'codegen'});
17671791
const discover = JSON.parse(
@@ -1779,16 +1803,12 @@ describe.skipIf(!POSIX)(
17791803
source: 'installed for this computer',
17801804
},
17811805
]);
1782-
const integrationsCheck = (/** @type {string} */ cwd) =>
1783-
JSON.parse(
1784-
run(g.bin, ['doctor', '--json'], {cwd, pc}).stdout,
1785-
).data.checks.find(
1786-
(/** @type {any} */ c) => c.id === 'computer-integrations',
1787-
);
17881806
expect(integrationsCheck(tool).fix).toBe(DOCTOR_RUN_FROM_PROJECT);
1807+
});
17891808

1790-
// Followed: from the project's folder, the command adds it there, and
1791-
// once it is installed nothing is offered any more.
1809+
it("from the project's folder (as G36), discover and doctor give the command that adds an integration installed for the computer", () => {
1810+
const {pc, g, integrationsCheck} = computerWithWidgets();
1811+
const dir = npmProject();
17921812
const fromProject = JSON.parse(
17931813
run(g.bin, ['discover', '--json'], {cwd: dir, pc}).stdout,
17941814
);
@@ -1798,6 +1818,11 @@ describe.skipIf(!POSIX)(
17981818
expect(integrationsCheck(dir).fix).toBe(
17991819
'To use one in this project, run `npm install @acme/widgets`.',
18001820
);
1821+
});
1822+
1823+
it('once the project installs it (as G36), discover and doctor no longer offer an integration installed for the computer', () => {
1824+
const {pc, g, integrationsCheck} = computerWithWidgets();
1825+
const dir = npmProject();
18011826
const pkg = JSON.parse(
18021827
fs.readFileSync(path.join(dir, 'package.json'), 'utf8'),
18031828
);
@@ -1811,7 +1836,10 @@ describe.skipIf(!POSIX)(
18111836
);
18121837
expect(notOfficial(after)).toEqual([]);
18131838
expect(integrationsCheck(dir)).not.toHaveProperty('fix');
1839+
});
18141840

1841+
it('with no project (as G36), discover names no command for an integration installed for the computer', () => {
1842+
const {pc, g} = computerWithWidgets();
18151843
// A folder that installs Core but belongs to no project.
18161844
const alone = tempDir('alone');
18171845
writeJson(path.join(alone, 'package.json'), {name: 'alone'});

0 commit comments

Comments
 (0)