Skip to content

Commit

Permalink
[io.js] Update jsdom and get jest working on io.js
Browse files Browse the repository at this point in the history
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.

Also mocked out JSDomEnvironment under __mocks__ instead of doing it in each test. Each test used to implement its own JSDomEnvironment. This diff removes the copy-pasted code and introduces a shared mock under __mocks__.

Test Plan:
```
nvm install iojs-1
rm -fr node_modules && npm install

nvm install iojs-2
rm -fr node_modules && npm install
```
  • Loading branch information
ide committed Jun 17, 2015
1 parent 4ba9cad commit c933916
Show file tree
Hide file tree
Showing 17 changed files with 124 additions and 144 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
language: node_js
node_js:
- "0.10"
- "iojs-v1"
- "iojs-v2"
sudo: false
3 changes: 0 additions & 3 deletions bin/jest.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
'use strict';

var fs = require('fs');
var harmonize = require('harmonize');
var optimist = require('optimist');
var path = require('path');

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

harmonize();

var argv = optimist
.usage('Usage: $0 [--config=<pathToConfigFile>] [TestPathRegExp]')
.options({
Expand Down
35 changes: 17 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,31 @@
"version": "0.4.13",
"main": "src/jest.js",
"dependencies": {
"coffee-script": "^1.8.0",
"cover": "~0.2.8",
"diff": "~1.0.4",
"graceful-fs": "^2.0.3",
"harmonize": "1.4.2",
"istanbul": "^0.3.2",
"jasmine-only": "0.1.0",
"jasmine-pit": "~2.0.0",
"jsdom": "~0.10.3",
"coffee-script": "jashkenas/coffeescript",
"cover": "^0.2.9",
"diff": "^1.4.0",
"graceful-fs": "^3.0.8",
"istanbul": "^0.3.15",
"jasmine-only": "^0.1.1",
"jasmine-pit": "^2.0.2",
"jsdom": "^5.4.3",
"lodash.template": "^3.6.1",
"node-haste": "^1.2.8",
"node-worker-pool": "~2.4.2",
"optimist": "~0.6.0",
"q": "~0.9.7",
"resolve": "~0.6.1",
"through": "^2.3.4",
"lodash.template": "^3.0.0"
"node-worker-pool": "^2.4.4",
"optimist": "^0.6.1",
"q": "^1.4.1",
"resolve": "^1.1.6",
"through": "^2.3.7"
},
"devDependencies": {
"jshint": "~2.5.0",
"node-find-files": "0.0.2"
"jshint": "^2.8.0",
"node-find-files": "0.0.4"
},
"bin": {
"jest": "./bin/jest.js"
},
"engines": {
"node": "0.8.x || 0.10.x"
"node": ">= 1"
},
"repository": {
"type": "git",
Expand Down
21 changes: 8 additions & 13 deletions src/HasteModuleLoader/HasteModuleLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,6 @@ function Loader(config, environment, resourceMap) {
}

if (_configUnmockListRegExpCache === null) {
// Node must have been run with --harmony in order for WeakMap to be
// available prior to version 0.12
if (typeof WeakMap !== 'function') {
throw new Error(
'Please run node with the --harmony flag! jest requires WeakMap ' +
'which is only available with the --harmony flag in node < v0.12'
);
}

_configUnmockListRegExpCache = new WeakMap();
}

Expand Down Expand Up @@ -868,14 +859,14 @@ Loader.prototype.requireModule = function(currPath, moduleName,
modulePath = manualMockResource.path;
}

if (!modulePath) {
modulePath = this._moduleNameToPath(currPath, moduleName);
}

if (NODE_CORE_MODULES[moduleName]) {
return require(moduleName);
}

if (!modulePath) {
modulePath = this._moduleNameToPath(currPath, moduleName);
}

// Always natively require the jasmine runner.
if (modulePath.indexOf(VENDOR_PATH) === 0) {
return require(modulePath);
Expand Down Expand Up @@ -1043,6 +1034,10 @@ Loader.prototype.resetModuleRegistry = function() {
this._environment.fakeTimers.runAllTicks();
}.bind(this),

runAllImmediates: function() {
this._environment.fakeTimers.runAllImmediates();
}.bind(this),

runAllTimers: function() {
this._environment.fakeTimers.runAllTimers();
}.bind(this),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@
'use strict';

jest.autoMockOff();
jest.mock('../../JSDomEnvironment');

var path = require('path');
var q = require('q');
var utils = require('../../lib/utils');

describe('HasteModuleLoader', function() {
var HasteModuleLoader;
var mockEnvironment;
var JSDomEnvironment;
var resourceMap;

var CONFIG = utils.normalizeConfig({
Expand All @@ -30,23 +31,15 @@ describe('HasteModuleLoader', function() {
return buildLoader();
});
} else {
var mockEnvironment = new JSDomEnvironment(CONFIG);
return q(new HasteModuleLoader(CONFIG, mockEnvironment, resourceMap));
}
}

function initHasteModuleLoader(nodePath) {
process.env.NODE_PATH = nodePath;
HasteModuleLoader = require('../HasteModuleLoader');
mockEnvironment = {
global: {
console: {},
mockClearTimers: jest.genMockFn()
},
runSourceText: jest.genMockFn().mockImplementation(function(codeStr) {
/* jshint evil:true */
return (new Function('return ' + codeStr))();
})
};
JSDomEnvironment = require('../../JSDomEnvironment');
}

pit('uses NODE_PATH to find modules', function() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@
'use strict';

jest.autoMockOff();
jest.mock('../../JSDomEnvironment');

var path = require('path');
var q = require('q');
var utils = require('../../lib/utils');

describe('nodeHasteModuleLoader', function() {
var HasteModuleLoader;
var mockEnvironment;
var JSDomEnvironment;
var resourceMap;

var CONFIG = utils.normalizeConfig({
Expand All @@ -30,23 +31,14 @@ describe('nodeHasteModuleLoader', function() {
return buildLoader();
});
} else {
var mockEnvironment = new JSDomEnvironment(CONFIG);
return q(new HasteModuleLoader(CONFIG, mockEnvironment, resourceMap));
}
}

beforeEach(function() {
HasteModuleLoader = require('../HasteModuleLoader');

mockEnvironment = {
global: {
console: {},
mockClearTimers: jest.genMockFn()
},
runSourceText: jest.genMockFn().mockImplementation(function(codeStr) {
/* jshint evil:true */
return (new Function('return ' + codeStr))();
})
};
JSDomEnvironment = require('../../JSDomEnvironment');
});

describe('genMockFromModule', function() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
'use strict';

jest.autoMockOff();
jest.mock('../../JSDomEnvironment');

describe('nodeHasteModuleLoader', function() {
var HasteModuleLoader;
Expand Down Expand Up @@ -42,18 +43,10 @@ describe('nodeHasteModuleLoader', function() {
}

beforeEach(function() {
var JSDomEnvironment = require('../../JSDomEnvironment');
HasteModuleLoader = require('../HasteModuleLoader');

mockEnvironment = {
global: {
console: {},
mockClearTimers: jest.genMockFn()
},
runSourceText: jest.genMockFn().mockImplementation(function(codeStr) {
/* jshint evil: true */
return (new Function('return ' + codeStr))();
})
};
mockEnvironment = new JSDomEnvironment(mockConfig);
resources = {};
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@
'use strict';

jest.autoMockOff();
jest.mock('../../JSDomEnvironment');

var path = require('path');
var q = require('q');
var utils = require('../../lib/utils');

describe('HasteModuleLoader', function() {
var HasteModuleLoader;
var mockEnvironment;
var JSDomEnvironment;
var resourceMap;

var CONFIG = utils.normalizeConfig({
Expand All @@ -30,23 +31,14 @@ describe('HasteModuleLoader', function() {
return buildLoader();
});
} else {
var mockEnvironment = new JSDomEnvironment(CONFIG);
return q(new HasteModuleLoader(CONFIG, mockEnvironment, resourceMap));
}
}

beforeEach(function() {
HasteModuleLoader = require('../HasteModuleLoader');

mockEnvironment = {
global: {
console: {},
mockClearTimers: jest.genMockFn()
},
runSourceText: jest.genMockFn().mockImplementation(function(codeStr) {
/* jshint evil:true */
return (new Function('return ' + codeStr))();
})
};
JSDomEnvironment = require('../../JSDomEnvironment');
});

describe('requireMock', function() {
Expand Down Expand Up @@ -144,7 +136,7 @@ describe('HasteModuleLoader', function() {
expect(loader.requireMock(null, 'events').EventEmitter).toBeDefined();
});
});

pit('throws on non-existant @providesModule modules', function() {
return buildLoader().then(function(loader) {
expect(function() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@
'use strict';

jest.autoMockOff();
jest.mock('../../JSDomEnvironment');

var path = require('path');
var q = require('q');
var utils = require('../../lib/utils');

describe('HasteModuleLoader', function() {
var HasteModuleLoader;
var mockEnvironment;
var JSDomEnvironment;
var resourceMap;

var CONFIG = utils.normalizeConfig({
Expand All @@ -30,24 +31,14 @@ describe('HasteModuleLoader', function() {
return buildLoader();
});
} else {
var mockEnvironment = new JSDomEnvironment(CONFIG);
return q(new HasteModuleLoader(CONFIG, mockEnvironment, resourceMap));
}
}

beforeEach(function() {
HasteModuleLoader = require('../HasteModuleLoader');

mockEnvironment = {
global: {
console: {},
mockClearTimers: jest.genMockFn(),
JSON: JSON
},
runSourceText: jest.genMockFn().mockImplementation(function(codeStr) {
/* jshint evil:true */
return (new Function('return ' + codeStr))();
})
};
JSDomEnvironment = require('../../JSDomEnvironment');
});

describe('requireModule', function() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@
'use strict';

jest.autoMockOff();
jest.mock('../../JSDomEnvironment');

var path = require('path');
var q = require('q');
var utils = require('../../lib/utils');

describe('HasteModuleLoader', function() {
var HasteModuleLoader;
var mockEnvironment;
var JSDomEnvironment;
var resourceMap;

var CONFIG = utils.normalizeConfig({
Expand All @@ -30,23 +31,14 @@ describe('HasteModuleLoader', function() {
return buildLoader();
});
} else {
var mockEnvironment = new JSDomEnvironment(CONFIG);
return q(new HasteModuleLoader(CONFIG, mockEnvironment, resourceMap));
}
}

beforeEach(function() {
HasteModuleLoader = require('../HasteModuleLoader');

mockEnvironment = {
global: {
console: {},
mockClearTimers: jest.genMockFn()
},
runSourceText: jest.genMockFn().mockImplementation(function(codeStr) {
/* jshint evil:true */
return (new Function('return ' + codeStr))();
})
};
JSDomEnvironment = require('../../JSDomEnvironment');
});

describe('requireModuleOrMock', function() {
Expand Down
Loading

0 comments on commit c933916

Please sign in to comment.