Repository navigation
Expand file tree
/
Copy pathjest.config.js
More file actions
84 lines (79 loc) · 3 KB
/
Copy pathjest.config.js
File metadata and controls
84 lines (79 loc) · 3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/**
* Two Jest projects, one runner.
*
* `cli` — every pre-existing suite, unchanged: ts-jest in CommonJS mode.
* `tui` — ink-testing-library render tests (`*.test.tsx`). ink 7 is ESM-only
* and pulls in yoga-layout, whose entry uses a top-level `await`;
* that cannot be downlevelled to CommonJS at all (require() is
* synchronous), so these suites must load the real published ESM
* through Jest's native ESM loader. No transformIgnorePatterns
* carve-out is needed precisely because nothing is being transformed.
*
* The `--experimental-vm-modules` flag that makes the `tui` project work is
* supplied by scripts/run-jest.mjs and is inert for the `cli` project.
*/
const tsJestEsm = {
extensionsToTreatAsEsm: ['.ts', '.tsx', '.mts'],
transform: {
'^.+\\.m?tsx?$': [
'ts-jest',
{ useESM: true, tsconfig: '<rootDir>/tsconfig.esm.json' },
],
},
};
/** TS sources import with ".js" specifiers throughout; resolve them to .ts/.tsx. */
const jsSpecifierMapper = { '^(\\.{1,2}/.*)\\.js$': '$1' };
/**
* npm hoists `ink-testing-library` to the workspace root but keeps `ink` nested
* under `cli/node_modules`, so the library's own `import {render} from 'ink'`
* cannot be resolved from where it sits. Pin `ink` to the copy this package
* actually depends on, independent of whatever layout npm picks this install.
*/
const inkMapper = {
'^ink$': require.resolve('ink', { paths: [__dirname] }),
};
const moduleFileExtensions = ['ts', 'tsx', 'js', 'jsx', 'json', 'node'];
// Agent detection reads the process tree and agent environment variables; a
// suite run inside Claude or Codex must not see a different actor than CI.
// Workers and every git/CLI child inherit this. Tests that exercise detection
// call its functions directly.
process.env.BRAINFILE_DETECT_AGENT = process.env.BRAINFILE_DETECT_AGENT || 'off';
// A hand-off's agent runs these suites in a shell that carries its role
// (BRAINFILE_AGENT_ROLE), which the commands keep to; the suites run as a
// person does, and the role tests set it themselves.
delete process.env.BRAINFILE_AGENT_ROLE;
delete process.env.BRAINFILE_LEAD_SCOPE;
module.exports = {
collectCoverageFrom: [
'src/**/*.ts',
'src/**/*.tsx',
'!src/**/*.d.ts',
'!src/cli.ts', // Entry point, tested via integration
],
coverageDirectory: 'coverage',
coverageReporters: ['text', 'lcov', 'html'],
projects: [
{
displayName: 'cli',
preset: 'ts-jest',
testEnvironment: 'node',
rootDir: __dirname,
roots: ['<rootDir>/src'],
testMatch: ['**/__tests__/**/*.test.ts'],
moduleNameMapper: jsSpecifierMapper,
moduleFileExtensions,
verbose: true,
},
{
displayName: 'tui',
testEnvironment: 'node',
rootDir: __dirname,
roots: ['<rootDir>/src/tui'],
testMatch: ['**/__tests__/**/*.test.tsx'],
moduleNameMapper: { ...jsSpecifierMapper, ...inkMapper },
moduleFileExtensions,
verbose: true,
...tsJestEsm,
},
],
};