build(server): the test-mock and hand-built-service ratchets read code, not comments, and see the import() and alias forms

lint:test-mocks missed vi.mock(import('../src/config'), ...), the typed form Vitest takes, and counted mocks quoted in doc comments, which left slack a real mock could take. lint:test-new-service missed a service built under an import alias or as new (Name)(...). Both now strip comments first and recognise those forms; the baselines lose the entries that were only comments.
This commit is contained in:
Maurice
2026-10-10 19:56:54 +02:00
parent ef68c62d80
commit ac918d362f
6 changed files with 106 additions and 23 deletions
@@ -77,6 +77,19 @@ describe('lint:test-mocks', () => {
expect(countHeldMocks(text)).toBe(0);
});
it('TEST-RATCHET-005: counts the import() form of a mock, and not a mock quoted in a comment', () => {
const text = [
`${MOCK}import('../../src/config'), () => ({}));`,
`${DO_MOCK}import("../../src/db/database"), async () => ({}));`,
'/**',
` * ${MOCK}'../../src/db/database', async () =>`,
' */',
`// ${MOCK}'../../src/config', () => ({}));`,
`const path = "// not a comment"; ${MOCK}'../../src/nest/realtime/realtime.service', () => ({}));`,
].join('\n');
expect(countHeldMocks(text)).toBe(3);
});
it('TEST-RATCHET-003: fails a new mock, passes at the baseline and fails a stale entry until --update', () => {
const mock = `${MOCK}'../../src/config', () => ({}));\n`;
const grown = run(
@@ -151,6 +164,19 @@ describe('lint:test-new-service', () => {
expect(countNewServices(text, new Set(['RealtimeService']))).toBe(3);
});
it('TEST-RATCHET-016: an import alias and a parenthesised class count as the service they name, a comment does not', () => {
const text = [
"import { DaysService as Days, TodoService } from '../../src/nest/days/days.service';",
"import { RealtimeService as Rt } from '../../src/nest/realtime/realtime.service';",
`const a = ${NEW}Days(repo, uow);`,
`const b = ${['ne', 'w'].join('')}(TodoService)(permissions);`,
`const c = ${NEW}Rt();`,
`// const d = ${NEW}DaysService(repo, uow);`,
`const e = ${NEW}Map<string, Days>();`,
].join('\n');
expect(countNewServices(text, new Set(['RealtimeService']))).toBe(2);
});
it('TEST-RATCHET-013: derives the allowlist from src/ and tests/helpers/ when it runs', () => {
const files = {
'src/plain.service.ts': 'export class PlainService { ping() {} }',