-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
/
run-tests.js
executable file
·248 lines (224 loc) · 6.78 KB
/
run-tests.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
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
/* eslint-disable no-console */
'use strict';
const execa = require('execa');
const execFile = require('child_process').execFile;
const chalk = require('chalk');
const runInSequence = require('../lib/run-in-sequence');
const path = require('path');
const finalhandler = require('finalhandler');
const http = require('http');
const serveStatic = require('serve-static');
const fs = require('fs');
// Serve up public/ftp folder.
const serve = serveStatic('./dist/', { index: ['index.html', 'index.htm'] });
// Create server.
const server = http.createServer(function(req, res) {
let done = finalhandler(req, res);
serve(req, res, done);
});
const PORT = 13141;
// Listen.
server.listen(PORT);
// Cache the Chrome browser instance when launched for new pages.
let browserRunner;
function getBrowserRunner() {
if (browserRunner === undefined) {
// requires new node
let BroswerRunner = require('./run-tests-browser-runner');
browserRunner = new BroswerRunner();
}
return browserRunner;
}
function run(queryString) {
var url = 'http://localhost:' + PORT + '/tests/?' + queryString;
return runInBrowser(url, 3);
}
function runInBrowser(url, attempts) {
console.log('Running Chrome headless: ' + url);
return getBrowserRunner().run(url, attempts);
}
var testFunctions = [];
function generateTestsFor(packageName) {
let relativePath = path.join('packages', packageName);
if (!fs.existsSync(path.join(relativePath, 'tests'))) {
return;
}
testFunctions.push(function() {
return run('package=' + packageName);
});
testFunctions.push(function() {
return run('package=' + packageName + '&dist=es');
});
testFunctions.push(function() {
return run('package=' + packageName + '&enableoptionalfeatures=true');
});
// TODO: this should ultimately be deleted (when all packages can run with and
// without jQuery)
if (packageName !== 'ember') {
testFunctions.push(function() {
return run('package=' + packageName + '&jquery=none');
});
}
}
function generateEachPackageTests() {
fs.readdirSync('packages/@ember').forEach(e => generateTestsFor(`@ember/${e}`));
fs
.readdirSync('packages')
.filter(e => e !== '@ember')
.forEach(generateTestsFor);
}
function generateBuiltTests() {
// Container isn't publicly available.
// ember-testing and @ember/debug are stripped from prod/min.
var common = 'skipPackage=container,ember-testing,@ember/debug';
testFunctions.push(function() {
return run(common + '&nolint=true');
});
testFunctions.push(function() {
return run(common + '&dist=min&prod=true');
});
testFunctions.push(function() {
return run(common + '&dist=prod&prod=true');
});
testFunctions.push(function() {
return run(common + '&enableoptionalfeatures=true&dist=prod&prod=true');
});
testFunctions.push(function() {
return run(common + '&ie=true&nolint=true');
});
testFunctions.push(function() {
return run(common + '&ie=true&dist=min&prod=true');
});
testFunctions.push(function() {
return run(common + '&ie=true&dist=prod&prod=true');
});
testFunctions.push(function() {
return run(common + '&ie=true&enableoptionalfeatures=true&dist=prod&prod=true');
});
}
function generateOldJQueryTests() {
testFunctions.push(function() {
return run('jquery=1.8.3&nolint=true');
});
testFunctions.push(function() {
return run('jquery=1.10.2&nolint=true');
});
testFunctions.push(function() {
return run('jquery=2.2.4&nolint=true');
});
}
function generateExtendPrototypeTests() {
testFunctions.push(function() {
return run('extendprototypes=true&nolint=true');
});
testFunctions.push(function() {
return run('extendprototypes=true&nolint=true&enableoptionalfeatures=true');
});
}
function runChecker(bin, args) {
return new Promise(function(resolve) {
execFile(bin, args, {}, function(error, stdout, stderr) {
// I'm buffering instead of inheriting these so that each
// checker doesn't interleave its output
process.stdout.write(stdout.toString('utf8'));
process.stderr.write(stderr.toString('utf8'));
resolve({ name: path.basename(args[0]), ok: !error });
});
});
}
function codeQualityChecks() {
var checkers = [
runChecker('node', [require.resolve('typescript/bin/tsc'), '--noEmit']),
runChecker('node', [require.resolve('tslint/bin/tslint'), '-p', 'tsconfig.json']),
runChecker('node', [require.resolve('eslint/bin/eslint'), '.']),
runChecker('node', [require.resolve('qunit/bin/qunit'), 'tests/docs/coverage-test.js']),
];
return Promise.all(checkers).then(function(results) {
results.forEach(result => {
if (result.ok) {
console.log(result.name + ': ' + chalk.green('OK'));
} else {
console.log(result.name + ': ' + chalk.red('Failed'));
}
});
if (!results.every(result => result.ok)) {
throw new Error('Some quality checks failed');
}
});
}
function runAndExit() {
runInSequence(testFunctions)
.then(function() {
console.log(chalk.green('Passed!'));
process.exit(0);
})
.catch(function(err) {
console.error(chalk.red(err.toString()));
console.error(chalk.red('Failed!'));
process.exit(1);
});
}
let p = process.env.PACKAGE || 'ember';
switch (process.env.TEST_SUITE) {
case 'package':
console.log(`suite: package ${p}`);
generateTestsFor(p);
runAndExit();
break;
case 'built-tests':
console.log('suite: built-tests');
generateBuiltTests();
runAndExit();
break;
case 'old-jquery-and-extend-prototypes':
console.log('suite: old-jquery-and-extend-prototypes');
generateOldJQueryTests();
generateExtendPrototypeTests();
runAndExit();
break;
case 'all':
console.log('suite: all');
generateBuiltTests();
generateOldJQueryTests();
generateExtendPrototypeTests();
generateEachPackageTests();
runAndExit();
break;
case 'node': {
console.log('suite: node');
let stream = execa('yarn', ['test:node']);
stream.stdout.pipe(process.stdout);
stream.then(
function() {
console.log(chalk.green('Passed!'));
process.exit(0);
},
function() {
console.error(chalk.red('Failed!'));
process.exit(1);
}
);
break;
}
case 'blueprints':
console.log('suite: blueprints');
require('../node-tests/nodetest-runner');
server.close();
break;
case 'travis-browsers':
console.log('suite: travis-browsers');
require('./run-travis-browser-tests');
break;
case 'browserstack':
console.log('suite: browserstack');
require('./run-browserstack-tests');
break;
case 'code-quality':
testFunctions.push(codeQualityChecks);
runAndExit();
break;
default:
console.log('suite: default (generate each package)');
generateEachPackageTests();
runAndExit();
}