@smoothbricks/nx-plugin 0.0.0-bootstrap.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +93 -2
- package/dist/bounded-test-policy.d.ts +32 -0
- package/dist/bounded-test-policy.d.ts.map +1 -0
- package/dist/bounded-test-policy.js +184 -0
- package/dist/executors/bounded-exec/executor.d.ts +15 -0
- package/dist/executors/bounded-exec/executor.d.ts.map +1 -0
- package/dist/executors/bounded-exec/executor.js +179 -0
- package/dist/executors/bounded-exec/schema.d.ts +11 -0
- package/dist/executors/bounded-exec/schema.d.ts.map +1 -0
- package/dist/executors/bounded-exec/schema.js +1 -0
- package/dist/generators/bounded-test-targets/generator.d.ts +7 -0
- package/dist/generators/bounded-test-targets/generator.d.ts.map +1 -0
- package/dist/generators/bounded-test-targets/generator.js +40 -0
- package/dist/generators/bun-test-tracing/generator.d.ts +10 -0
- package/dist/generators/bun-test-tracing/generator.d.ts.map +1 -0
- package/dist/generators/bun-test-tracing/generator.js +247 -0
- package/dist/generators/create-package/generator.d.ts +4 -0
- package/dist/generators/create-package/generator.d.ts.map +1 -0
- package/dist/generators/create-package/generator.js +204 -0
- package/dist/generators/make-public/generator.d.ts +4 -0
- package/dist/generators/make-public/generator.d.ts.map +1 -0
- package/dist/generators/make-public/generator.js +55 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +197 -0
- package/dist/package-target-policy.d.ts +31 -0
- package/dist/package-target-policy.d.ts.map +1 -0
- package/dist/package-target-policy.js +930 -0
- package/dist/release-config-policy.d.ts +32 -0
- package/dist/release-config-policy.d.ts.map +1 -0
- package/dist/release-config-policy.js +225 -0
- package/dist/typecheck-test-policy.d.ts +56 -0
- package/dist/typecheck-test-policy.d.ts.map +1 -0
- package/dist/typecheck-test-policy.js +640 -0
- package/dist/version-actions.cjs +78 -0
- package/dist/version-actions.d.cts +6 -0
- package/dist/version-actions.d.cts.map +1 -0
- package/dist/workspace-config-policy.d.ts +33 -0
- package/dist/workspace-config-policy.d.ts.map +1 -0
- package/dist/workspace-config-policy.js +334 -0
- package/executors.json +9 -0
- package/generators.json +24 -0
- package/loader.js +16 -0
- package/package.json +89 -4
- package/src/bounded-test-policy.test.ts +257 -0
- package/src/bounded-test-policy.ts +257 -0
- package/src/bun-bootstrap.test.ts +52 -0
- package/src/executors/bounded-exec/executor.test.ts +258 -0
- package/src/executors/bounded-exec/executor.ts +228 -0
- package/src/executors/bounded-exec/schema.json +68 -0
- package/src/executors/bounded-exec/schema.ts +10 -0
- package/src/generators/bounded-test-targets/generator.test.ts +136 -0
- package/src/generators/bounded-test-targets/generator.ts +67 -0
- package/src/generators/bounded-test-targets/schema.d.ts +3 -0
- package/src/generators/bounded-test-targets/schema.json +14 -0
- package/src/generators/bun-test-tracing/generator.test.ts +243 -0
- package/src/generators/bun-test-tracing/generator.ts +348 -0
- package/src/generators/bun-test-tracing/schema.d.ts +8 -0
- package/src/generators/bun-test-tracing/schema.json +28 -0
- package/src/generators/create-package/generator.test.ts +206 -0
- package/src/generators/create-package/generator.ts +251 -0
- package/src/generators/create-package/schema.d.ts +5 -0
- package/src/generators/create-package/schema.json +24 -0
- package/src/generators/make-public/generator.test.ts +137 -0
- package/src/generators/make-public/generator.ts +83 -0
- package/src/generators/make-public/schema.d.ts +3 -0
- package/src/generators/make-public/schema.json +13 -0
- package/src/index.test.ts +200 -0
- package/src/index.ts +242 -0
- package/src/package-target-policy.test.ts +778 -0
- package/src/package-target-policy.ts +1127 -0
- package/src/release-config-policy.test.ts +280 -0
- package/src/release-config-policy.ts +258 -0
- package/src/typecheck-test-policy.test.ts +797 -0
- package/src/typecheck-test-policy.ts +752 -0
- package/src/version-actions.cts +94 -0
- package/src/workspace-config-policy.test.ts +376 -0
- package/src/workspace-config-policy.ts +390 -0
|
@@ -0,0 +1,797 @@
|
|
|
1
|
+
import { describe, expect, it } from 'bun:test';
|
|
2
|
+
import { mkdir, mkdtemp, readFile, rm, writeFile } from 'node:fs/promises';
|
|
3
|
+
import { tmpdir } from 'node:os';
|
|
4
|
+
import { dirname, join } from 'node:path';
|
|
5
|
+
|
|
6
|
+
import { addProjectConfiguration, readJson, writeJson } from 'nx/src/devkit-exports.js';
|
|
7
|
+
import { createTreeWithEmptyWorkspace } from 'nx/src/devkit-testing-exports.js';
|
|
8
|
+
|
|
9
|
+
import {
|
|
10
|
+
applyTypecheckTestDefaults,
|
|
11
|
+
applyTypecheckTestPolicy,
|
|
12
|
+
applyTypecheckTestPolicyTree,
|
|
13
|
+
checkTsconfigTestReference,
|
|
14
|
+
checkTypecheckTestConfig,
|
|
15
|
+
checkTypecheckTestPolicy,
|
|
16
|
+
checkTypecheckTestPolicyTree,
|
|
17
|
+
detectPackageTestRunners,
|
|
18
|
+
removeTsconfigTestReference,
|
|
19
|
+
} from './typecheck-test-policy.js';
|
|
20
|
+
|
|
21
|
+
// ---------------------------------------------------------------------------
|
|
22
|
+
// Helpers for filesystem tests
|
|
23
|
+
// ---------------------------------------------------------------------------
|
|
24
|
+
|
|
25
|
+
async function writeJsonFs(path: string, value: unknown): Promise<void> {
|
|
26
|
+
await mkdir(dirname(path), { recursive: true });
|
|
27
|
+
await writeFile(path, `${JSON.stringify(value, null, 2)}\n`);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
async function readJsonFs(path: string): Promise<unknown> {
|
|
31
|
+
return JSON.parse(await readFile(path, 'utf8'));
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// ---------------------------------------------------------------------------
|
|
35
|
+
// Layer 1: Pure core function tests
|
|
36
|
+
// ---------------------------------------------------------------------------
|
|
37
|
+
|
|
38
|
+
describe('detectPackageTestRunners', () => {
|
|
39
|
+
it('detects bun from scripts', () => {
|
|
40
|
+
const runners = detectPackageTestRunners({ scripts: { test: 'bun test' } });
|
|
41
|
+
expect(runners.has('bun')).toBe(true);
|
|
42
|
+
expect(runners.size).toBe(1);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('detects vitest from scripts', () => {
|
|
46
|
+
const runners = detectPackageTestRunners({ scripts: { test: 'vitest run' } });
|
|
47
|
+
expect(runners.has('vitest')).toBe(true);
|
|
48
|
+
expect(runners.size).toBe(1);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('detects bun from nx targets in package.json', () => {
|
|
52
|
+
const runners = detectPackageTestRunners({
|
|
53
|
+
nx: { targets: { test: { options: { command: 'bun test --coverage' } } } },
|
|
54
|
+
});
|
|
55
|
+
expect(runners.has('bun')).toBe(true);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('detects bun from project targets', () => {
|
|
59
|
+
const runners = detectPackageTestRunners({}, { test: { options: { command: 'bun test' } } });
|
|
60
|
+
expect(runners.has('bun')).toBe(true);
|
|
61
|
+
expect(runners.size).toBe(1);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('detects vitest from project targets', () => {
|
|
65
|
+
const runners = detectPackageTestRunners({}, { test: { options: { command: 'vitest run' } } });
|
|
66
|
+
expect(runners.has('vitest')).toBe(true);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it('detects bun behind env prefix', () => {
|
|
70
|
+
const runners = detectPackageTestRunners({ scripts: { test: 'NODE_ENV=test bun test' } });
|
|
71
|
+
expect(runners.has('bun')).toBe(true);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it('returns empty set for non-test runners', () => {
|
|
75
|
+
const runners = detectPackageTestRunners({ scripts: { test: 'node --test' } });
|
|
76
|
+
expect(runners.size).toBe(0);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it('returns empty set for no scripts or targets', () => {
|
|
80
|
+
const runners = detectPackageTestRunners({});
|
|
81
|
+
expect(runners.size).toBe(0);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it('merges runners from scripts and project targets', () => {
|
|
85
|
+
const runners = detectPackageTestRunners(
|
|
86
|
+
{ scripts: { test: 'bun test' } },
|
|
87
|
+
{ 'test-vitest': { options: { command: 'vitest run' } } },
|
|
88
|
+
);
|
|
89
|
+
expect(runners.has('bun')).toBe(true);
|
|
90
|
+
expect(runners.has('vitest')).toBe(true);
|
|
91
|
+
expect(runners.size).toBe(2);
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
describe('checkTypecheckTestConfig', () => {
|
|
96
|
+
it('returns no issues for valid config', () => {
|
|
97
|
+
const issues = checkTypecheckTestConfig({ compilerOptions: { noEmit: true, composite: false } }, 'packages/app');
|
|
98
|
+
expect(issues).toEqual([]);
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it('reports missing noEmit', () => {
|
|
102
|
+
const issues = checkTypecheckTestConfig({ compilerOptions: { composite: false } }, 'packages/app');
|
|
103
|
+
expect(issues.length).toBe(1);
|
|
104
|
+
expect(issues[0]!.message).toContain('noEmit must be true');
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it('reports composite = true', () => {
|
|
108
|
+
const issues = checkTypecheckTestConfig({ compilerOptions: { noEmit: true, composite: true } }, 'packages/app');
|
|
109
|
+
expect(issues.length).toBe(1);
|
|
110
|
+
expect(issues[0]!.message).toContain('composite');
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it('reports declaration = true', () => {
|
|
114
|
+
const issues = checkTypecheckTestConfig({ compilerOptions: { noEmit: true, declaration: true } }, 'packages/app');
|
|
115
|
+
expect(issues.length).toBe(1);
|
|
116
|
+
expect(issues[0]!.message).toContain('declaration = true');
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it('reports declarationMap = true', () => {
|
|
120
|
+
const issues = checkTypecheckTestConfig(
|
|
121
|
+
{ compilerOptions: { noEmit: true, declarationMap: true } },
|
|
122
|
+
'packages/app',
|
|
123
|
+
);
|
|
124
|
+
expect(issues.length).toBe(1);
|
|
125
|
+
expect(issues[0]!.message).toContain('declarationMap');
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
it('reports dist-test outDir', () => {
|
|
129
|
+
const issues = checkTypecheckTestConfig({ compilerOptions: { noEmit: true, outDir: 'dist-test' } }, 'packages/app');
|
|
130
|
+
expect(issues.length).toBe(1);
|
|
131
|
+
expect(issues[0]!.message).toContain('dist-test');
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
it('reports dist-test tsBuildInfoFile', () => {
|
|
135
|
+
const issues = checkTypecheckTestConfig(
|
|
136
|
+
{ compilerOptions: { noEmit: true, tsBuildInfoFile: 'dist-test/tsconfig.test.tsbuildinfo' } },
|
|
137
|
+
'packages/app',
|
|
138
|
+
);
|
|
139
|
+
expect(issues.length).toBe(1);
|
|
140
|
+
expect(issues[0]!.message).toContain('dist-test');
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
it('returns empty for null input', () => {
|
|
144
|
+
const issues = checkTypecheckTestConfig(null, 'packages/app');
|
|
145
|
+
expect(issues).toEqual([]);
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
it('uses packagePath in issue path', () => {
|
|
149
|
+
const issues = checkTypecheckTestConfig({ compilerOptions: {} }, 'packages/mylib');
|
|
150
|
+
expect(issues[0]!.path).toContain('packages/mylib');
|
|
151
|
+
expect(issues[0]!.path).toContain('tsconfig.test.json');
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
describe('checkTsconfigTestReference', () => {
|
|
156
|
+
it('returns no issues when no test reference', () => {
|
|
157
|
+
const issues = checkTsconfigTestReference({ references: [{ path: './tsconfig.lib.json' }] }, 'packages/app');
|
|
158
|
+
expect(issues).toEqual([]);
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
it('reports test reference', () => {
|
|
162
|
+
const issues = checkTsconfigTestReference(
|
|
163
|
+
{ references: [{ path: './tsconfig.lib.json' }, { path: './tsconfig.test.json' }] },
|
|
164
|
+
'packages/app',
|
|
165
|
+
);
|
|
166
|
+
expect(issues.length).toBe(1);
|
|
167
|
+
expect(issues[0]!.message).toContain('must not reference ./tsconfig.test.json');
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
it('returns empty for null input', () => {
|
|
171
|
+
const issues = checkTsconfigTestReference(null, 'packages/app');
|
|
172
|
+
expect(issues).toEqual([]);
|
|
173
|
+
});
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
describe('applyTypecheckTestDefaults', () => {
|
|
177
|
+
it('applies all defaults to empty object', () => {
|
|
178
|
+
const tsconfigTest: Record<string, unknown> = {};
|
|
179
|
+
const changed = applyTypecheckTestDefaults(tsconfigTest, {
|
|
180
|
+
testRunners: new Set(['bun'] as const),
|
|
181
|
+
referencePaths: ['./tsconfig.lib.json'],
|
|
182
|
+
});
|
|
183
|
+
expect(changed).toBe(true);
|
|
184
|
+
expect(tsconfigTest.extends).toBe('../../tsconfig.base.json');
|
|
185
|
+
|
|
186
|
+
const compilerOptions = tsconfigTest.compilerOptions as Record<string, unknown>;
|
|
187
|
+
expect(compilerOptions.noEmit).toBe(true);
|
|
188
|
+
expect(compilerOptions.composite).toBe(false);
|
|
189
|
+
expect(compilerOptions.declaration).toBe(false);
|
|
190
|
+
expect(compilerOptions.declarationMap).toBe(false);
|
|
191
|
+
expect(compilerOptions.emitDeclarationOnly).toBe(false);
|
|
192
|
+
expect(compilerOptions.types).toContain('bun');
|
|
193
|
+
|
|
194
|
+
const include = tsconfigTest.include as string[];
|
|
195
|
+
expect(include).toContain('src/**/*.test.ts');
|
|
196
|
+
expect(include).toContain('src/**/*.spec.ts');
|
|
197
|
+
|
|
198
|
+
const references = tsconfigTest.references as Array<{ path: string }>;
|
|
199
|
+
expect(references).toContainEqual({ path: './tsconfig.lib.json' });
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
it('uses custom extends from lib tsconfig', () => {
|
|
203
|
+
const tsconfigTest: Record<string, unknown> = {};
|
|
204
|
+
applyTypecheckTestDefaults(tsconfigTest, {
|
|
205
|
+
testRunners: new Set(['bun'] as const),
|
|
206
|
+
tsconfigLibExtends: '../tsconfig.custom.json',
|
|
207
|
+
referencePaths: [],
|
|
208
|
+
});
|
|
209
|
+
expect(tsconfigTest.extends).toBe('../tsconfig.custom.json');
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
it('copies lib compiler options', () => {
|
|
213
|
+
const tsconfigTest: Record<string, unknown> = {};
|
|
214
|
+
applyTypecheckTestDefaults(tsconfigTest, {
|
|
215
|
+
testRunners: new Set(['bun'] as const),
|
|
216
|
+
libCompilerOptions: { baseUrl: '.', module: 'esnext', jsx: 'react-jsx' },
|
|
217
|
+
referencePaths: [],
|
|
218
|
+
});
|
|
219
|
+
const compilerOptions = tsconfigTest.compilerOptions as Record<string, unknown>;
|
|
220
|
+
expect(compilerOptions.baseUrl).toBe('.');
|
|
221
|
+
expect(compilerOptions.module).toBe('esnext');
|
|
222
|
+
expect(compilerOptions.jsx).toBe('react-jsx');
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
it('does not add bun types for vitest-only', () => {
|
|
226
|
+
const tsconfigTest: Record<string, unknown> = {};
|
|
227
|
+
applyTypecheckTestDefaults(tsconfigTest, {
|
|
228
|
+
testRunners: new Set(['vitest'] as const),
|
|
229
|
+
referencePaths: [],
|
|
230
|
+
});
|
|
231
|
+
const compilerOptions = tsconfigTest.compilerOptions as Record<string, unknown>;
|
|
232
|
+
expect(compilerOptions.types).toBeUndefined();
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
it('removes outDir and tsBuildInfoFile', () => {
|
|
236
|
+
const tsconfigTest: Record<string, unknown> = {
|
|
237
|
+
compilerOptions: { outDir: 'dist-test', tsBuildInfoFile: 'dist-test/tsconfig.tsbuildinfo' },
|
|
238
|
+
};
|
|
239
|
+
const changed = applyTypecheckTestDefaults(tsconfigTest, {
|
|
240
|
+
testRunners: new Set(['bun'] as const),
|
|
241
|
+
referencePaths: [],
|
|
242
|
+
});
|
|
243
|
+
expect(changed).toBe(true);
|
|
244
|
+
const compilerOptions = tsconfigTest.compilerOptions as Record<string, unknown>;
|
|
245
|
+
expect('outDir' in compilerOptions).toBe(false);
|
|
246
|
+
expect('tsBuildInfoFile' in compilerOptions).toBe(false);
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
it('is idempotent', () => {
|
|
250
|
+
const tsconfigTest: Record<string, unknown> = {};
|
|
251
|
+
const opts = {
|
|
252
|
+
testRunners: new Set(['bun'] as const),
|
|
253
|
+
referencePaths: ['./tsconfig.lib.json'],
|
|
254
|
+
};
|
|
255
|
+
applyTypecheckTestDefaults(tsconfigTest, opts);
|
|
256
|
+
const secondChanged = applyTypecheckTestDefaults(tsconfigTest, opts);
|
|
257
|
+
expect(secondChanged).toBe(false);
|
|
258
|
+
});
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
describe('removeTsconfigTestReference', () => {
|
|
262
|
+
it('removes test reference', () => {
|
|
263
|
+
const tsconfig: Record<string, unknown> = {
|
|
264
|
+
references: [{ path: './tsconfig.lib.json' }, { path: './tsconfig.test.json' }],
|
|
265
|
+
};
|
|
266
|
+
expect(removeTsconfigTestReference(tsconfig)).toBe(true);
|
|
267
|
+
expect(tsconfig.references).toEqual([{ path: './tsconfig.lib.json' }]);
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
it('returns false when no test reference', () => {
|
|
271
|
+
const tsconfig: Record<string, unknown> = {
|
|
272
|
+
references: [{ path: './tsconfig.lib.json' }],
|
|
273
|
+
};
|
|
274
|
+
expect(removeTsconfigTestReference(tsconfig)).toBe(false);
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
it('returns false when no references', () => {
|
|
278
|
+
const tsconfig: Record<string, unknown> = {};
|
|
279
|
+
expect(removeTsconfigTestReference(tsconfig)).toBe(false);
|
|
280
|
+
});
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
// ---------------------------------------------------------------------------
|
|
284
|
+
// Layer 2: Tree-based tests
|
|
285
|
+
// ---------------------------------------------------------------------------
|
|
286
|
+
|
|
287
|
+
describe('typecheck test policy (Tree)', () => {
|
|
288
|
+
it('creates tsconfig.test.json for bun test package', () => {
|
|
289
|
+
const tree = createTreeWithEmptyWorkspace();
|
|
290
|
+
addProjectConfiguration(tree, 'app', { root: 'packages/app', targets: {} });
|
|
291
|
+
// Remove auto-created project.json to test package.json-only detection
|
|
292
|
+
if (tree.exists('packages/app/project.json')) tree.delete('packages/app/project.json');
|
|
293
|
+
writeJson(tree, 'packages/app/package.json', {
|
|
294
|
+
name: '@scope/app',
|
|
295
|
+
scripts: { test: 'bun test' },
|
|
296
|
+
nx: { name: 'app' },
|
|
297
|
+
});
|
|
298
|
+
writeJson(tree, 'packages/app/tsconfig.lib.json', {
|
|
299
|
+
extends: '../../tsconfig.base.json',
|
|
300
|
+
compilerOptions: { baseUrl: '.', rootDir: 'src', outDir: 'dist' },
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
const changed = applyTypecheckTestPolicyTree(tree);
|
|
304
|
+
expect(changed).toBe(true);
|
|
305
|
+
|
|
306
|
+
const tsconfig = readJson<Record<string, unknown>>(tree, 'packages/app/tsconfig.test.json');
|
|
307
|
+
const compilerOptions = tsconfig.compilerOptions as Record<string, unknown>;
|
|
308
|
+
expect(compilerOptions.noEmit).toBe(true);
|
|
309
|
+
expect(compilerOptions.composite).toBe(false);
|
|
310
|
+
expect(compilerOptions.types).toContain('bun');
|
|
311
|
+
expect(compilerOptions.baseUrl).toBe('.');
|
|
312
|
+
expect(tsconfig.extends).toBe('../../tsconfig.base.json');
|
|
313
|
+
|
|
314
|
+
const include = tsconfig.include as string[];
|
|
315
|
+
expect(include).toContain('src/**/*.test.ts');
|
|
316
|
+
expect(include).toContain('src/**/*.spec.ts');
|
|
317
|
+
|
|
318
|
+
const references = tsconfig.references as Array<{ path: string }>;
|
|
319
|
+
expect(references).toContainEqual({ path: './tsconfig.lib.json' });
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
it('detects bun test in project.json targets', () => {
|
|
323
|
+
const tree = createTreeWithEmptyWorkspace();
|
|
324
|
+
addProjectConfiguration(tree, 'app', {
|
|
325
|
+
root: 'packages/app',
|
|
326
|
+
targets: { test: { executor: 'nx:run-commands', options: { command: 'bun test' } } },
|
|
327
|
+
});
|
|
328
|
+
writeJson(tree, 'packages/app/package.json', { name: '@scope/app' });
|
|
329
|
+
|
|
330
|
+
const issues = checkTypecheckTestPolicyTree(tree);
|
|
331
|
+
// Should detect bun test from project.json and require tsconfig.test.json
|
|
332
|
+
expect(issues.some((i) => i.message.includes('requires tsconfig.test.json'))).toBe(true);
|
|
333
|
+
expect(issues.some((i) => i.message.includes('bun test'))).toBe(true);
|
|
334
|
+
});
|
|
335
|
+
|
|
336
|
+
it('detects vitest in project.json targets', () => {
|
|
337
|
+
const tree = createTreeWithEmptyWorkspace();
|
|
338
|
+
addProjectConfiguration(tree, 'web', {
|
|
339
|
+
root: 'packages/web',
|
|
340
|
+
targets: { test: { executor: 'nx:run-commands', options: { command: 'vitest run' } } },
|
|
341
|
+
});
|
|
342
|
+
writeJson(tree, 'packages/web/package.json', { name: '@scope/web' });
|
|
343
|
+
|
|
344
|
+
const issues = checkTypecheckTestPolicyTree(tree);
|
|
345
|
+
expect(issues.some((i) => i.message.includes('vitest'))).toBe(true);
|
|
346
|
+
});
|
|
347
|
+
|
|
348
|
+
it('reports issues for bad tsconfig.test.json contents', () => {
|
|
349
|
+
const tree = createTreeWithEmptyWorkspace();
|
|
350
|
+
addProjectConfiguration(tree, 'bad', { root: 'packages/bad', targets: {} });
|
|
351
|
+
writeJson(tree, 'packages/bad/package.json', {
|
|
352
|
+
name: '@scope/bad',
|
|
353
|
+
scripts: { test: 'bun test' },
|
|
354
|
+
nx: { name: 'bad' },
|
|
355
|
+
});
|
|
356
|
+
writeJson(tree, 'packages/bad/tsconfig.test.json', {
|
|
357
|
+
compilerOptions: {
|
|
358
|
+
composite: true,
|
|
359
|
+
declaration: true,
|
|
360
|
+
outDir: 'dist-test',
|
|
361
|
+
},
|
|
362
|
+
});
|
|
363
|
+
|
|
364
|
+
const issues = checkTypecheckTestPolicyTree(tree);
|
|
365
|
+
const messages = issues.map((i) => i.message);
|
|
366
|
+
expect(messages).toContainEqual(expect.stringContaining('noEmit must be true'));
|
|
367
|
+
expect(messages).toContainEqual(expect.stringContaining('composite'));
|
|
368
|
+
expect(messages).toContainEqual(expect.stringContaining('declaration = true'));
|
|
369
|
+
expect(messages).toContainEqual(expect.stringContaining('dist-test'));
|
|
370
|
+
});
|
|
371
|
+
|
|
372
|
+
it('reports tsconfig.json test reference', () => {
|
|
373
|
+
const tree = createTreeWithEmptyWorkspace();
|
|
374
|
+
addProjectConfiguration(tree, 'app', { root: 'packages/app', targets: {} });
|
|
375
|
+
writeJson(tree, 'packages/app/package.json', {
|
|
376
|
+
name: '@scope/app',
|
|
377
|
+
scripts: { test: 'bun test' },
|
|
378
|
+
nx: { name: 'app' },
|
|
379
|
+
});
|
|
380
|
+
writeJson(tree, 'packages/app/tsconfig.test.json', {
|
|
381
|
+
compilerOptions: { noEmit: true },
|
|
382
|
+
});
|
|
383
|
+
writeJson(tree, 'packages/app/tsconfig.json', {
|
|
384
|
+
references: [{ path: './tsconfig.lib.json' }, { path: './tsconfig.test.json' }],
|
|
385
|
+
});
|
|
386
|
+
|
|
387
|
+
const issues = checkTypecheckTestPolicyTree(tree);
|
|
388
|
+
expect(issues.some((i) => i.message.includes('must not reference'))).toBe(true);
|
|
389
|
+
});
|
|
390
|
+
|
|
391
|
+
it('removes tsconfig.json test reference on apply', () => {
|
|
392
|
+
const tree = createTreeWithEmptyWorkspace();
|
|
393
|
+
addProjectConfiguration(tree, 'app', { root: 'packages/app', targets: {} });
|
|
394
|
+
writeJson(tree, 'packages/app/package.json', {
|
|
395
|
+
name: '@scope/app',
|
|
396
|
+
scripts: { test: 'bun test' },
|
|
397
|
+
nx: { name: 'app' },
|
|
398
|
+
});
|
|
399
|
+
writeJson(tree, 'packages/app/tsconfig.test.json', {
|
|
400
|
+
extends: '../../tsconfig.base.json',
|
|
401
|
+
compilerOptions: {
|
|
402
|
+
noEmit: true,
|
|
403
|
+
composite: false,
|
|
404
|
+
declaration: false,
|
|
405
|
+
declarationMap: false,
|
|
406
|
+
emitDeclarationOnly: false,
|
|
407
|
+
types: ['bun'],
|
|
408
|
+
},
|
|
409
|
+
include: [
|
|
410
|
+
'src/**/*.test.ts',
|
|
411
|
+
'src/**/*.spec.ts',
|
|
412
|
+
'src/**/__tests__/**/*.ts',
|
|
413
|
+
'src/**/__tests__/**/*.tsx',
|
|
414
|
+
'src/test-suite-tracer.ts',
|
|
415
|
+
],
|
|
416
|
+
});
|
|
417
|
+
writeJson(tree, 'packages/app/tsconfig.json', {
|
|
418
|
+
references: [{ path: './tsconfig.lib.json' }, { path: './tsconfig.test.json' }],
|
|
419
|
+
});
|
|
420
|
+
|
|
421
|
+
const changed = applyTypecheckTestPolicyTree(tree);
|
|
422
|
+
expect(changed).toBe(true);
|
|
423
|
+
|
|
424
|
+
const tsconfig = readJson<Record<string, unknown>>(tree, 'packages/app/tsconfig.json');
|
|
425
|
+
const references = tsconfig.references as Array<{ path: string }>;
|
|
426
|
+
expect(references).toEqual([{ path: './tsconfig.lib.json' }]);
|
|
427
|
+
});
|
|
428
|
+
|
|
429
|
+
it('skips root project', () => {
|
|
430
|
+
const tree = createTreeWithEmptyWorkspace();
|
|
431
|
+
// Root project with root "." should be skipped
|
|
432
|
+
addProjectConfiguration(tree, 'root', { root: '.', targets: {} });
|
|
433
|
+
writeJson(tree, 'package.json', {
|
|
434
|
+
name: '@scope/root',
|
|
435
|
+
scripts: { test: 'bun test' },
|
|
436
|
+
});
|
|
437
|
+
|
|
438
|
+
const issues = checkTypecheckTestPolicyTree(tree);
|
|
439
|
+
expect(issues).toEqual([]);
|
|
440
|
+
});
|
|
441
|
+
|
|
442
|
+
it('skips packages without test runners', () => {
|
|
443
|
+
const tree = createTreeWithEmptyWorkspace();
|
|
444
|
+
addProjectConfiguration(tree, 'utils', { root: 'packages/utils', targets: {} });
|
|
445
|
+
writeJson(tree, 'packages/utils/package.json', {
|
|
446
|
+
name: '@scope/utils',
|
|
447
|
+
scripts: { build: 'tsc' },
|
|
448
|
+
});
|
|
449
|
+
|
|
450
|
+
const issues = checkTypecheckTestPolicyTree(tree);
|
|
451
|
+
expect(issues).toEqual([]);
|
|
452
|
+
expect(applyTypecheckTestPolicyTree(tree)).toBe(false);
|
|
453
|
+
});
|
|
454
|
+
|
|
455
|
+
it('adds workspace dependency references', () => {
|
|
456
|
+
const tree = createTreeWithEmptyWorkspace();
|
|
457
|
+
|
|
458
|
+
// Library dependency
|
|
459
|
+
addProjectConfiguration(tree, 'lib', { root: 'packages/lib', targets: {} });
|
|
460
|
+
writeJson(tree, 'packages/lib/package.json', { name: '@scope/lib' });
|
|
461
|
+
writeJson(tree, 'packages/lib/tsconfig.lib.json', {
|
|
462
|
+
extends: '../../tsconfig.base.json',
|
|
463
|
+
compilerOptions: {},
|
|
464
|
+
});
|
|
465
|
+
|
|
466
|
+
// App that depends on lib
|
|
467
|
+
addProjectConfiguration(tree, 'app', { root: 'packages/app', targets: {} });
|
|
468
|
+
writeJson(tree, 'packages/app/package.json', {
|
|
469
|
+
name: '@scope/app',
|
|
470
|
+
scripts: { test: 'bun test' },
|
|
471
|
+
dependencies: { '@scope/lib': 'workspace:*' },
|
|
472
|
+
nx: { name: 'app' },
|
|
473
|
+
});
|
|
474
|
+
writeJson(tree, 'packages/app/tsconfig.lib.json', {
|
|
475
|
+
extends: '../../tsconfig.base.json',
|
|
476
|
+
compilerOptions: {},
|
|
477
|
+
});
|
|
478
|
+
|
|
479
|
+
expect(applyTypecheckTestPolicyTree(tree)).toBe(true);
|
|
480
|
+
|
|
481
|
+
const tsconfig = readJson<Record<string, unknown>>(tree, 'packages/app/tsconfig.test.json');
|
|
482
|
+
const references = tsconfig.references as Array<{ path: string }>;
|
|
483
|
+
expect(references).toContainEqual({ path: './tsconfig.lib.json' });
|
|
484
|
+
expect(references).toContainEqual({ path: '../lib/tsconfig.lib.json' });
|
|
485
|
+
});
|
|
486
|
+
});
|
|
487
|
+
|
|
488
|
+
// ---------------------------------------------------------------------------
|
|
489
|
+
// Layer 3: Filesystem-based tests (existing)
|
|
490
|
+
// ---------------------------------------------------------------------------
|
|
491
|
+
|
|
492
|
+
describe('typecheck test policy', () => {
|
|
493
|
+
it('creates tsconfig.test.json for bun test package', async () => {
|
|
494
|
+
const root = await mkdtemp(join(tmpdir(), 'smoo-typecheck-test-policy-'));
|
|
495
|
+
try {
|
|
496
|
+
await writeJsonFs(join(root, 'package.json'), { workspaces: ['packages/*'] });
|
|
497
|
+
await writeJsonFs(join(root, 'packages/app/package.json'), {
|
|
498
|
+
name: '@scope/app',
|
|
499
|
+
scripts: { test: 'bun test' },
|
|
500
|
+
});
|
|
501
|
+
|
|
502
|
+
// check should report missing tsconfig.test.json
|
|
503
|
+
const issues = checkTypecheckTestPolicy(root);
|
|
504
|
+
expect(issues.length).toBe(1);
|
|
505
|
+
expect(issues[0]!.message).toContain('bun test');
|
|
506
|
+
expect(issues[0]!.message).toContain('tsconfig.test.json');
|
|
507
|
+
|
|
508
|
+
// apply should create it
|
|
509
|
+
expect(applyTypecheckTestPolicy(root)).toBe(true);
|
|
510
|
+
|
|
511
|
+
const tsconfig = (await readJsonFs(join(root, 'packages/app/tsconfig.test.json'))) as Record<string, unknown>;
|
|
512
|
+
const compilerOptions = tsconfig.compilerOptions as Record<string, unknown>;
|
|
513
|
+
expect(compilerOptions.noEmit).toBe(true);
|
|
514
|
+
expect(compilerOptions.composite).toBe(false);
|
|
515
|
+
expect(compilerOptions.declaration).toBe(false);
|
|
516
|
+
expect(compilerOptions.declarationMap).toBe(false);
|
|
517
|
+
expect(compilerOptions.emitDeclarationOnly).toBe(false);
|
|
518
|
+
expect(compilerOptions.types).toContain('bun');
|
|
519
|
+
expect(tsconfig.extends).toBe('../../tsconfig.base.json');
|
|
520
|
+
|
|
521
|
+
const include = tsconfig.include as string[];
|
|
522
|
+
expect(include).toContain('src/**/*.test.ts');
|
|
523
|
+
expect(include).toContain('src/**/*.spec.ts');
|
|
524
|
+
expect(include).toContain('src/**/__tests__/**/*.ts');
|
|
525
|
+
expect(include).toContain('src/test-suite-tracer.ts');
|
|
526
|
+
|
|
527
|
+
// second apply should be idempotent
|
|
528
|
+
expect(applyTypecheckTestPolicy(root)).toBe(false);
|
|
529
|
+
|
|
530
|
+
// check should now pass
|
|
531
|
+
expect(checkTypecheckTestPolicy(root)).toEqual([]);
|
|
532
|
+
} finally {
|
|
533
|
+
await rm(root, { recursive: true, force: true });
|
|
534
|
+
}
|
|
535
|
+
});
|
|
536
|
+
|
|
537
|
+
it('creates tsconfig.test.json for vitest package', async () => {
|
|
538
|
+
const root = await mkdtemp(join(tmpdir(), 'smoo-typecheck-test-policy-'));
|
|
539
|
+
try {
|
|
540
|
+
await writeJsonFs(join(root, 'package.json'), { workspaces: ['packages/*'] });
|
|
541
|
+
await writeJsonFs(join(root, 'packages/web/package.json'), {
|
|
542
|
+
name: '@scope/web',
|
|
543
|
+
scripts: { test: 'vitest run' },
|
|
544
|
+
});
|
|
545
|
+
|
|
546
|
+
expect(applyTypecheckTestPolicy(root)).toBe(true);
|
|
547
|
+
|
|
548
|
+
const tsconfig = (await readJsonFs(join(root, 'packages/web/tsconfig.test.json'))) as Record<string, unknown>;
|
|
549
|
+
const compilerOptions = tsconfig.compilerOptions as Record<string, unknown>;
|
|
550
|
+
expect(compilerOptions.noEmit).toBe(true);
|
|
551
|
+
// vitest should NOT add bun types
|
|
552
|
+
expect(compilerOptions.types).toBeUndefined();
|
|
553
|
+
|
|
554
|
+
expect(checkTypecheckTestPolicy(root)).toEqual([]);
|
|
555
|
+
} finally {
|
|
556
|
+
await rm(root, { recursive: true, force: true });
|
|
557
|
+
}
|
|
558
|
+
});
|
|
559
|
+
|
|
560
|
+
it('detects bun test in Nx targets', async () => {
|
|
561
|
+
const root = await mkdtemp(join(tmpdir(), 'smoo-typecheck-test-policy-'));
|
|
562
|
+
try {
|
|
563
|
+
await writeJsonFs(join(root, 'package.json'), { workspaces: ['packages/*'] });
|
|
564
|
+
await writeJsonFs(join(root, 'packages/lib/package.json'), {
|
|
565
|
+
name: '@scope/lib',
|
|
566
|
+
nx: {
|
|
567
|
+
targets: {
|
|
568
|
+
test: {
|
|
569
|
+
options: { command: 'bun test --coverage' },
|
|
570
|
+
},
|
|
571
|
+
},
|
|
572
|
+
},
|
|
573
|
+
});
|
|
574
|
+
|
|
575
|
+
const issues = checkTypecheckTestPolicy(root);
|
|
576
|
+
expect(issues.length).toBe(1);
|
|
577
|
+
expect(issues[0]!.message).toContain('bun test');
|
|
578
|
+
|
|
579
|
+
expect(applyTypecheckTestPolicy(root)).toBe(true);
|
|
580
|
+
|
|
581
|
+
const tsconfig = (await readJsonFs(join(root, 'packages/lib/tsconfig.test.json'))) as Record<string, unknown>;
|
|
582
|
+
const compilerOptions = tsconfig.compilerOptions as Record<string, unknown>;
|
|
583
|
+
expect(compilerOptions.noEmit).toBe(true);
|
|
584
|
+
expect(compilerOptions.types).toContain('bun');
|
|
585
|
+
} finally {
|
|
586
|
+
await rm(root, { recursive: true, force: true });
|
|
587
|
+
}
|
|
588
|
+
});
|
|
589
|
+
|
|
590
|
+
it('rejects composite/declaration/dist-test in tsconfig.test.json', async () => {
|
|
591
|
+
const root = await mkdtemp(join(tmpdir(), 'smoo-typecheck-test-policy-'));
|
|
592
|
+
try {
|
|
593
|
+
await writeJsonFs(join(root, 'package.json'), { workspaces: ['packages/*'] });
|
|
594
|
+
await writeJsonFs(join(root, 'packages/bad/package.json'), {
|
|
595
|
+
name: '@scope/bad',
|
|
596
|
+
scripts: { test: 'bun test' },
|
|
597
|
+
});
|
|
598
|
+
await writeJsonFs(join(root, 'packages/bad/tsconfig.test.json'), {
|
|
599
|
+
compilerOptions: {
|
|
600
|
+
composite: true,
|
|
601
|
+
declaration: true,
|
|
602
|
+
declarationMap: true,
|
|
603
|
+
outDir: 'dist-test',
|
|
604
|
+
tsBuildInfoFile: 'dist-test/tsconfig.test.tsbuildinfo',
|
|
605
|
+
},
|
|
606
|
+
});
|
|
607
|
+
|
|
608
|
+
const issues = checkTypecheckTestPolicy(root);
|
|
609
|
+
// Should report: noEmit missing, composite, declaration, declarationMap, outDir dist-test, tsBuildInfoFile dist-test
|
|
610
|
+
expect(issues.length).toBe(6);
|
|
611
|
+
const messages = issues.map((issue) => issue.message);
|
|
612
|
+
expect(messages).toContainEqual(expect.stringContaining('noEmit must be true'));
|
|
613
|
+
expect(messages).toContainEqual(expect.stringContaining('composite'));
|
|
614
|
+
expect(messages).toContainEqual(expect.stringContaining('declaration = true'));
|
|
615
|
+
expect(messages).toContainEqual(expect.stringContaining('declarationMap'));
|
|
616
|
+
expect(messages).toContainEqual(expect.stringContaining('dist-test'));
|
|
617
|
+
} finally {
|
|
618
|
+
await rm(root, { recursive: true, force: true });
|
|
619
|
+
}
|
|
620
|
+
});
|
|
621
|
+
|
|
622
|
+
it('removes tsconfig.json reference to ./tsconfig.test.json', async () => {
|
|
623
|
+
const root = await mkdtemp(join(tmpdir(), 'smoo-typecheck-test-policy-'));
|
|
624
|
+
try {
|
|
625
|
+
await writeJsonFs(join(root, 'package.json'), { workspaces: ['packages/*'] });
|
|
626
|
+
await writeJsonFs(join(root, 'packages/app/package.json'), {
|
|
627
|
+
name: '@scope/app',
|
|
628
|
+
scripts: { test: 'bun test' },
|
|
629
|
+
});
|
|
630
|
+
await writeJsonFs(join(root, 'packages/app/tsconfig.test.json'), {
|
|
631
|
+
extends: '../../tsconfig.base.json',
|
|
632
|
+
compilerOptions: {
|
|
633
|
+
noEmit: true,
|
|
634
|
+
composite: false,
|
|
635
|
+
declaration: false,
|
|
636
|
+
declarationMap: false,
|
|
637
|
+
emitDeclarationOnly: false,
|
|
638
|
+
},
|
|
639
|
+
include: ['src/**/*.test.ts'],
|
|
640
|
+
});
|
|
641
|
+
await writeJsonFs(join(root, 'packages/app/tsconfig.json'), {
|
|
642
|
+
references: [{ path: './tsconfig.lib.json' }, { path: './tsconfig.test.json' }],
|
|
643
|
+
});
|
|
644
|
+
|
|
645
|
+
// check should report the bad reference
|
|
646
|
+
const issues = checkTypecheckTestPolicy(root);
|
|
647
|
+
const referenceIssues = issues.filter((i) => i.message.includes('must not reference'));
|
|
648
|
+
expect(referenceIssues.length).toBe(1);
|
|
649
|
+
|
|
650
|
+
// apply should remove it
|
|
651
|
+
expect(applyTypecheckTestPolicy(root)).toBe(true);
|
|
652
|
+
|
|
653
|
+
const tsconfig = (await readJsonFs(join(root, 'packages/app/tsconfig.json'))) as Record<string, unknown>;
|
|
654
|
+
const references = tsconfig.references as Array<{ path: string }>;
|
|
655
|
+
expect(references).toEqual([{ path: './tsconfig.lib.json' }]);
|
|
656
|
+
} finally {
|
|
657
|
+
await rm(root, { recursive: true, force: true });
|
|
658
|
+
}
|
|
659
|
+
});
|
|
660
|
+
|
|
661
|
+
it('copies lib compiler options', async () => {
|
|
662
|
+
const root = await mkdtemp(join(tmpdir(), 'smoo-typecheck-test-policy-'));
|
|
663
|
+
try {
|
|
664
|
+
await writeJsonFs(join(root, 'package.json'), { workspaces: ['packages/*'] });
|
|
665
|
+
await writeJsonFs(join(root, 'packages/app/package.json'), {
|
|
666
|
+
name: '@scope/app',
|
|
667
|
+
scripts: { test: 'bun test' },
|
|
668
|
+
});
|
|
669
|
+
await writeJsonFs(join(root, 'packages/app/tsconfig.lib.json'), {
|
|
670
|
+
extends: '../../tsconfig.base.json',
|
|
671
|
+
compilerOptions: {
|
|
672
|
+
baseUrl: '.',
|
|
673
|
+
module: 'esnext',
|
|
674
|
+
moduleResolution: 'bundler',
|
|
675
|
+
jsx: 'react-jsx',
|
|
676
|
+
lib: ['ES2023', 'DOM'],
|
|
677
|
+
},
|
|
678
|
+
});
|
|
679
|
+
|
|
680
|
+
expect(applyTypecheckTestPolicy(root)).toBe(true);
|
|
681
|
+
|
|
682
|
+
const tsconfig = (await readJsonFs(join(root, 'packages/app/tsconfig.test.json'))) as Record<string, unknown>;
|
|
683
|
+
const compilerOptions = tsconfig.compilerOptions as Record<string, unknown>;
|
|
684
|
+
expect(compilerOptions.baseUrl).toBe('.');
|
|
685
|
+
expect(compilerOptions.module).toBe('esnext');
|
|
686
|
+
expect(compilerOptions.moduleResolution).toBe('bundler');
|
|
687
|
+
expect(compilerOptions.jsx).toBe('react-jsx');
|
|
688
|
+
expect(compilerOptions.lib).toEqual(['ES2023', 'DOM']);
|
|
689
|
+
// extends should come from tsconfig.lib.json
|
|
690
|
+
expect(tsconfig.extends).toBe('../../tsconfig.base.json');
|
|
691
|
+
|
|
692
|
+
// references should include ./tsconfig.lib.json
|
|
693
|
+
const references = tsconfig.references as Array<{ path: string }>;
|
|
694
|
+
expect(references).toContainEqual({ path: './tsconfig.lib.json' });
|
|
695
|
+
} finally {
|
|
696
|
+
await rm(root, { recursive: true, force: true });
|
|
697
|
+
}
|
|
698
|
+
});
|
|
699
|
+
|
|
700
|
+
it('adds workspace dependency references', async () => {
|
|
701
|
+
const root = await mkdtemp(join(tmpdir(), 'smoo-typecheck-test-policy-'));
|
|
702
|
+
try {
|
|
703
|
+
await writeJsonFs(join(root, 'package.json'), { workspaces: ['packages/*'] });
|
|
704
|
+
await writeJsonFs(join(root, 'packages/lib/package.json'), {
|
|
705
|
+
name: '@scope/lib',
|
|
706
|
+
});
|
|
707
|
+
await writeJsonFs(join(root, 'packages/lib/tsconfig.lib.json'), {
|
|
708
|
+
extends: '../../tsconfig.base.json',
|
|
709
|
+
compilerOptions: {},
|
|
710
|
+
});
|
|
711
|
+
await writeJsonFs(join(root, 'packages/app/package.json'), {
|
|
712
|
+
name: '@scope/app',
|
|
713
|
+
scripts: { test: 'bun test' },
|
|
714
|
+
dependencies: { '@scope/lib': 'workspace:*' },
|
|
715
|
+
});
|
|
716
|
+
await writeJsonFs(join(root, 'packages/app/tsconfig.lib.json'), {
|
|
717
|
+
extends: '../../tsconfig.base.json',
|
|
718
|
+
compilerOptions: {},
|
|
719
|
+
});
|
|
720
|
+
|
|
721
|
+
expect(applyTypecheckTestPolicy(root)).toBe(true);
|
|
722
|
+
|
|
723
|
+
const tsconfig = (await readJsonFs(join(root, 'packages/app/tsconfig.test.json'))) as Record<string, unknown>;
|
|
724
|
+
const references = tsconfig.references as Array<{ path: string }>;
|
|
725
|
+
expect(references).toContainEqual({ path: './tsconfig.lib.json' });
|
|
726
|
+
expect(references).toContainEqual({ path: '../lib/tsconfig.lib.json' });
|
|
727
|
+
} finally {
|
|
728
|
+
await rm(root, { recursive: true, force: true });
|
|
729
|
+
}
|
|
730
|
+
});
|
|
731
|
+
|
|
732
|
+
it('does not require tsconfig.test.json for non-bun/vitest runners', async () => {
|
|
733
|
+
const root = await mkdtemp(join(tmpdir(), 'smoo-typecheck-test-policy-'));
|
|
734
|
+
try {
|
|
735
|
+
await writeJsonFs(join(root, 'package.json'), { workspaces: ['packages/*'] });
|
|
736
|
+
await writeJsonFs(join(root, 'packages/app/package.json'), {
|
|
737
|
+
name: '@scope/app',
|
|
738
|
+
scripts: { test: 'node --test' },
|
|
739
|
+
});
|
|
740
|
+
|
|
741
|
+
expect(checkTypecheckTestPolicy(root)).toEqual([]);
|
|
742
|
+
expect(applyTypecheckTestPolicy(root)).toBe(false);
|
|
743
|
+
} finally {
|
|
744
|
+
await rm(root, { recursive: true, force: true });
|
|
745
|
+
}
|
|
746
|
+
});
|
|
747
|
+
|
|
748
|
+
it('accepts valid noEmit test tsconfig', async () => {
|
|
749
|
+
const root = await mkdtemp(join(tmpdir(), 'smoo-typecheck-test-policy-'));
|
|
750
|
+
try {
|
|
751
|
+
await writeJsonFs(join(root, 'package.json'), { workspaces: ['packages/*'] });
|
|
752
|
+
await writeJsonFs(join(root, 'packages/app/package.json'), {
|
|
753
|
+
name: '@scope/app',
|
|
754
|
+
scripts: { test: 'bun test' },
|
|
755
|
+
});
|
|
756
|
+
await writeJsonFs(join(root, 'packages/app/tsconfig.test.json'), {
|
|
757
|
+
extends: '../../tsconfig.base.json',
|
|
758
|
+
compilerOptions: {
|
|
759
|
+
composite: false,
|
|
760
|
+
declaration: false,
|
|
761
|
+
declarationMap: false,
|
|
762
|
+
emitDeclarationOnly: false,
|
|
763
|
+
noEmit: true,
|
|
764
|
+
types: ['bun'],
|
|
765
|
+
},
|
|
766
|
+
include: [
|
|
767
|
+
'src/**/*.test.ts',
|
|
768
|
+
'src/**/*.spec.ts',
|
|
769
|
+
'src/**/__tests__/**/*.ts',
|
|
770
|
+
'src/**/__tests__/**/*.tsx',
|
|
771
|
+
'src/test-suite-tracer.ts',
|
|
772
|
+
],
|
|
773
|
+
});
|
|
774
|
+
|
|
775
|
+
expect(checkTypecheckTestPolicy(root)).toEqual([]);
|
|
776
|
+
} finally {
|
|
777
|
+
await rm(root, { recursive: true, force: true });
|
|
778
|
+
}
|
|
779
|
+
});
|
|
780
|
+
|
|
781
|
+
it('detects bun test behind env prefix', async () => {
|
|
782
|
+
const root = await mkdtemp(join(tmpdir(), 'smoo-typecheck-test-policy-'));
|
|
783
|
+
try {
|
|
784
|
+
await writeJsonFs(join(root, 'package.json'), { workspaces: ['packages/*'] });
|
|
785
|
+
await writeJsonFs(join(root, 'packages/app/package.json'), {
|
|
786
|
+
name: '@scope/app',
|
|
787
|
+
scripts: { test: 'NODE_ENV=test bun test' },
|
|
788
|
+
});
|
|
789
|
+
|
|
790
|
+
const issues = checkTypecheckTestPolicy(root);
|
|
791
|
+
expect(issues.length).toBe(1);
|
|
792
|
+
expect(issues[0]!.message).toContain('bun test');
|
|
793
|
+
} finally {
|
|
794
|
+
await rm(root, { recursive: true, force: true });
|
|
795
|
+
}
|
|
796
|
+
});
|
|
797
|
+
});
|