-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
multiAutoTest.js
executable file
·38 lines (25 loc) · 1.21 KB
/
multiAutoTest.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
#!/usr/bin/env node
'use strict';
var assert = require('assert');
var path = require('path');
var args = process.argv.slice(2); // remove node, and script name
assert.equal(args, 0, 'wrong number of arguments; expected 0');
var fakeShim = require('./fakeShim');
assert.equal(fakeShim.calls.length, 0, 'shims are not yet called');
var subPackages = require(process.cwd());
subPackages.forEach(function (subPackage) {
require.cache[require.resolve(path.join(process.cwd(), subPackage, 'shim'))] = require.cache[require.resolve('./fakeShim')];
});
var autoPath = path.join(process.cwd(), './auto');
console.log('## Requiring root ' + autoPath + '...');
require(autoPath);
subPackages.forEach(function (subPackage) {
require(path.join(process.cwd(), subPackage, 'auto'));
});
console.log('## shims were called ' + fakeShim.calls.length + ' times');
assert.equal(fakeShim.calls.length, subPackages.length * 2, 'shim was called twice per sub-package');
var expectedCalls = subPackages.map(function () {
return [undefined, []];
});
assert.deepEqual(fakeShim.calls, expectedCalls.concat(expectedCalls), 'all shims were invoked with no receiver or arguments');
console.log('## all shims were invoked with no receiver or arguments');