Mocked test suite (`npm run test:mocked`) is too slow — speed it up without losing coverage
@YuryShkoda is already working on this.
Since Jul 3, 2026.
Assessment
This issue has not been assessed yet.
Description
Problem
npm run test:mocked currently takes ~9 minutes (80 suites / 589 tests, ~513-525s wall time across multiple recent runs) even though it's meant to be the fast, mocked/offline test path (as opposed to test:server, which talks to real servers). A handful of spec files dominate that time.
The worst offender is src/commands/testing/spec/testing.spec.ts, which alone took ~307s in one measured run — roughly 60% of the entire suite's runtime — for only 6 it() blocks. Digging into why:
- It calls
createTestApp()(twice), which (viacreate()) runssetupNpmProject()whenever no app type is given — this shells out to realnpm init --yesandnpm i @sasjs/core --save(src/utils/utils.ts). Real npm installs against the real registry are slow and also make the "mocked" suite dependent on network/registry availability. - Several other spec files that call
createTestApp/createReactApp/createAngularApp/etc. likely pay the same real-npm-install and real-template-download tax (e.g.create.spec.ts'screateReactApptest took ~25s by itself in a recent run).
Notably, create.spec.ts already solved this exact problem for its own suite:
jest.spyOn(shelljs, 'exec').mockImplementation((command: string) => {
if (!command.includes('npm install')) {
return exec(command, { silent: true })
}
return undefined
})
This lets everything except the slow npm install step run for real. That pattern isn't applied anywhere else, so other spec files (like testing.spec.ts) still pay the full real-install cost on every run.
Goal
Make npm run test:mocked meaningfully faster (target: cut total runtime significantly, e.g. by half or more) without reducing what's actually being verified. Speed must never come at the cost of weaker coverage of real logic — if a shortcut risks masking a regression, don't take it.
Suggested approach
- Audit per-file/per-suite timing (
jest --verboseor--jsonoutput) to get an authoritative ranking of the slowest spec files, rather than relying on the two data points above. - Extend the existing
create.spec.ts"skip realnpm install"shelljs.execmocking pattern to every spec file that goes throughcreateTestApp,createReactApp,createAngularApp,createMinimalApp, orcreateTemplateApp(directly or indirectly), since none of these tests are asserting on npm's actual install behavior. - Identify any other real, slow I/O in hot-path spec files (real template downloads from GitHub, redundant
compile()/build()cycles re-run perit()instead of once perdescribe()viabeforeAll, etc.) and either mock it or hoist it out of per-test setup where correctness allows. - Re-measure after each change to confirm both the speed improvement and that coverage thresholds (
jest.config.js→coverageThreshold) still hold or improve — no test should be deleted or weakened purely to save time. - Document any newly-established "mock slow I/O, keep everything else real" pattern (e.g. in a shared test helper in
src/utils/test.ts) so future spec files adopt it by default instead of reinventing/re-discovering it.
Priority note
Reviewers should treat coverage of actual CLI logic as non-negotiable: any PR addressing this issue should show before/after timing and before/after coverage numbers, and should be rejected if it trades correctness confidence for speed.
- Dominant language
- TypeScript
- Stars
- 40
- Forks
- 6
- Avg merge
- 1d 16h
- Merged PRs (30d)
- 4
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from sasjs/cli
-
Difficulty 3/5 1-2 days Newbie friendliness 48/100
-
refactoring
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
-
adapter refactoring
Similar issues
-
clawsweeper:fix-shape-clear clawsweeper:queueable-fix clawsweeper:source-repro impact:ux-friction issue-rating: 🦞 diamond lobster no-stale P3
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
community first-timers-only good first issue hacktoberfest help wanted low hanging fruit up-for-grabs
Difficulty 1/5 Under an hour Newbie friendliness 76/100
-
code-quality refactoring
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
github/gh-aw-firewall#8816 ·
-
integration:quickjs org:external priority:backlog topic:code-interpreter topic:middleware type:feature
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
langchain-ai/deepagents#6450 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
vercel/react-tweet#225 ·