Skip to content

Commit

Permalink
Updates for haste2 inside of jest
Browse files Browse the repository at this point in the history
Summary:
I'm working on deploying haste2 with jest. This updates all the files that require changes for this to work and they are backwards compatible with the current version of jest.

* package.json was just outdated. I think haste1's liberal handling with collisions made this a "non-issue"
* env.js didn't properly set up ErrorUtils, also unsure why that isn't a problem in jest right now already?
* some things were mocking things they shouldn't
* Because of the regex that matches against providesModule and System.import, it isn't possible to list module names more than once. We have multiple tests reusing the same providesModule ids and using System.import with modules that only exist virtually within that test. Splitting up the strings makes the regexes work (we do the same kind of splitting on www sometimes if we need to) and using different providesModule names in different test files fixes the problem. I think the BundlesLayoutIntegration-test is going to be deleted, so this doesn't even matter.

public

Reviewed By: voideanvalue

Differential Revision: D2809681

fb-gh-sync-id: 8fe6ed8b5a1be28ba141e9001de143e502693281
  • Loading branch information
cpojer authored and facebook-github-bot-5 committed Jan 8, 2016
1 parent 8ecd352 commit b84ad2a
Show file tree
Hide file tree
Showing 10 changed files with 123 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
'use strict';

jest
.dontMock('Map')
.dontMock('NavigationTreeNode')
.dontMock('invariant')
.dontMock('immutable');
Expand Down
4 changes: 2 additions & 2 deletions Libraries/Interaction/TaskQueue.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ export type Task = Function | SimpleTask | PromiseTask;
* function is supplied, then the promise it returns will block execution of
* tasks already in the queue until it resolves. This can be used to make sure
* the first task is fully resolved (including asynchronous dependencies that
* also schedule more tasks via `enqueue`) before starting on the next task.
* The `onMoreTasks` constructor argument is used to inform the owner that an
* also schedule more tasks via `enqueue`) before starting on the next task.
* The `onMoreTasks` constructor argument is used to inform the owner that an
* async task has resolved and that the queue should be processed again.
*
* Note: Tasks are only actually executed with explicit calls to `processNext`.
Expand Down
10 changes: 2 additions & 8 deletions Libraries/Utilities/__tests__/MessageQueue-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,8 @@
*/
'use strict';

jest.setMock('ReactUpdates', {
batchedUpdates: fn => fn()
});

jest.dontMock('MessageQueue');
jest.dontMock('keyMirror');
jest.dontMock('MessageQueue')
.dontMock('keyMirror');
var MessageQueue = require('MessageQueue');

let MODULE_IDS = 0;
Expand All @@ -24,8 +20,6 @@ let TestModule = {
testHook1(){}, testHook2(){},
};

let customRequire = (moduleName) => TestModule;

let assertQueue = (flushedQueue, index, moduleID, methodID, params) => {
expect(flushedQueue[MODULE_IDS][index]).toEqual(moduleID);
expect(flushedQueue[METHOD_IDS][index]).toEqual(methodID);
Expand Down
2 changes: 2 additions & 0 deletions jestSupport/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@ global.__fbBatchedBridgeConfig = {
};

global.Promise = require('promise');

jest.setMock('ErrorUtils', require('ErrorUtils'));
51 changes: 51 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,57 @@
"testPathIgnorePatterns": [
"/node_modules/"
],
"modulePathIgnorePatterns": [
"node_modules/react/lib/React.js",
"node_modules/react/lib/ReactDOM.js",

"node_modules/fbjs/lib/Map.js",
"node_modules/fbjs/lib/Promise.js",
"node_modules/fbjs/lib/fetch.js",
"node_modules/fbjs/lib/ErrorUtils.js",
"node_modules/fbjs/lib/URI.js",
"node_modules/fbjs/lib/Deferred.js",
"node_modules/fbjs/lib/PromiseMap.js",
"node_modules/fbjs/lib/UserAgent.js",
"node_modules/fbjs/lib/areEqual.js",
"node_modules/fbjs/lib/base62.js",
"node_modules/fbjs/lib/crc32.js",
"node_modules/fbjs/lib/everyObject.js",
"node_modules/fbjs/lib/fetchWithRetries.js",
"node_modules/fbjs/lib/filterObject.js",
"node_modules/fbjs/lib/flattenArray.js",
"node_modules/fbjs/lib/forEachObject.js",
"node_modules/fbjs/lib/isEmpty.js",
"node_modules/fbjs/lib/nullthrows.js",
"node_modules/fbjs/lib/removeFromArray.js",
"node_modules/fbjs/lib/resolveImmediate.js",
"node_modules/fbjs/lib/someObject.js",
"node_modules/fbjs/lib/sprintf.js",
"node_modules/fbjs/lib/xhrSimpleDataSerializer.js",

"downstream/core/CSSCore.js",
"downstream/core/TouchEventUtils.js",
"downstream/core/camelize.js",
"downstream/core/createArrayFromMixed.js",
"downstream/core/createNodesFromMarkup.js",
"downstream/core/dom/containsNode.js",
"downstream/core/dom/focusNode.js",
"downstream/core/dom/getActiveElement.js",
"downstream/core/dom/getUnboundedScrollPosition.js",
"downstream/core/dom/isNode.js",
"downstream/core/dom/isTextNode.js",
"downstream/core/emptyFunction.js",
"downstream/core/emptyObject.js",
"downstream/core/getMarkupWrap.js",
"downstream/core/hyphenate.js",
"downstream/core/hyphenateStyleName.js",
"downstream/core/invariant.js",
"downstream/core/nativeRequestAnimationFrame.js",
"downstream/core/toArray.js",

"node_modules/jest-cli",
"node_modules/react/dist"
],
"testFileExtensions": [
"js"
],
Expand Down
2 changes: 1 addition & 1 deletion packager/blacklist.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

var path = require('path');

// Don't forget to everything listed here to `testConfig.json`
// Don't forget to everything listed here to `package.json`
// modulePathIgnorePatterns.
var sharedBlacklist = [
/node_modules[/\\]react[/\\]dist[/\\].*/,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ describe('BundlesLayout', () => {
'root': {
'index.js': `
/**
* @providesModule index
* @providesModule xindex
*/`,
}
});
Expand All @@ -116,12 +116,12 @@ describe('BundlesLayout', () => {
'root': {
'index.js': `
/**
* @providesModule index
* @providesModule xindex
*/
require("a");`,
require("xa");`,
'a.js': `
/**
* @providesModule a
* @providesModule xa
*/`,
}
});
Expand All @@ -142,12 +142,12 @@ describe('BundlesLayout', () => {
'root': {
'index.js': `
/**
* @providesModule index
* @providesModule xindex
*/
System.import("a");`,
${'System.import'}("xa");`,
'a.js': `
/**,
* @providesModule a
* @providesModule xa
*/`,
}
});
Expand All @@ -172,17 +172,17 @@ describe('BundlesLayout', () => {
'root': {
'index.js': `
/**
* @providesModule index
* @providesModule xindex
*/
System.import("a");
System.import("b");`,
${'System.import'}("xa");
${'System.import'}("xb");`,
'a.js': `
/**,
* @providesModule a
* @providesModule xa
*/`,
'b.js': `
/**
* @providesModule b
* @providesModule xb
*/`,
}
});
Expand Down Expand Up @@ -213,17 +213,17 @@ describe('BundlesLayout', () => {
'root': {
'index.js': `
/**
* @providesModule index
* @providesModule xindex
*/
require("a");
System.import("b");`,
require("xa");
${'System.import'}("xb");`,
'a.js': `
/**,
* @providesModule a
* @providesModule xa
*/`,
'b.js': `
/**
* @providesModule b
* @providesModule xb
*/`,
}
});
Expand All @@ -248,22 +248,22 @@ describe('BundlesLayout', () => {
'root': {
'index.js': `
/**
* @providesModule index
* @providesModule xindex
*/
System.import("a");`,
${'System.import'}("xa");`,
'a.js': `
/**,
* @providesModule a
* @providesModule xa
*/,
require("b");`,
require("xb");`,
'b.js': `
/**
* @providesModule b
* @providesModule xb
*/
require("c");`,
require("xc");`,
'c.js': `
/**
* @providesModule c
* @providesModule xc
*/`,
}
});
Expand All @@ -288,23 +288,23 @@ describe('BundlesLayout', () => {
'root': {
'index.js': `
/**
* @providesModule index
* @providesModule xindex
*/
System.import("a");
System.import("b");`,
${'System.import'}("xa");
${'System.import'}("xb");`,
'a.js': `
/**,
* @providesModule a
* @providesModule xa
*/,
require("c");`,
require("xc");`,
'b.js': `
/**
* @providesModule b
* @providesModule xb
*/
require("c");`,
require("xc");`,
'c.js': `
/**
* @providesModule c
* @providesModule xc
*/`,
}
});
Expand Down Expand Up @@ -336,22 +336,22 @@ describe('BundlesLayout', () => {
'root': {
'index.js': `
/**
* @providesModule index
* @providesModule xindex
*/
System.import("a");`,
${'System.import'}("xa");`,
'a.js': `
/**,
* @providesModule a
* @providesModule xa
*/,
System.import("b");`,
${'System.import'}("xb");`,
'b.js': `
/**
* @providesModule b
* @providesModule xb
*/
require("c");`,
require("xc");`,
'c.js': `
/**
* @providesModule c
* @providesModule xc
*/`,
}
});
Expand Down Expand Up @@ -382,12 +382,12 @@ describe('BundlesLayout', () => {
'root': {
'index.js': `
/**
* @providesModule index
* @providesModule xindex
*/
System.import("a");`,
${'System.import'}("xa");`,
'a.js':`
/**,
* @providesModule a
* @providesModule xa
*/,
require("./img.png");`,
'img.png': '',
Expand All @@ -414,18 +414,18 @@ describe('BundlesLayout', () => {
'root': {
'index.js': `
/**
* @providesModule index
* @providesModule xindex
*/
System.import("a");
System.import("b");`,
${'System.import'}("xa");
${'System.import'}("xb");`,
'a.js':`
/**,
* @providesModule a
* @providesModule xa
*/,
require("./img.png");`,
'b.js':`
/**,
* @providesModule b
* @providesModule xb
*/,
require("./img.png");`,
'img.png': '',
Expand Down Expand Up @@ -459,9 +459,9 @@ describe('BundlesLayout', () => {
'root': {
'index.js': `
/**
* @providesModule index
* @providesModule xindex
*/
System.import("./img.png");`,
${'System.import'}("./img.png");`,
'img.png': '',
}
});
Expand All @@ -486,12 +486,12 @@ describe('BundlesLayout', () => {
'root': {
'index.js': `
/**
* @providesModule index
* @providesModule xindex
*/
System.import("a");`,
${'System.import'}("xa");`,
'a.js':`
/**,
* @providesModule a
* @providesModule xa
*/,
require("image!img");`,
'img.png': '',
Expand All @@ -518,9 +518,9 @@ describe('BundlesLayout', () => {
'root': {
'index.js': `
/**
* @providesModule index
* @providesModule xindex
*/
System.import("image!img");`,
${'System.import'}("image!img");`,
'img.png': '',
}
});
Expand All @@ -545,9 +545,9 @@ describe('BundlesLayout', () => {
'root': {
'index.js': `
/**
* @providesModule index
* @providesModule xindex
*/
System.import("aPackage");`,
${'System.import'}("aPackage");`,
'aPackage': {
'package.json': JSON.stringify({
name: 'aPackage',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3934,7 +3934,7 @@ describe('DependencyGraph', function() {
'/**',
' * @providesModule index',
' */',
'System.import("a")',
'System.' + 'import("a")',
].join('\n'),
'a.js': [
'/**',
Expand Down
Loading

0 comments on commit b84ad2a

Please sign in to comment.