Skip to content

Commit 95c69ff

Browse files
committed
test: add e2e test to validate generateTrace behavior with TS 4.1.x
Also update README.md to better reflect the current state of this feature.
1 parent d2fe738 commit 95c69ff

File tree

2 files changed

+41
-4
lines changed

2 files changed

+41
-4
lines changed

README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -347,12 +347,11 @@ yarn add --dev @types/webpack
347347

348348
## Profiling types resolution
349349

350-
Starting from TypeScript 4.1.0, you can profile long type checks by
350+
When using TypeScript 4.1.x in `build` mode you can profile long type checks by
351351
setting "generateTrace" compiler option. This is an instruction from [microsoft/TypeScript#40063](https://github.com/microsoft/TypeScript/pull/40063):
352352

353-
1. Set "generateTrace": "{folderName}" in your `tsconfig.json`
354-
2. Look in the resulting folder. If you used build mode, there will be a `legend.json` telling you what went where.
355-
Otherwise, there will be `trace.json` file and `types.json` files.
353+
1. Set "generateTrace": "{folderName}" in your `tsconfig.json` (under `compilerOptions`)
354+
2. Look in the resulting folder. There will be a `legend.json` telling you what went where.
356355
3. Navigate to [edge://tracing](edge://tracing) or [chrome://tracing](chrome://tracing) and load `trace.json`
357356
4. Expand Process 1 with the little triangle in the left sidebar
358357
5. Click on different blocks to see their payloads in the bottom pane

test/e2e/type-script-tracing.spec.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import path from 'path';
2+
3+
import { extractWebpackErrors } from './driver/webpack-errors-extractor';
4+
5+
describe('TypeScript Tracing', () => {
6+
it.each([{ build: true, typescript: '~4.1.0' }])(
7+
'can generate trace files for %p',
8+
async ({ build, ...dependencies }) => {
9+
await sandbox.load(path.join(__dirname, 'fixtures/typescript-basic'));
10+
await sandbox.install('yarn', { ...dependencies });
11+
12+
// enable tracing
13+
await sandbox.patch(
14+
'tsconfig.json',
15+
'"outDir": "./dist"',
16+
'"outDir": "./dist",\n"generateTrace": "./traces"'
17+
);
18+
19+
await sandbox.write(
20+
'fork-ts-checker.config.js',
21+
`module.exports = ${JSON.stringify({ typescript: { build } })};`
22+
);
23+
24+
const webpackResult = await sandbox.exec('yarn webpack --mode=development');
25+
const errors = extractWebpackErrors(webpackResult);
26+
expect(errors).toEqual([]);
27+
28+
expect(await sandbox.exists('dist')).toEqual(true);
29+
30+
expect(await sandbox.list('./traces')).toEqual(
31+
expect.arrayContaining([
32+
expect.objectContaining({ name: expect.stringMatching(/types.*\.json/) }),
33+
expect.objectContaining({ name: expect.stringMatching(/trace.*\.json/) }),
34+
])
35+
);
36+
}
37+
);
38+
});

0 commit comments

Comments
 (0)