Skip to content

Commit fefbf04

Browse files
committed
[test] Upgrade common.js from node core
1 parent 3d61877 commit fefbf04

File tree

1 file changed

+48
-9
lines changed

1 file changed

+48
-9
lines changed

test/core/common.js

+48-9
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ exports.tmpDir = path.join(exports.testDir, 'tmp');
2929
exports.PORT = 12346;
3030
exports.PROXY_PORT = 1234567;
3131

32-
if (process.platform == 'win32') {
32+
if (process.platform === 'win32') {
3333
exports.PIPE = '\\\\.\\pipe\\libuv-test';
3434
} else {
3535
exports.PIPE = exports.tmpDir + '/test.sock';
@@ -54,9 +54,10 @@ exports.indirectInstanceOf = function(obj, cls) {
5454

5555

5656
exports.ddCommand = function(filename, kilobytes) {
57-
if (process.platform == 'win32') {
58-
return '"' + process.argv[0] + '" "' + path.resolve(exports.fixturesDir,
59-
'create-file.js') + '" "' + filename + '" ' + (kilobytes * 1024);
57+
if (process.platform === 'win32') {
58+
var p = path.resolve(exports.fixturesDir, 'create-file.js');
59+
return '"' + process.argv[0] + '" "' + p + '" "' +
60+
filename + '" ' + (kilobytes * 1024);
6061
} else {
6162
return 'dd if=/dev/zero of="' + filename + '" bs=1024 count=' + kilobytes;
6263
}
@@ -66,7 +67,7 @@ exports.ddCommand = function(filename, kilobytes) {
6667
exports.spawnPwd = function(options) {
6768
var spawn = require('child_process').spawn;
6869

69-
if (process.platform == 'win32') {
70+
if (process.platform === 'win32') {
7071
return spawn('cmd.exe', ['/c', 'cd'], options);
7172
} else {
7273
return spawn('pwd', [], options);
@@ -81,8 +82,10 @@ process.on('exit', function() {
8182
if (!exports.globalCheck) return;
8283
var knownGlobals = [setTimeout,
8384
setInterval,
85+
setImmediate,
8486
clearTimeout,
8587
clearInterval,
88+
clearImmediate,
8689
console,
8790
Buffer,
8891
process,
@@ -111,6 +114,7 @@ process.on('exit', function() {
111114
knownGlobals.push(ArrayBuffer);
112115
knownGlobals.push(Int8Array);
113116
knownGlobals.push(Uint8Array);
117+
knownGlobals.push(Uint8ClampedArray);
114118
knownGlobals.push(Int16Array);
115119
knownGlobals.push(Uint16Array);
116120
knownGlobals.push(Int32Array);
@@ -138,8 +142,43 @@ process.on('exit', function() {
138142
});
139143

140144

141-
// This function allows one two run an HTTP test agaist both HTTPS and
142-
// normal HTTP modules. This ensures they fit the same API.
143-
exports.httpTest = function httpTest(cb) {
144-
};
145+
var mustCallChecks = [];
146+
147+
148+
function runCallChecks() {
149+
var failed = mustCallChecks.filter(function(context) {
150+
return context.actual !== context.expected;
151+
});
152+
153+
failed.forEach(function(context) {
154+
console.log('Mismatched %s function calls. Expected %d, actual %d.',
155+
context.name,
156+
context.expected,
157+
context.actual);
158+
console.log(context.stack.split('\n').slice(2).join('\n'));
159+
});
160+
161+
if (failed.length) process.exit(1);
162+
}
145163

164+
165+
exports.mustCall = function(fn, expected) {
166+
if (typeof expected !== 'number') expected = 1;
167+
168+
var context = {
169+
expected: expected,
170+
actual: 0,
171+
stack: (new Error).stack,
172+
name: fn.name || '<anonymous>'
173+
};
174+
175+
// add the exit listener only once to avoid listener leak warnings
176+
if (mustCallChecks.length === 0) process.on('exit', runCallChecks);
177+
178+
mustCallChecks.push(context);
179+
180+
return function() {
181+
context.actual++;
182+
return fn.apply(this, arguments);
183+
};
184+
};

0 commit comments

Comments
 (0)