-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathcompilation.js
61 lines (52 loc) · 1.81 KB
/
compilation.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
import path from 'node:path';
import {fileURLToPath} from 'node:url';
import test from 'ava';
import del from 'del';
import execa from 'execa';
import createProviderMacro from './_with-provider.js';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const withProvider = createProviderMacro('ava-3.2', '3.2.0', path.join(__dirname, 'fixtures'));
const withAltProvider = createProviderMacro('ava-3.2', '3.2.0', path.join(__dirname, 'broken-fixtures'));
test.before('deleting compiled files', async t => {
t.log(await del('test/fixtures/typescript/compiled'));
t.log(await del('test/broken-fixtures/typescript/compiled'));
});
const compile = async provider => ({
state: await provider.main({
config: {
rewritePaths: {
'ts/': 'typescript/',
'compiled/': 'typescript/compiled/',
},
compile: 'tsc',
},
}).compile(),
});
test('worker(): load rewritten paths files', withProvider, async (t, provider) => {
const {state} = await compile(provider);
const {stdout, stderr} = await execa.node(
path.join(__dirname, 'fixtures/install-and-load'),
[JSON.stringify({state}), path.join(__dirname, 'fixtures/ts', 'file.ts')],
{cwd: path.join(__dirname, 'fixtures')},
);
if (stderr.length > 0) {
t.log(stderr);
}
t.snapshot(stdout);
});
test('worker(): runs compiled files', withProvider, async (t, provider) => {
const {state} = await compile(provider);
const {stdout, stderr} = await execa.node(
path.join(__dirname, 'fixtures/install-and-load'),
[JSON.stringify({state}), path.join(__dirname, 'fixtures/compiled', 'index.ts')],
{cwd: path.join(__dirname, 'fixtures')},
);
if (stderr.length > 0) {
t.log(stderr);
}
t.snapshot(stdout);
});
test('compile() error', withAltProvider, async (t, provider) => {
const {message} = await t.throwsAsync(compile(provider));
t.snapshot(message);
});