Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

test(ci): fail when a *.pg.spec.ts is missing from the postgres job

Yudhi Armyndharis4eb417f478bb
diff --git a/src/common/test-lane-partition.spec.ts b/src/common/test-lane-partition.spec.ts
index 0854b3a16..62a6fd62d 100644
--- a/src/common/test-lane-partition.spec.ts
+++ b/src/common/test-lane-partition.spec.ts
@@ -1,5 +1,6 @@
import { existsSync, readFileSync, readdirSync } from 'node:fs';
import { join } from 'node:path';
+import * as yaml from 'js-yaml';
/**
* The doc-lint suites live in two hand-maintained lists in package.json: the `test:docs` script
@@ -109,6 +110,35 @@ describe('Test lane partition', () => {
}).toEqual({ neverRun: [], namedButAbsent: [] });
});
+ /**
+ * The PostgreSQL specs self-skip unless DATABASE_TYPE=postgres, so the unit lane reports one as
+ * skipped, which is green. The only lane that sets it is the `test-postgres` job, and that job
+ * names its specs inline. jest reads those positionals as OR'd regex filters, so a stale name
+ * matches nothing and still exits 0, and a new spec left off the list runs nowhere. Diff each
+ * workflow's list against the files on disk.
+ */
+ it.each(['ci.yml', 'release.yml'])('runs every *.pg.spec.ts in the %s test-postgres job', file => {
+ const isPgSpec = (path: string): boolean => path.endsWith('.pg.spec.ts');
+ const onDisk = (readdirSync(join(repoRoot, 'src'), { recursive: true }) as string[])
+ .filter(isPgSpec)
+ .map(path => `src/${path.split('\\').join('/')}`);
+ const workflow = yaml.load(readFileSync(join(repoRoot, '.github', 'workflows', file), 'utf8')) as {
+ jobs?: Record<string, { steps?: { run?: string }[] }>;
+ };
+ const named = (workflow.jobs?.['test-postgres']?.steps ?? [])
+ .flatMap(step => (step.run ?? '').split(/\s+/))
+ .filter(isPgSpec);
+
+ // Vacuity guard: a scan or a parse that found nothing would pass the diff below.
+ expect(onDisk.length).toBeGreaterThanOrEqual(5);
+ expect(named.length).toBeGreaterThanOrEqual(5);
+
+ 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);