Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
test(scripts): gate the test:scripts lane on disk
Yudhi Armyndharis200803c4daa7
diff --git a/src/common/test-lane-partition.spec.ts b/src/common/test-lane-partition.spec.tsindex ee2f66436..0854b3a16 100644--- a/src/common/test-lane-partition.spec.ts+++ b/src/common/test-lane-partition.spec.ts@@ -1,4 +1,4 @@-import { existsSync, readFileSync } from 'node:fs';+import { existsSync, readFileSync, readdirSync } from 'node:fs';import { join } from 'node:path';/**@@ -12,7 +12,7 @@ import { join } from 'node:path';describe('Test lane partition', () => {const repoRoot = join(__dirname, '..', '..');const pkg = JSON.parse(readFileSync(join(repoRoot, 'package.json'), 'utf8')) as {- scripts: { 'test:docs'?: string };+ scripts: { 'test:docs'?: string; 'test:scripts'?: string };jest?: { testPathIgnorePatterns?: string[]; coveragePathIgnorePatterns?: string[] };};@@ -82,6 +82,33 @@ describe('Test lane partition', () => {expect(notASpec).toEqual([]);});+ /**+ * `scripts/` has its own lane. `test:scripts` hands node:test an explicit list of positionals,+ * and jest never looks in that directory, so the two lanes cannot cover for each other: a spec+ * written under `scripts/` and left out of that string runs NOWHERE, and nothing fails to say so.+ *+ * Unlike the doc lane above there is no second list to compare against, so the comparison is+ * against the directory itself. That also catches the reverse, a renamed or deleted spec still+ * named by the script, which makes the whole node:test invocation exit non-zero on a file it+ * cannot open.+ */+ it('runs every spec under scripts/ in the test:scripts lane', () => {+ const isSpec = (name: string): boolean => name.endsWith('.spec.js') || name.endsWith('.spec.mjs');+ const onDisk = readdirSync(join(repoRoot, 'scripts'))+ .filter(isSpec)+ .map(name => `scripts/${name}`);+ const named = (pkg.scripts['test:scripts'] ?? '').split(/\s+/).filter(isSpec);++ // Vacuity guard: an empty directory scan or an unparsed script would pass the diff below.+ expect(onDisk.length).toBeGreaterThan(10);+ expect(named.length).toBeGreaterThan(10);++ expect({+ neverRun: onDisk.filter(path => !named.includes(path)).sort(),+ namedButAbsent: named.filter(path => !onDisk.includes(path)).sort(),+ }).toEqual({ neverRun: [], namedButAbsent: [] });+ });+it('names suites that exist on disk', () => {const paths = [...new Set([...docLane(), ...unitLaneExcludes().map(asPath)])];expect(paths.length).toBeGreaterThan(20);