Updates for haste2 inside of jest

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
This commit is contained in:
Christoph Pojer 2016-01-08 06:51:45 -08:00 коммит произвёл facebook-github-bot-5
Родитель 8ecd352bbf
Коммит b84ad2ab0d
10 изменённых файлов: 123 добавлений и 77 удалений

Просмотреть файл

@ -5,7 +5,6 @@
'use strict';
jest
.dontMock('Map')
.dontMock('NavigationTreeNode')
.dontMock('invariant')
.dontMock('immutable');

Просмотреть файл

@ -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;
@ -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);

Просмотреть файл

@ -16,3 +16,5 @@ global.__fbBatchedBridgeConfig = {
};
global.Promise = require('promise');
jest.setMock('ErrorUtils', require('ErrorUtils'));

Просмотреть файл

@ -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"
],

Просмотреть файл

@ -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[/\\].*/,

Просмотреть файл

@ -95,7 +95,7 @@ describe('BundlesLayout', () => {
'root': {
'index.js': `
/**
* @providesModule index
* @providesModule xindex
*/`,
}
});
@ -116,12 +116,12 @@ describe('BundlesLayout', () => {
'root': {
'index.js': `
/**
* @providesModule index
* @providesModule xindex
*/
require("a");`,
require("xa");`,
'a.js': `
/**
* @providesModule a
* @providesModule xa
*/`,
}
});
@ -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
*/`,
}
});
@ -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
*/`,
}
});
@ -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
*/`,
}
});
@ -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
*/`,
}
});
@ -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
*/`,
}
});
@ -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
*/`,
}
});
@ -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': '',
@ -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': '',
@ -459,9 +459,9 @@ describe('BundlesLayout', () => {
'root': {
'index.js': `
/**
* @providesModule index
* @providesModule xindex
*/
System.import("./img.png");`,
${'System.import'}("./img.png");`,
'img.png': '',
}
});
@ -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': '',
@ -518,9 +518,9 @@ describe('BundlesLayout', () => {
'root': {
'index.js': `
/**
* @providesModule index
* @providesModule xindex
*/
System.import("image!img");`,
${'System.import'}("image!img");`,
'img.png': '',
}
});
@ -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',

Просмотреть файл

@ -3934,7 +3934,7 @@ describe('DependencyGraph', function() {
'/**',
' * @providesModule index',
' */',
'System.import("a")',
'System.' + 'import("a")',
].join('\n'),
'a.js': [
'/**',

Просмотреть файл

@ -68,7 +68,7 @@ describe('Module', () => {
pit('should recognize single dependency', () => {
fs.__setMockFilesystem({
'root': {
'index.js': 'System.import("dep1")',
'index.js': 'System.' + 'import("dep1")',
},
});
@ -78,7 +78,7 @@ describe('Module', () => {
pit('should parse single quoted dependencies', () => {
fs.__setMockFilesystem({
'root': {
'index.js': 'System.import(\'dep1\')',
'index.js': 'System.' + 'import(\'dep1\')',
},
});
@ -89,8 +89,8 @@ describe('Module', () => {
fs.__setMockFilesystem({
'root': {
'index.js': [
'System.import("dep1")',
'System.import("dep2")',
'System.' + 'import("dep1")',
'System.' + 'import("dep2")',
].join('\n'),
},
});
@ -104,7 +104,7 @@ describe('Module', () => {
pit('parse fine new lines', () => {
fs.__setMockFilesystem({
'root': {
'index.js': 'System.import(\n"dep1"\n)',
'index.js': 'System.' + 'import(\n"dep1"\n)',
},
});

Просмотреть файл

@ -14,17 +14,17 @@ const BundlesLayout = require('../../../BundlesLayout');
const testData = {
isolated: {
input: 'System.import("moduleA");',
input: 'System.' + 'import("moduleA");',
output: 'loadBundles(["bundle.0"]);'
},
single: {
input: 'System.import("moduleA").then(function (bundleA) {});',
input: 'System.' + 'import("moduleA").then(function (bundleA) {});',
output: 'loadBundles(["bundle.0"]).then(function (bundleA) {});'
},
multiple: {
input: [
'Promise.all([',
'System.import("moduleA"), System.import("moduleB"),',
'System.' + 'import("moduleA"), System.' + 'import("moduleB"),',
']).then(function (bundlesA, bundlesB) {});',
].join('\n'),
output: [