From 49d4381c677cc33b93382611168a140af38a1df9 Mon Sep 17 00:00:00 2001 From: Dan Abramov Date: Mon, 16 Oct 2017 23:17:00 +0100 Subject: [PATCH] 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 --- package.json | 12 +++------- .../eslint-rules}/README.md | 0 .../no-primitive-constructors-test.js | 11 +++------ .../warning-and-invariant-args-test.js | 15 ++++-------- .../eslint-rules}/index.js | 0 .../no-primitive-constructors.js | 4 ++-- .../eslint-rules}/package.json | 0 .../warning-and-invariant-args.js | 12 ++++------ .../__tests__/ReactRenderDocument-test.js | 12 ++++++++-- .../getNodeForCharacterOffset-test.js | 13 +++++++++-- .../dom/test/__tests__/ReactTestUtils-test.js | 13 +++++++++-- src/test/getTestDocument.js | 23 ------------------- 12 files changed, 50 insertions(+), 65 deletions(-) rename {eslint-rules => scripts/eslint-rules}/README.md (100%) rename {eslint-rules => scripts/eslint-rules}/__tests__/no-primitive-constructors-test.js (82%) rename {eslint-rules => scripts/eslint-rules}/__tests__/warning-and-invariant-args-test.js (81%) rename {eslint-rules => scripts/eslint-rules}/index.js (100%) rename {eslint-rules => scripts/eslint-rules}/no-primitive-constructors.js (91%) rename {eslint-rules => scripts/eslint-rules}/package.json (100%) rename {eslint-rules => scripts/eslint-rules}/warning-and-invariant-args.js (89%) delete mode 100644 src/test/getTestDocument.js diff --git a/package.json b/package.json index 525a7d3eb4..2847614f37 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "eslint-plugin-babel": "^3.3.0", "eslint-plugin-flowtype": "^2.25.0", "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-scripts": "^0.6.0", "filesize": "^3.5.6", @@ -110,8 +110,6 @@ }, "jest": { "modulePathIgnorePatterns": [ - "/.module-cache/", - "/build/", "/scripts/rollup/shims/", "/scripts/bench/" ], @@ -132,16 +130,12 @@ "ts" ], "roots": [ - "/eslint-rules", "/mocks", "/scripts", - "/src", - "node_modules/fbjs" + "/src" ], "collectCoverageFrom": [ - "src/**/*.js", - "!src/__mocks__/vendor/third_party/*.js", - "!src/test/*.js" + "src/**/*.js" ], "timers": "fake" } diff --git a/eslint-rules/README.md b/scripts/eslint-rules/README.md similarity index 100% rename from eslint-rules/README.md rename to scripts/eslint-rules/README.md diff --git a/eslint-rules/__tests__/no-primitive-constructors-test.js b/scripts/eslint-rules/__tests__/no-primitive-constructors-test.js similarity index 82% rename from eslint-rules/__tests__/no-primitive-constructors-test.js rename to scripts/eslint-rules/__tests__/no-primitive-constructors-test.js index aa74fa8ad6..1437cbe055 100644 --- a/eslint-rules/__tests__/no-primitive-constructors-test.js +++ b/scripts/eslint-rules/__tests__/no-primitive-constructors-test.js @@ -14,11 +14,7 @@ var RuleTester = require('eslint').RuleTester; var ruleTester = new RuleTester(); ruleTester.run('eslint-rules/no-primitive-constructors', rule, { - valid: [ - '!!obj', - "'' + obj", - '+string', - ], + valid: ['!!obj', "'' + obj", '+string'], invalid: [ { code: 'Boolean(obj)', @@ -32,10 +28,9 @@ ruleTester.run('eslint-rules/no-primitive-constructors', rule, { code: 'String(obj)', errors: [ { - message: - 'Do not use the String constructor. ' + + message: 'Do not use the String constructor. ' + '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", }, ], }, diff --git a/eslint-rules/__tests__/warning-and-invariant-args-test.js b/scripts/eslint-rules/__tests__/warning-and-invariant-args-test.js similarity index 81% rename from eslint-rules/__tests__/warning-and-invariant-args-test.js rename to scripts/eslint-rules/__tests__/warning-and-invariant-args-test.js index 7e6b63942f..d4540ed68f 100644 --- a/eslint-rules/__tests__/warning-and-invariant-args-test.js +++ b/scripts/eslint-rules/__tests__/warning-and-invariant-args-test.js @@ -49,8 +49,7 @@ ruleTester.run('eslint-rules/warning-and-invariant-args', rule, { code: "warning(true, 'expected %s, got %s');", errors: [ { - message: - 'Expected 4 arguments in call to warning based on the number of ' + + message: 'Expected 4 arguments in call to warning based on the number of ' + '"%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');", errors: [ { - message: - 'Expected 2 arguments in call to warning based on the number of ' + + message: 'Expected 2 arguments in call to warning based on the number of ' + '"%s" substitutions, but got 3', }, ], @@ -69,8 +67,7 @@ ruleTester.run('eslint-rules/warning-and-invariant-args', rule, { code: "invariant(true, 'error!');", errors: [ { - message: - 'The invariant format should be able to uniquely identify this ' + + message: 'The invariant format should be able to uniquely identify this ' + '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!');", errors: [ { - message: - 'The warning format should be able to uniquely identify this ' + + message: 'The warning format should be able to uniquely identify this ' + '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);", errors: [ { - message: - 'The warning format should be able to uniquely identify this ' + + message: 'The warning format should be able to uniquely identify this ' + 'warning. Please, use a more descriptive format than: ' + '%s %s, %s %s: %s (%s)', }, diff --git a/eslint-rules/index.js b/scripts/eslint-rules/index.js similarity index 100% rename from eslint-rules/index.js rename to scripts/eslint-rules/index.js diff --git a/eslint-rules/no-primitive-constructors.js b/scripts/eslint-rules/no-primitive-constructors.js similarity index 91% rename from eslint-rules/no-primitive-constructors.js rename to scripts/eslint-rules/no-primitive-constructors.js index d02182f6cb..89c7264d56 100644 --- a/eslint-rules/no-primitive-constructors.js +++ b/scripts/eslint-rules/no-primitive-constructors.js @@ -29,8 +29,8 @@ module.exports = function(context) { node, name, '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" ); break; case 'Number': diff --git a/eslint-rules/package.json b/scripts/eslint-rules/package.json similarity index 100% rename from eslint-rules/package.json rename to scripts/eslint-rules/package.json diff --git a/eslint-rules/warning-and-invariant-args.js b/scripts/eslint-rules/warning-and-invariant-args.js similarity index 89% rename from eslint-rules/warning-and-invariant-args.js rename to scripts/eslint-rules/warning-and-invariant-args.js index ac72bc9a19..e5540be816 100644 --- a/eslint-rules/warning-and-invariant-args.js +++ b/scripts/eslint-rules/warning-and-invariant-args.js @@ -40,11 +40,9 @@ module.exports = function(context) { return; } if (node.arguments.length < 2) { - context.report( - node, - '{{name}} takes at least two arguments', - {name: node.callee.name} - ); + context.report(node, '{{name}} takes at least two arguments', { + name: node.callee.name, + }); return; } var format = getLiteralString(node.arguments[1]); @@ -60,7 +58,7 @@ module.exports = function(context) { context.report( node, '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} ); return; @@ -71,7 +69,7 @@ module.exports = function(context) { context.report( node, '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, name: node.callee.name, diff --git a/src/renderers/dom/shared/__tests__/ReactRenderDocument-test.js b/src/renderers/dom/shared/__tests__/ReactRenderDocument-test.js index 1c86f2b548..4a5f463dea 100644 --- a/src/renderers/dom/shared/__tests__/ReactRenderDocument-test.js +++ b/src/renderers/dom/shared/__tests__/ReactRenderDocument-test.js @@ -13,7 +13,16 @@ var React; var ReactDOM; var ReactDOMServer; -var getTestDocument; +function getTestDocument(markup) { + var doc = document.implementation.createHTMLDocument(''); + doc.open(); + doc.write( + markup || + 'test doc', + ); + doc.close(); + return doc; +} describe('rendering React components at document', () => { beforeEach(() => { @@ -22,7 +31,6 @@ describe('rendering React components at document', () => { React = require('react'); ReactDOM = require('react-dom'); ReactDOMServer = require('react-dom/server'); - getTestDocument = require('getTestDocument'); }); describe('with old implicit hydration API', () => { diff --git a/src/renderers/dom/shared/utils/__tests__/getNodeForCharacterOffset-test.js b/src/renderers/dom/shared/utils/__tests__/getNodeForCharacterOffset-test.js index 5c391aa5fc..534d6442e6 100644 --- a/src/renderers/dom/shared/utils/__tests__/getNodeForCharacterOffset-test.js +++ b/src/renderers/dom/shared/utils/__tests__/getNodeForCharacterOffset-test.js @@ -9,8 +9,6 @@ 'use strict'; -var getTestDocument = require('getTestDocument'); - // TODO: can we express this test with only public API? var getNodeForCharacterOffset = require('getNodeForCharacterOffset'); @@ -21,6 +19,17 @@ function createNode(html) { return node; } +function getTestDocument(markup) { + var doc = document.implementation.createHTMLDocument(''); + doc.open(); + doc.write( + markup || + 'test doc', + ); + doc.close(); + return doc; +} + // Check getNodeForCharacterOffset return value matches expected result. function expectNodeOffset(result, textContent, nodeOffset) { expect(result.node.textContent).toBe(textContent); diff --git a/src/renderers/dom/test/__tests__/ReactTestUtils-test.js b/src/renderers/dom/test/__tests__/ReactTestUtils-test.js index 1905dca59f..63ea448508 100644 --- a/src/renderers/dom/test/__tests__/ReactTestUtils-test.js +++ b/src/renderers/dom/test/__tests__/ReactTestUtils-test.js @@ -15,6 +15,17 @@ let ReactDOM; let ReactDOMServer; let ReactTestUtils; +function getTestDocument(markup) { + var doc = document.implementation.createHTMLDocument(''); + doc.open(); + doc.write( + markup || + 'test doc', + ); + doc.close(); + return doc; +} + describe('ReactTestUtils', () => { beforeEach(() => { createRenderer = require('react-test-renderer/shallow').createRenderer; @@ -131,8 +142,6 @@ describe('ReactTestUtils', () => { }); it('should support injected wrapper components as DOM components', () => { - const getTestDocument = require('getTestDocument'); - const injectedDOMComponents = [ 'button', 'form', diff --git a/src/test/getTestDocument.js b/src/test/getTestDocument.js deleted file mode 100644 index b39edfdb95..0000000000 --- a/src/test/getTestDocument.js +++ /dev/null @@ -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 || - 'test doc', - ); - doc.close(); - return doc; -} - -module.exports = getTestDocument;