-
Notifications
You must be signed in to change notification settings - Fork 835
/
test-build.js
executable file
·56 lines (45 loc) · 1.91 KB
/
test-build.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
#!/usr/bin/env node
const fs = require('fs-extra');
const path = require('path');
const { build, collectModules } = require('.');
// Istanbul is provided by karma-coverage
const { Instrumenter } = require('istanbul');
if (require.main === module) {
buildCordovaJsTestBundle(process.argv[2])
.catch(err => {
console.error(err);
process.exitCode = 1;
});
}
module.exports = buildCordovaJsTestBundle;
// Writes the cordova-js test build bundle to bundlePath
function buildCordovaJsTestBundle (bundlePath) {
const instrumenter = new Instrumenter();
return build({
platformName: 'test',
platformVersion: 'N/A',
extraModules: collectTestBuildModules(),
preprocess (f) {
// Do not instrument our test dummies
if (f.path.includes('/test/test-platform-modules/')) return f;
const contents = instrumenter.instrumentSync(f.contents, f.path);
return Object.assign({}, f, { contents });
}
})
.then(testBundle => fs.outputFile(bundlePath, testBundle));
}
function collectTestBuildModules () {
// Add platform-specific modules that have tests to the test bundle.
const platformModules = ['android', 'ios'].map(platform => {
const platformPath = path.dirname(require.resolve(`cordova-${platform}/package`));
const modulePath = path.join(platformPath, 'cordova-js-src');
const modules = collectModules(modulePath);
// Prevent overwriting this platform's exec module with the next one
const moduleId = path.posix.join(platform, 'exec');
modules[moduleId] = Object.assign({}, modules.exec, { moduleId });
return modules;
});
// Finally, add modules provided by test platform
const testModulesPath = path.join(__dirname, '../test/test-platform-modules');
return Object.assign(...platformModules, collectModules(testModulesPath));
}