-
Notifications
You must be signed in to change notification settings - Fork 778
/
Copy pathbundlers.mjs
165 lines (151 loc) · 5.74 KB
/
bundlers.mjs
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
import cp from 'node:child_process';
import fs from 'node:fs';
import path from 'node:path';
import url from 'node:url';
const dirname = path.dirname(url.fileURLToPath(import.meta.url));
const DIR = path.join(dirname, 'bundlers');
// Prepare
cp.execSync('npm install --no-audit --update-notifier=false', { cwd: DIR, encoding: 'utf8' });
await import('./bundlers/build.mjs');
const tmpJsFiles = fs.readdirSync(path.join(DIR, 'tmp'))
.filter(name => name.endsWith('.js') || name.endsWith('.mjs'));
const directFiles = tmpJsFiles.filter(name => !name.includes('-indirect'));
const indirectFiles = tmpJsFiles.filter(name => name.includes('-indirect'));
function normalize (str) {
return str
.replace(/^localhost:\d+/g, 'localhost:8000')
.replace(/\b\d+ms\b/g, '42ms');
}
QUnit.module('bundlers');
QUnit.test.each('test in Node.js [direct]', directFiles, function (assert, fileName) {
const actual = cp.execFileSync(process.execPath,
[
'--input-type=module',
'-e',
`import ${JSON.stringify('./tmp/' + fileName)}; QUnit.start();`
],
{ cwd: DIR, env: { qunit_config_reporters_tap: 'true' }, encoding: 'utf8' }
);
const expected = `
1..1
# pass 1
# skip 0
# todo 0
# fail 0`.trim();
assert.pushResult({ result: actual.includes(expected), actual, expected }, 'stdout');
});
QUnit.test.each('test in Node.js [indirect]', indirectFiles, function (assert, fileName) {
const actual = cp.execFileSync(process.execPath,
[
'--input-type=module',
'-e',
`import ${JSON.stringify('./tmp/' + fileName)}; QUnit.start();`
],
{ cwd: DIR, env: { qunit_config_reporters_tap: 'true' }, encoding: 'utf8' }
);
const expected = `
1..5
# pass 5
# skip 0
# todo 0
# fail 0`.trim();
assert.pushResult({ result: actual.includes(expected), actual, expected }, 'stdout');
});
QUnit.test('test in browser', function (assert) {
assert.timeout(60_000);
const expected = `Running "connect:all" (connect) task
Started connect web server on http://localhost:8000
Running "qunit:all" (qunit) task
Testing http://localhost:8000/tmp/test-import-default.es.html .OK
>> passed test "import-default"
Testing http://localhost:8000/tmp/test-import-default.iife.html .OK
>> passed test "import-default"
Testing http://localhost:8000/tmp/test-import-default.umd.html .OK
>> passed test "import-default"
Testing http://localhost:8000/tmp/test-import-default.webpack.html .OK
>> passed test "import-default"
Testing http://localhost:8000/tmp/test-import-indirect.es.html .....OK
>> passed test "import-default"
>> passed test "import-named"
>> passed test "require-default"
>> passed test "require-sub"
>> passed test "import-indirect"
Testing http://localhost:8000/tmp/test-import-indirect.iife.html .....OK
>> passed test "import-default"
>> passed test "import-named"
>> passed test "require-default"
>> passed test "require-sub"
>> passed test "import-indirect"
Testing http://localhost:8000/tmp/test-import-indirect.umd.html .....OK
>> passed test "import-default"
>> passed test "import-named"
>> passed test "require-default"
>> passed test "require-sub"
>> passed test "import-indirect"
Testing http://localhost:8000/tmp/test-import-indirect.webpack.html .....OK
>> passed test "import-default"
>> passed test "import-named"
>> passed test "require-default"
>> passed test "require-sub"
>> passed test "import-indirect"
Testing http://localhost:8000/tmp/test-import-named.es.html .OK
>> passed test "import-named"
Testing http://localhost:8000/tmp/test-import-named.iife.html .OK
>> passed test "import-named"
Testing http://localhost:8000/tmp/test-import-named.umd.html .OK
>> passed test "import-named"
Testing http://localhost:8000/tmp/test-import-named.webpack.html .OK
>> passed test "import-named"
Testing http://localhost:8000/tmp/test-require-default.es.html .OK
>> passed test "require-default"
Testing http://localhost:8000/tmp/test-require-default.iife.html .OK
>> passed test "require-default"
Testing http://localhost:8000/tmp/test-require-default.umd.html .OK
>> passed test "require-default"
Testing http://localhost:8000/tmp/test-require-default.webpack.html .OK
>> passed test "require-default"
Testing http://localhost:8000/tmp/test-require-indirect.es.html .....OK
>> passed test "import-default"
>> passed test "import-named"
>> passed test "require-default"
>> passed test "require-sub"
>> passed test "require-indirect"
Testing http://localhost:8000/tmp/test-require-indirect.iife.html .....OK
>> passed test "import-default"
>> passed test "import-named"
>> passed test "require-default"
>> passed test "require-sub"
>> passed test "require-indirect"
Testing http://localhost:8000/tmp/test-require-indirect.umd.html .....OK
>> passed test "import-default"
>> passed test "import-named"
>> passed test "require-default"
>> passed test "require-sub"
>> passed test "require-indirect"
Testing http://localhost:8000/tmp/test-require-indirect.webpack.html .....OK
>> passed test "import-default"
>> passed test "import-named"
>> passed test "require-default"
>> passed test "require-sub"
>> passed test "require-indirect"
Testing http://localhost:8000/tmp/test-require-sub.es.html .OK
>> passed test "require-sub"
Testing http://localhost:8000/tmp/test-require-sub.iife.html .OK
>> passed test "require-sub"
Testing http://localhost:8000/tmp/test-require-sub.umd.html .OK
>> passed test "require-sub"
Testing http://localhost:8000/tmp/test-require-sub.webpack.html .OK
>> passed test "require-sub"
>> 56 tests completed in 42ms, with 0 failed, 0 skipped, and 0 todo.
Done.`;
try {
// This will use env CI, CHROMIUM_FLAGS, and PUPPETEER_CACHE_DIR
const actual = cp.execSync('node_modules/.bin/grunt test', {
cwd: DIR,
encoding: 'utf8'
});
assert.equal(normalize(actual).trim(), expected);
} catch (e) {
assert.equal(e.stdout || e.stderr, '', 'error');
}
});