Simplify Jest config a little bit (#11242)

* Inline getTestDocument into test cases

* Remove mention of mock file we do not use

* Remove unused configuration entries

* Move eslint-rules package into the scripts/ folder
This commit is contained in:
Dan Abramov 2017-10-16 23:17:00 +01:00 committed by GitHub
parent 9ed78ad277
commit 49d4381c67
12 changed files with 50 additions and 65 deletions

View File

@ -50,7 +50,7 @@
"eslint-plugin-babel": "^3.3.0", "eslint-plugin-babel": "^3.3.0",
"eslint-plugin-flowtype": "^2.25.0", "eslint-plugin-flowtype": "^2.25.0",
"eslint-plugin-react": "^6.7.1", "eslint-plugin-react": "^6.7.1",
"eslint-plugin-react-internal": "file:./eslint-rules", "eslint-plugin-react-internal": "file:./scripts/eslint-rules",
"fbjs": "^0.8.16", "fbjs": "^0.8.16",
"fbjs-scripts": "^0.6.0", "fbjs-scripts": "^0.6.0",
"filesize": "^3.5.6", "filesize": "^3.5.6",
@ -110,8 +110,6 @@
}, },
"jest": { "jest": {
"modulePathIgnorePatterns": [ "modulePathIgnorePatterns": [
"/.module-cache/",
"<rootDir>/build/",
"<rootDir>/scripts/rollup/shims/", "<rootDir>/scripts/rollup/shims/",
"<rootDir>/scripts/bench/" "<rootDir>/scripts/bench/"
], ],
@ -132,16 +130,12 @@
"ts" "ts"
], ],
"roots": [ "roots": [
"<rootDir>/eslint-rules",
"<rootDir>/mocks", "<rootDir>/mocks",
"<rootDir>/scripts", "<rootDir>/scripts",
"<rootDir>/src", "<rootDir>/src"
"node_modules/fbjs"
], ],
"collectCoverageFrom": [ "collectCoverageFrom": [
"src/**/*.js", "src/**/*.js"
"!src/__mocks__/vendor/third_party/*.js",
"!src/test/*.js"
], ],
"timers": "fake" "timers": "fake"
} }

View File

@ -14,11 +14,7 @@ var RuleTester = require('eslint').RuleTester;
var ruleTester = new RuleTester(); var ruleTester = new RuleTester();
ruleTester.run('eslint-rules/no-primitive-constructors', rule, { ruleTester.run('eslint-rules/no-primitive-constructors', rule, {
valid: [ valid: ['!!obj', "'' + obj", '+string'],
'!!obj',
"'' + obj",
'+string',
],
invalid: [ invalid: [
{ {
code: 'Boolean(obj)', code: 'Boolean(obj)',
@ -32,10 +28,9 @@ ruleTester.run('eslint-rules/no-primitive-constructors', rule, {
code: 'String(obj)', code: 'String(obj)',
errors: [ errors: [
{ {
message: message: 'Do not use the String constructor. ' +
'Do not use the String constructor. ' +
'To cast a value to a string, concat it with the empty string ' + 'To cast a value to a string, concat it with the empty string ' +
'(unless it\'s a symbol, which has different semantics): \'\' + value', "(unless it's a symbol, which has different semantics): '' + value",
}, },
], ],
}, },

View File

@ -49,8 +49,7 @@ ruleTester.run('eslint-rules/warning-and-invariant-args', rule, {
code: "warning(true, 'expected %s, got %s');", code: "warning(true, 'expected %s, got %s');",
errors: [ errors: [
{ {
message: message: 'Expected 4 arguments in call to warning based on the number of ' +
'Expected 4 arguments in call to warning based on the number of ' +
'"%s" substitutions, but got 2', '"%s" substitutions, but got 2',
}, },
], ],
@ -59,8 +58,7 @@ ruleTester.run('eslint-rules/warning-and-invariant-args', rule, {
code: "warning(true, 'foo is a bar under foobar', 'junk argument');", code: "warning(true, 'foo is a bar under foobar', 'junk argument');",
errors: [ errors: [
{ {
message: message: 'Expected 2 arguments in call to warning based on the number of ' +
'Expected 2 arguments in call to warning based on the number of ' +
'"%s" substitutions, but got 3', '"%s" substitutions, but got 3',
}, },
], ],
@ -69,8 +67,7 @@ ruleTester.run('eslint-rules/warning-and-invariant-args', rule, {
code: "invariant(true, 'error!');", code: "invariant(true, 'error!');",
errors: [ errors: [
{ {
message: message: 'The invariant format should be able to uniquely identify this ' +
'The invariant format should be able to uniquely identify this ' +
'invariant. Please, use a more descriptive format than: error!', 'invariant. Please, use a more descriptive format than: error!',
}, },
], ],
@ -79,8 +76,7 @@ ruleTester.run('eslint-rules/warning-and-invariant-args', rule, {
code: "warning(true, 'error!');", code: "warning(true, 'error!');",
errors: [ errors: [
{ {
message: message: 'The warning format should be able to uniquely identify this ' +
'The warning format should be able to uniquely identify this ' +
'warning. Please, use a more descriptive format than: error!', 'warning. Please, use a more descriptive format than: error!',
}, },
], ],
@ -89,8 +85,7 @@ ruleTester.run('eslint-rules/warning-and-invariant-args', rule, {
code: "warning(true, '%s %s, %s %s: %s (%s)', 1, 2, 3, 4, 5, 6);", code: "warning(true, '%s %s, %s %s: %s (%s)', 1, 2, 3, 4, 5, 6);",
errors: [ errors: [
{ {
message: message: 'The warning format should be able to uniquely identify this ' +
'The warning format should be able to uniquely identify this ' +
'warning. Please, use a more descriptive format than: ' + 'warning. Please, use a more descriptive format than: ' +
'%s %s, %s %s: %s (%s)', '%s %s, %s %s: %s (%s)',
}, },

View File

@ -29,8 +29,8 @@ module.exports = function(context) {
node, node,
name, name,
'To cast a value to a string, concat it with the empty string ' + 'To cast a value to a string, concat it with the empty string ' +
'(unless it\'s a symbol, which has different semantics): ' + "(unless it's a symbol, which has different semantics): " +
'\'\' + value' "'' + value"
); );
break; break;
case 'Number': case 'Number':

View File

@ -40,11 +40,9 @@ module.exports = function(context) {
return; return;
} }
if (node.arguments.length < 2) { if (node.arguments.length < 2) {
context.report( context.report(node, '{{name}} takes at least two arguments', {
node, name: node.callee.name,
'{{name}} takes at least two arguments', });
{name: node.callee.name}
);
return; return;
} }
var format = getLiteralString(node.arguments[1]); var format = getLiteralString(node.arguments[1]);
@ -60,7 +58,7 @@ module.exports = function(context) {
context.report( context.report(
node, node,
'The {{name}} format should be able to uniquely identify this ' + 'The {{name}} format should be able to uniquely identify this ' +
'{{name}}. Please, use a more descriptive format than: {{format}}', '{{name}}. Please, use a more descriptive format than: {{format}}',
{name: node.callee.name, format: format} {name: node.callee.name, format: format}
); );
return; return;
@ -71,7 +69,7 @@ module.exports = function(context) {
context.report( context.report(
node, node,
'Expected {{expectedNArgs}} arguments in call to {{name}} based on ' + 'Expected {{expectedNArgs}} arguments in call to {{name}} based on ' +
'the number of "%s" substitutions, but got {{length}}', 'the number of "%s" substitutions, but got {{length}}',
{ {
expectedNArgs: expectedNArgs, expectedNArgs: expectedNArgs,
name: node.callee.name, name: node.callee.name,

View File

@ -13,7 +13,16 @@ var React;
var ReactDOM; var ReactDOM;
var ReactDOMServer; var ReactDOMServer;
var getTestDocument; function getTestDocument(markup) {
var doc = document.implementation.createHTMLDocument('');
doc.open();
doc.write(
markup ||
'<!doctype html><html><meta charset=utf-8><title>test doc</title>',
);
doc.close();
return doc;
}
describe('rendering React components at document', () => { describe('rendering React components at document', () => {
beforeEach(() => { beforeEach(() => {
@ -22,7 +31,6 @@ describe('rendering React components at document', () => {
React = require('react'); React = require('react');
ReactDOM = require('react-dom'); ReactDOM = require('react-dom');
ReactDOMServer = require('react-dom/server'); ReactDOMServer = require('react-dom/server');
getTestDocument = require('getTestDocument');
}); });
describe('with old implicit hydration API', () => { describe('with old implicit hydration API', () => {

View File

@ -9,8 +9,6 @@
'use strict'; 'use strict';
var getTestDocument = require('getTestDocument');
// TODO: can we express this test with only public API? // TODO: can we express this test with only public API?
var getNodeForCharacterOffset = require('getNodeForCharacterOffset'); var getNodeForCharacterOffset = require('getNodeForCharacterOffset');
@ -21,6 +19,17 @@ function createNode(html) {
return node; return node;
} }
function getTestDocument(markup) {
var doc = document.implementation.createHTMLDocument('');
doc.open();
doc.write(
markup ||
'<!doctype html><html><meta charset=utf-8><title>test doc</title>',
);
doc.close();
return doc;
}
// Check getNodeForCharacterOffset return value matches expected result. // Check getNodeForCharacterOffset return value matches expected result.
function expectNodeOffset(result, textContent, nodeOffset) { function expectNodeOffset(result, textContent, nodeOffset) {
expect(result.node.textContent).toBe(textContent); expect(result.node.textContent).toBe(textContent);

View File

@ -15,6 +15,17 @@ let ReactDOM;
let ReactDOMServer; let ReactDOMServer;
let ReactTestUtils; let ReactTestUtils;
function getTestDocument(markup) {
var doc = document.implementation.createHTMLDocument('');
doc.open();
doc.write(
markup ||
'<!doctype html><html><meta charset=utf-8><title>test doc</title>',
);
doc.close();
return doc;
}
describe('ReactTestUtils', () => { describe('ReactTestUtils', () => {
beforeEach(() => { beforeEach(() => {
createRenderer = require('react-test-renderer/shallow').createRenderer; createRenderer = require('react-test-renderer/shallow').createRenderer;
@ -131,8 +142,6 @@ describe('ReactTestUtils', () => {
}); });
it('should support injected wrapper components as DOM components', () => { it('should support injected wrapper components as DOM components', () => {
const getTestDocument = require('getTestDocument');
const injectedDOMComponents = [ const injectedDOMComponents = [
'button', 'button',
'form', 'form',

View File

@ -1,23 +0,0 @@
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @providesModule getTestDocument
*/
'use strict';
function getTestDocument(markup) {
var doc = document.implementation.createHTMLDocument('');
doc.open();
doc.write(
markup ||
'<!doctype html><html><meta charset=utf-8><title>test doc</title>',
);
doc.close();
return doc;
}
module.exports = getTestDocument;