-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
typescript.js
85 lines (78 loc) 路 2.52 KB
/
typescript.js
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
85
import fs from 'node:fs/promises';
import path from 'node:path';
import {test, withFixture} from './helpers/watch.js';
test('waits for external compiler before re-running typescript test files', withFixture('typescript-precompiled'), async (t, fixture) => {
await fixture.watch({
async 1({stats}) {
t.true(stats.passed.length > 0);
await this.assertIdle(async () => {
await this.touch('src/test.ts');
});
t.log('stayed idle, now touching build/test.js');
await this.touch('build/test.js');
return stats.passed;
},
async 2({stats}, previousPassed) {
t.deepEqual(stats.passed, previousPassed);
this.done();
},
});
});
test('does not run precompiled files when sources are deleted', withFixture('typescript-precompiled'), async (t, fixture) => {
await fixture.watch({
async 1() {
await this.assertIdle(async () => {
await this.rm('src/test.ts');
});
this.done();
},
});
});
test('handles deletion of precompiled and source files (multiple possible sources for precompiled file)', withFixture('typescript-precompiled'), async (t, fixture) => {
await fixture.watch({
async 1() {
await this.assertIdle(async () => {
await this.rm('src/test.ts');
await this.rm('build/test.js');
});
this.done();
},
});
});
test('handles deletion of precompiled and source files (single possible source for precompiled file)', withFixture('typescript-precompiled'), async (t, fixture) => {
await fixture.watch({
async 1() {
await this.assertIdle(async () => {
await this.rm('src/test.ts');
await this.rm('build/test.js');
});
this.done();
},
}, [], {env: {JUST_TS_EXTENSION: 'true'}});
});
test('handles inline compilation', withFixture('typescript-inline'), async (t, fixture) => {
await fs.symlink(new URL('../../node_modules', import.meta.url), path.join(fixture.dir, 'node_modules'), 'junction');
await fixture.watch({
async 1({stats}) {
t.true(stats.passed.length > 0);
await this.touch('src/test.ts');
return stats.passed;
},
async 2({stats}, previousPassed) {
t.deepEqual(stats.passed, previousPassed);
this.done();
},
});
});
test('ignores changes to compiled files with inline compilation', withFixture('typescript-inline'), async (t, fixture) => {
await fs.symlink(new URL('../../node_modules', import.meta.url), path.join(fixture.dir, 'node_modules'), 'junction');
await fixture.watch({
async 1({stats}) {
t.true(stats.passed.length > 0);
await this.assertIdle(async () => {
await this.touch('build/test.js');
});
this.done();
},
});
});