Update to jest 15 #7625

Merged
merged 1 commit into from Sep 1, 2016
Jump to file or symbol
Failed to load files and symbols.
+28 −71
Diff settings

Always

Just for now

View
@@ -58,7 +58,7 @@
"gulp-load-plugins": "^1.2.4",
"gulp-util": "^3.0.7",
"gzip-js": "~0.3.2",
- "jest": "^12.1.1",
+ "jest": "^15.0.1",
"loose-envify": "^1.1.0",
"merge-stream": "^1.0.0",
"object-assign": "^4.1.0",
@@ -90,14 +90,18 @@
"/.module-cache/",
"/react/build/"
],
- "persistModuleRegistryBetweenSpecs": true,

This comment has been minimized.

@vjeux

vjeux Aug 31, 2016

Contributor

Jest upgrade path was so good. For each option that was deprecated, there was a big blob of text saying why and what was the new one I needed to use.

screen shot 2016-08-31 at 3 37 51 pm

@vjeux

vjeux Aug 31, 2016

Contributor

Jest upgrade path was so good. For each option that was deprecated, there was a big blob of text saying why and what was the new one I needed to use.

screen shot 2016-08-31 at 3 37 51 pm

"rootDir": "",
"scriptPreprocessor": "scripts/jest/preprocessor.js",
- "setupEnvScriptFile": "scripts/jest/environment.js",
+ "setupFiles": [
+ "scripts/jest/environment.js"
+ ],
"setupTestFrameworkScriptFile": "scripts/jest/test-framework-setup.js",
- "testFileExtensions": [
- "coffee",
+ "testRegex": "/__tests__/",
+ "moduleFileExtensions": [
"js",
+ "json",
+ "node",
+ "coffee",
"ts"
],
"testPathDirs": [
@@ -107,8 +111,6 @@
"<rootDir>/src",
"node_modules/fbjs"
],
- "unmockedModulePathPatterns": [
- ""
- ]
+ "timers": "fake"
}
}
@@ -32,7 +32,11 @@ describe('ReactClassEquivalence', function() {
function runJest(testFile) {
var cwd = process.cwd();
var jestBin = path.resolve('node_modules', '.bin', 'jest');
- var setupFile = path.resolve(__dirname, 'setupSpecEquivalenceReporter.js');
+ var setupFile = path.resolve(
+ 'scripts',
+ 'jest',
+ 'setupSpecEquivalenceReporter.js'
+ );
var result = spawnSync('node', [
jestBin,
testFile,
@@ -60,7 +64,7 @@ function runJest(testFile) {
}
function compareResults(a, b) {
- var regexp = /^EQUIVALENCE.*$/gm;
+ var regexp = /EQUIVALENCE.*$/gm;
var aSpecs = (a.match(regexp) || []).sort().join('\n');
var bSpecs = (b.match(regexp) || []).sort().join('\n');
@@ -1,18 +0,0 @@
-/**
- * Copyright 2014-present, Facebook, Inc.
- * All rights reserved.
- *
- * This source code is licensed under the BSD-style license found in the
- * LICENSE file in the root directory of this source tree. An additional grant
- * of patent rights can be found in the PATENTS file in the same directory.
- *
- * @emails react-core
- */
-
-'use strict';
-
-describe('ReactFlowPropTypes', function() {
-
- // TODO: Test Flow integration and ensure that prop types works.

This comment has been minimized.

@vjeux

vjeux Aug 31, 2016

Contributor

Jest now marks test files with no assertions as failing. I also really dislike having dead code in the codebase. If we are going to test proptypes with flow one day, we'll recreate this file.

@vjeux

vjeux Aug 31, 2016

Contributor

Jest now marks test files with no assertions as failing. I also really dislike having dead code in the codebase. If we are going to test proptypes with flow one day, we'll recreate this file.

-
-});
@@ -1,18 +0,0 @@
-/**
- * Copyright 2014-present, Facebook, Inc.
- * All rights reserved.
- *
- * This source code is licensed under the BSD-style license found in the
- * LICENSE file in the root directory of this source tree. An additional grant
- * of patent rights can be found in the PATENTS file in the same directory.
- *
- * @emails react-core
- */
-
-'use strict';
-
-describe('ReactTypeScriptPropTypes', function() {
-
- // TODO: Test TypeScript integration and ensure that prop types works.
-
-});
@@ -13,9 +13,6 @@
'use strict';
-jest
- .unmock('ReactART');

This comment has been minimized.

@vjeux

vjeux Aug 31, 2016

Contributor

We manually call unmock on a bunch of file even though automocking is off for the repo. There's now a warning in Jest for that :)

@vjeux

vjeux Aug 31, 2016

Contributor

We manually call unmock on a bunch of file even though automocking is off for the repo. There's now a warning in Jest for that :)

This comment has been minimized.

@zpao

zpao Aug 31, 2016

Member

FWIW These files were copied directly from another repo (where they are mostly copied from www). I don't think we can remove that line internally so we'll have to have it in some copies.

It's ok to diverge a tiny bit in this part but if we ever make changes to the actual tests, let's make sure those propagate.

@zpao

zpao Aug 31, 2016

Member

FWIW These files were copied directly from another repo (where they are mostly copied from www). I don't think we can remove that line internally so we'll have to have it in some copies.

It's ok to diverge a tiny bit in this part but if we ever make changes to the actual tests, let's make sure those propagate.

This comment has been minimized.

@cpojer

cpojer Aug 31, 2016

Contributor

art is unmocked by default on www, so this should be fine.

@cpojer

cpojer Aug 31, 2016

Contributor

art is unmocked by default on www, so this should be fine.

-
var React = require('React');
var ReactDOM = require('ReactDOM');
var ReactTestUtils = require('ReactTestUtils');
@@ -45,33 +45,33 @@ describe('ReactServerRendering', function() {
var response = ReactServerRendering.renderToString(
<span>hello world</span>
);
- expect(response).toMatch(
+ expect(response).toMatch(new RegExp(

This comment has been minimized.

@vjeux

vjeux Aug 31, 2016

Contributor

toMatch used to silently convert the string into a RegExp and no longer does it. Replacing the few call sites we had to match the new behavior. It's IMO a good thing to have to pass a RegExp to toMatch :)

@vjeux

vjeux Aug 31, 2016

Contributor

toMatch used to silently convert the string into a RegExp and no longer does it. Replacing the few call sites we had to match the new behavior. It's IMO a good thing to have to pass a RegExp to toMatch :)

'<span ' + ROOT_ATTRIBUTE_NAME + '="" ' +
ID_ATTRIBUTE_NAME + '="[^"]+" ' +
ReactMarkupChecksum.CHECKSUM_ATTR_NAME + '="[^"]+">hello world</span>'
- );
+ ));
});
it('should generate simple markup for self-closing tags', function() {
var response = ReactServerRendering.renderToString(
<img />
);
- expect(response).toMatch(
+ expect(response).toMatch(new RegExp(
'<img ' + ROOT_ATTRIBUTE_NAME + '="" ' +
ID_ATTRIBUTE_NAME + '="[^"]+" ' +
ReactMarkupChecksum.CHECKSUM_ATTR_NAME + '="[^"]+"/>'
- );
+ ));
});
it('should generate simple markup for attribute with `>` symbol', function() {
var response = ReactServerRendering.renderToString(
<img data-attr=">" />
);
- expect(response).toMatch(
+ expect(response).toMatch(new RegExp(
'<img data-attr="&gt;" ' + ROOT_ATTRIBUTE_NAME + '="" ' +
ID_ATTRIBUTE_NAME + '="[^"]+" ' +
ReactMarkupChecksum.CHECKSUM_ATTR_NAME + '="[^"]+"/>'
- );
+ ));
});
it('should generate comment markup for component returns null', function() {
@@ -111,7 +111,7 @@ describe('ReactServerRendering', function() {
var response = ReactServerRendering.renderToString(
<Parent />
);
- expect(response).toMatch(
+ expect(response).toMatch(new RegExp(
'<div ' + ROOT_ATTRIBUTE_NAME + '="" ' +
ID_ATTRIBUTE_NAME + '="[^"]+" ' +
ReactMarkupChecksum.CHECKSUM_ATTR_NAME + '="[^"]+">' +
@@ -120,7 +120,7 @@ describe('ReactServerRendering', function() {
'<!-- react-text: [0-9]+ -->child<!-- /react-text -->' +
'</span>' +
'</div>'
- );
+ ));
});
it('should only execute certain lifecycle methods', function() {
@@ -172,14 +172,14 @@ describe('ReactServerRendering', function() {
<TestComponent />
);
- expect(response).toMatch(
+ expect(response).toMatch(new RegExp(
'<span ' + ROOT_ATTRIBUTE_NAME + '="" ' +
ID_ATTRIBUTE_NAME + '="[^"]+" ' +
ReactMarkupChecksum.CHECKSUM_ATTR_NAME + '="[^"]+">' +
'<!-- react-text: [0-9]+ -->Component name: <!-- /react-text -->' +
'<!-- react-text: [0-9]+ -->TestComponent<!-- /react-text -->' +
'</span>'
- );
+ ));
expect(lifecycle).toEqual(
['getInitialState', 'componentWillMount', 'render']
);
@@ -9,11 +9,6 @@
*/
'use strict';
-jest.unmock('ReactNativeAttributePayload');
-jest.unmock('ReactNativePropRegistry');
-// jest.dontMock('deepDiffer');
-// jest.dontMock('flattenStyle');
-
var ReactNativeAttributePayload = require('ReactNativeAttributePayload');
var ReactNativePropRegistry = require('ReactNativePropRegistry');
@@ -11,9 +11,7 @@
'use strict';
-jest
- .unmock('EventPluginHub')
- .mock('isEventSupported');
+jest.mock('isEventSupported');
describe('EventPluginHub', function() {
var EventPluginHub;
@@ -60,7 +60,7 @@ var expectChildren = function(d, children) {
openingCommentNode = outerNode.childNodes[mountIndex];
expect(openingCommentNode.nodeType).toBe(8);
- expect(openingCommentNode.nodeValue).toMatch(' react-text: [0-9]+ ');
+ expect(openingCommentNode.nodeValue).toMatch(/ react-text: [0-9]+ /);
if (child === '') {
textNode = null;
@@ -11,9 +11,6 @@
'use strict';
-jest
- .unmock('accumulateInto');
-
var accumulateInto;
describe('accumulateInto', function() {