ktx/scripts/precommit-check.test.mjs

43 lines
1.2 KiB
JavaScript
Raw Permalink Normal View History

2026-05-10 23:12:26 +02:00
import assert from 'node:assert/strict';
import { describe, it } from 'node:test';
import { planChecks } from './precommit-check.mjs';
function commandKeys(files) {
return planChecks(files).map((command) => command.key);
}
describe('precommit-check', () => {
2026-05-10 23:51:24 +02:00
it('skips files outside ktx', () => {
assert.deepEqual(commandKeys(['outside-workspace/src/app.ts']), []);
2026-05-10 23:12:26 +02:00
});
2026-05-12 13:02:06 +02:00
it('runs only the touched package checks for standalone package paths', () => {
assert.deepEqual(commandKeys(['packages/cli/src/index.ts']), [
'boundary-check',
'type-check:@ktx/cli',
'build:@ktx/cli',
'test:@ktx/cli',
]);
});
it('accepts legacy subtree-prefixed package paths', () => {
2026-05-10 23:51:24 +02:00
assert.deepEqual(commandKeys(['ktx/packages/cli/src/index.ts']), [
2026-05-10 23:12:26 +02:00
'boundary-check',
2026-05-10 23:51:24 +02:00
'type-check:@ktx/cli',
'build:@ktx/cli',
'test:@ktx/cli',
2026-05-10 23:12:26 +02:00
]);
});
it('runs the matching script test when a script changes', () => {
2026-05-12 13:02:06 +02:00
assert.deepEqual(commandKeys(['scripts/check-boundaries.mjs']), [
2026-05-10 23:12:26 +02:00
'script-test:scripts/check-boundaries.test.mjs',
]);
});
it('runs the touched python package tests', () => {
2026-05-12 13:02:06 +02:00
assert.deepEqual(commandKeys(['python/ktx-sl/semantic_layer/parser.py']), ['pytest:ktx-sl']);
2026-05-10 23:12:26 +02:00
});
});