Skip to content

Commit 7ca1234

Browse files
committed
[io.js] Update jsdom and get jest working on io.js
This gets jest working on io.js 1.8.x and 2.0.x. io.js is reconciling with the Node Foundation so users who are still on Node are on the upgrade path that converges with io.js anyway. What this means is the jest version probably should be bumped to 0.5.0, where 0.4.x is a maintenance branch for legacy Node (typically with semver, a major version bump is required but 0.x.x releases are considered a free-for-all). This diff is near the minimal amount of work to bring jest up to date and pass all of its tests. - Upgraded npm dependencies. The major update is jsdom from 0.10.3 to 5.4.3. This lets us drop the indirect contextify dependency. - Removed harmonize, since io.js uses modern V8 and enables stable ES6 features by default - Removed the `--harmony` flag from the TestRunner for the same reason (trivia: i added that line once upon a time, let me delete it) - Replaced jsdom's `run` with io.js's built-in `vm` module - Added support for curried arguments in the fake `nextTick` implementation, which io.js itself relies on - Updated the HasteModuleLoader to handle Node built-in modules before `node_modules` -- this fixes an issue I was getting with graceful-fs trying to require smalloc. - Patched coffeescript to use Array.isArray instead of `instanceof Array`. Working on getting that merged upstream. Test Plan: ``` nvm install iojs-1 rm -fr node_modules && npm install nvm install iojs-2 rm -fr node_modules && npm install ```
1 parent 69229fb commit 7ca1234

File tree

8 files changed

+34
-55
lines changed

8 files changed

+34
-55
lines changed

bin/jest.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
'use strict';
1111

1212
var fs = require('fs');
13-
var harmonize = require('harmonize');
1413
var optimist = require('optimist');
1514
var path = require('path');
1615

@@ -36,8 +35,6 @@ function _wrapDesc(desc) {
3635
}, ['']).join(indent);
3736
}
3837

39-
harmonize();
40-
4138
var argv = optimist
4239
.usage('Usage: $0 [--config=<pathToConfigFile>] [TestPathRegExp]')
4340
.options({

package.json

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,30 @@
44
"version": "0.4.5",
55
"main": "src/jest.js",
66
"dependencies": {
7-
"coffee-script": "^1.8.0",
8-
"cover": "~0.2.8",
9-
"diff": "~1.0.4",
10-
"graceful-fs": "^2.0.3",
11-
"harmonize": "1.4.2",
12-
"istanbul": "^0.3.2",
13-
"jasmine-only": "0.1.0",
14-
"jasmine-pit": "~2.0.0",
15-
"jsdom": "~0.10.3",
7+
"coffee-script": "ide/coffeescript#array-check",
8+
"cover": "^0.2.9",
9+
"diff": "^1.4.0",
10+
"graceful-fs": "^3.0.7",
11+
"istanbul": "^0.3.14",
12+
"jasmine-only": "^0.1.1",
13+
"jasmine-pit": "^2.0.2",
14+
"jsdom": "^5.4.2",
1615
"node-haste": "^1.2.8",
17-
"node-worker-pool": "~2.4.2",
18-
"optimist": "~0.6.0",
19-
"q": "~0.9.7",
20-
"resolve": "~0.6.1",
21-
"through": "^2.3.4",
22-
"lodash.template": "^3.0.0"
16+
"node-worker-pool": "^2.4.4",
17+
"optimist": "^0.6.1",
18+
"q": "^1.4.1",
19+
"resolve": "^1.1.6",
20+
"through": "^2.3.7"
2321
},
2422
"devDependencies": {
25-
"jshint": "~2.5.0",
26-
"node-find-files": "0.0.2"
23+
"jshint": "^2.7.0",
24+
"node-find-files": "0.0.4"
2725
},
2826
"bin": {
2927
"jest": "./bin/jest.js"
3028
},
3129
"engines": {
32-
"node": "0.8.x || 0.10.x"
30+
"node": ">= 1"
3331
},
3432
"repository": {
3533
"type": "git",

src/HasteModuleLoader/HasteModuleLoader.js

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -129,15 +129,6 @@ function Loader(config, environment, resourceMap) {
129129
this._configShouldMockModuleNames = {};
130130

131131
if (_configUnmockListRegExpCache === null) {
132-
// Node must have been run with --harmony in order for WeakMap to be
133-
// available prior to version 0.12
134-
if (typeof WeakMap !== 'function') {
135-
throw new Error(
136-
'Please run node with the --harmony flag! jest requires WeakMap ' +
137-
'which is only available with the --harmony flag in node < v0.12'
138-
);
139-
}
140-
141132
_configUnmockListRegExpCache = new WeakMap();
142133
}
143134

@@ -862,14 +853,14 @@ Loader.prototype.requireModule = function(currPath, moduleName,
862853
modulePath = manualMockResource.path;
863854
}
864855

865-
if (!modulePath) {
866-
modulePath = this._moduleNameToPath(currPath, moduleName);
867-
}
868-
869856
if (NODE_CORE_MODULES[moduleName]) {
870857
return require(moduleName);
871858
}
872859

860+
if (!modulePath) {
861+
modulePath = this._moduleNameToPath(currPath, moduleName);
862+
}
863+
873864
// Always natively require the jasmine runner.
874865
if (modulePath.indexOf(VENDOR_PATH) === 0) {
875866
return require(modulePath);

src/JSDomEnvironment.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
var FakeTimers = require('./lib/FakeTimers');
1111

12+
var vm = require('vm');
13+
1214
function _deepCopy(obj) {
1315
var newObj = {};
1416
var value;
@@ -29,7 +31,7 @@ function JSDomEnvironment(config) {
2931
// use it (depending on the context -- such as TestRunner.js when operating as
3032
// a workerpool parent), this is the best way to ensure we only spend time
3133
// require()ing this when necessary.
32-
this.global = require('./lib/jsdom-compat').jsdom().parentWindow;
34+
this.global = require('./lib/jsdom-compat').jsdom().defaultView;
3335

3436
// Node's error-message stack size is limited at 10, but it's pretty useful to
3537
// see more than that when a test fails.
@@ -52,7 +54,6 @@ function JSDomEnvironment(config) {
5254
this.global.Uint32Array = Uint32Array;
5355
this.global.DataView = DataView;
5456
this.global.Buffer = Buffer;
55-
this.global.process = process;
5657
this.global.setImmediate = setImmediate;
5758
this.global.clearImmediate = clearImmediate;
5859

@@ -105,7 +106,10 @@ JSDomEnvironment.prototype.dispose = function() {
105106
};
106107

107108
JSDomEnvironment.prototype.runSourceText = function(sourceText, fileName) {
108-
return this.global.run(sourceText, fileName);
109+
var sandbox = vm.createContext(this.global);
110+
return vm.runInContext(sourceText, sandbox, {
111+
filename: fileName,
112+
});
109113
};
110114

111115
JSDomEnvironment.prototype.runWithRealTimers = function(cb) {

src/TestRunner.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,6 @@ TestRunner.prototype._createParallelTestRun = function(
494494
this._opts.maxWorkers,
495495
this._opts.nodePath,
496496
this._opts.nodeArgv.concat([
497-
'--harmony',
498497
TEST_WORKER_PATH,
499498
'--config=' + JSON.stringify(this._config)
500499
])

src/jasmineTestRunner/JasmineReporter.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -201,14 +201,7 @@ JasmineReporter.prototype._prettyPrint = function(obj, indent, cycleWeakMap) {
201201
')';
202202
}
203203

204-
/* jshint camelcase:false */
205204
if (!cycleWeakMap) {
206-
if (typeof WeakMap !== 'function') {
207-
throw new Error(
208-
'Please run node with the --harmony flag! jest requires WeakMap ' +
209-
'which is only available with the --harmony flag in node < v0.12'
210-
);
211-
}
212205
cycleWeakMap = new WeakMap();
213206
}
214207

@@ -231,6 +224,7 @@ JasmineReporter.prototype._prettyPrint = function(obj, indent, cycleWeakMap) {
231224
this._prettyPrint(value, indent + keyIndent, cycleWeakMap)
232225
);
233226
}
227+
/* jshint camelcase:false */
234228
delete obj.__jstest_pp_cycle__;
235229
return '{\n' + keysOutput.join(',\n') + '\n' + indent + '}';
236230
} else {

src/jasmineTestRunner/jasmineTestRunner.js

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,6 @@ function jasmineTestRunner(config, environment, moduleLoader, testPath) {
5454
// Install jasmine-only
5555
environment.runSourceText(jasmineOnlyContent);
5656

57-
// Node must have been run with --harmony in order for WeakMap to be
58-
// available prior to version 0.12
59-
if (typeof WeakMap !== 'function') {
60-
throw new Error(
61-
'Please run node with the --harmony flag! jest requires WeakMap ' +
62-
'which is only available with the --harmony flag in node < v0.12'
63-
);
64-
}
65-
6657
// Mainline Jasmine sets __Jasmine_been_here_before__ on each object to
6758
// detect cycles, but that doesn't work on frozen objects so we use a
6859
// WeakMap instead.

src/lib/FakeTimers.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,11 @@ FakeTimers.prototype._fakeClearImmediate = function(uuid) {
315315
};
316316

317317
FakeTimers.prototype._fakeNextTick = function(callback) {
318+
var args = [];
319+
for (var ii = 1, ll = arguments.length; ii < ll; ii++) {
320+
args.push(arguments[ii]);
321+
}
322+
318323
var uuid = this._uuidCounter++;
319324
this._ticks.push({
320325
uuid: uuid,
@@ -326,7 +331,7 @@ FakeTimers.prototype._fakeNextTick = function(callback) {
326331
if (!cancelledTicks.hasOwnProperty(uuid)) {
327332
// Callback may throw, so update the map prior calling.
328333
cancelledTicks[uuid] = true;
329-
callback();
334+
callback.apply(null, args);
330335
}
331336
});
332337
};

0 commit comments

Comments
 (0)