-
Notifications
You must be signed in to change notification settings - Fork 316
Expand file tree
/
Copy pathcli.js
More file actions
166 lines (165 loc) · 5.4 KB
/
Copy pathcli.js
File metadata and controls
166 lines (165 loc) · 5.4 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
const { join, resolve: pathResolve } = require('path');
module.exports = [
{
args: ["run", "test/fixtures/ts-interop/interop.ts"],
expect: { code: 0 }
},
{
args: ["run", "test/fixtures/interop-test.mjs"],
expect: { code: 0 }
},
{
args: ["run", "test/integration/test.ts"],
expect: { code: 0 }
},
{
args: ["build", "test/fixtures/type-module/main.js", "-a", "-o", "tmp"],
expect: { code: 0 }
},
{
args: ["build", "test/integration/test.ts", "-o", "tmp"],
expect (code, stdout, stderr) {
return stdout.toString().indexOf(join('tmp', 'index.js')) !== -1;
}
},
{
args: ["run", "--v8-cache", "-a", "test/integration/test.ts"],
expect: { code: 0 }
},
{
args: ["run", "--v8-cache", "test/integration/stack-trace.js"],
expect: { code: 0 }
},
{
args: ["run", "test/fixtures/error.js"],
expect: { code: 1 }
},
{
args: ["run", "test/fixtures/does-not-exist.js"],
expect: { code: 1 }
},
{
args: ["run", "test/fixtures/error.js", "--no-source-map-register"],
expect (code, stdout, stderr) {
return code === 1 && stderr.toString().indexOf('fixtures/error.js') === -1;
}
},
{
args: ["run", "--watch", "-a", "test/integration/test.ts"],
expect: { code: 2 }
},
{
args: ["build", "-o", "tmp", "--watch", "test/fixtures/no-dep.js"],
timeout: 500,
expect: { timeout: true }
},
{
args: ["run", "test/fixtures/ts-error1/fail.ts"],
expect (code, stdout, stderr) {
return code === 1 && stderr.toString().indexOf('fail.ts:2:1') !== -1;
}
},
{
args: ["run", "test/fixtures/ts-error2/ts-error.ts"],
expect (code, stdout, stderr) {
return code === 1 && stderr.toString().indexOf('ts-error.ts(3,16)') !== -1 && stderr.toString().split('\n').length < 11;
}
},
{
args: ["run", "-t", "test/fixtures/with-type-errors/ts-error.ts"],
expect: { code: 0 }
},
{
args: ["build", "-o", "tmp", "test/fixtures/test.cjs"],
expect (code, stdout, stderr) {
return stdout.toString().indexOf(join('tmp', 'index.cjs')) !== -1;
}
},
{
args: ["build", "-o", "tmp", "test/fixtures/test.mjs"],
expect (code, stdout, stderr) {
return stdout.toString().indexOf(join('tmp', 'index.mjs')) !== -1;
}
},
{
args: ["build", "-o", "tmp", "test/fixtures/test.mjs", "--stats-out", "tmp/stats.json"],
expect (code, stdout, stderr) {
const fs = require('fs');
try {
JSON.parse(fs.readFileSync(join('tmp', 'stats.json'), 'utf8'));
} catch {
return false;
}
return true;
}
},
{
args: ["build", "--quiet", "test/integration/test.ts"],
expect (code, stdout) {
stdout = stdout.toString().replace(/[\r\n\s]/g, '').trim();
return stdout.length === 0;
}
},
{
args: ["build", "test/integration/test.ts"],
env: {
TYPESCRIPT_LOOKUP_PATH: '/tmp/nowhere'
},
expect (code, stdout) {
return code === 0 && stdout.indexOf('ncc built-in') !== -1;
},
},
{
args: ["build", "-o", "tmp", "test/fixtures/module.cjs"],
expect (code, stdout) {
const fs = require('fs');
return code === 0 && fs.readFileSync(join('tmp', 'index.js'), 'utf8').toString().indexOf('export {') === -1;
}
},
{
args: ["build", "-o", "tmp", "test/fixtures/sourcemap-resource-path/index.ts", "--source-map", "--no-source-map-register"],
expect (code, stdout, stderr) {
const fs = require('fs');
const map = JSON.parse(fs.readFileSync(join('tmp', 'index.js.map'), 'utf8'));
const paths = map.sources.map(source=>pathResolve(join('tmp', source)));
function hasPath(path) {
return paths.includes(pathResolve(path));
}
return code === 0 && hasPath('test/fixtures/sourcemap-resource-path/index.ts') && hasPath('test/fixtures/sourcemap-resource-path/sum.ts');
}
},
{
args: ["build", "-o", "tmp", "test/fixtures/sourcemap-resource-path/index.ts", "-m", "--source-map", "--no-source-map-register"],
expect (code, stdout, stderr) {
const fs = require('fs');
const map = JSON.parse(fs.readFileSync(join('tmp', 'index.js.map'), 'utf8'));
const paths = map.sources.map(source=>pathResolve(join('tmp', source)));
function hasPath(path) {
return paths.includes(pathResolve(path));
}
return code === 0 && hasPath('test/fixtures/sourcemap-resource-path/index.ts') && hasPath('test/fixtures/sourcemap-resource-path/sum.ts');
}
},
{
args: ["build", "-o", "tmp", "test/fixtures/sourcemap-base-prefix/index.js", "--source-map"],
expect(code) {
const fs = require('fs');
const map = JSON.parse(fs.readFileSync(join('tmp', 'index.js.map'), 'utf8'));
const actual = map.sources[1];
const expected = '../test/fixtures/sourcemap-base-prefix/index.js'
if (actual !== expected) console.log({ actual, expected })
return code === 0 && actual === expected;
}
},
{
args: ["build", "-o", "tmp/sourcemap-base-prefix", "test/fixtures/sourcemap-base-prefix/index.js", "--source-map"],
expect(code) {
const fs = require('fs');
const map = JSON.parse(fs.readFileSync(join('tmp', 'sourcemap-base-prefix', 'index.js.map'), 'utf8'));
const actual = map.sources[1];
const expected = '../../test/fixtures/sourcemap-base-prefix/index.js'
if (actual !== expected) console.log({ actual, expected })
return code === 0 && actual === expected;
}
}
]