@samitouri / QOS-React-2 / commits / 49d4381c67

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

Dan Abramov committed Oct 16, 2017 at 23:17 UTC 49d4381c677cc33b93382611168a140af38a1df9
12 files changed +50 -65
package.json
+3 -9
@@ -50,7 +50,7 @@
50 "eslint-plugin-babel": "^3.3.0",
51 "eslint-plugin-flowtype": "^2.25.0",
52 "eslint-plugin-react": "^6.7.1",
53 - "eslint-plugin-react-internal": "file:./eslint-rules",
53 + "eslint-plugin-react-internal": "file:./scripts/eslint-rules",
54 "fbjs": "^0.8.16",
55 "fbjs-scripts": "^0.6.0",
56 "filesize": "^3.5.6",
@@ -110,8 +110,6 @@
110 },
111 "jest": {
112 "modulePathIgnorePatterns": [
113 - "/.module-cache/",
114 - "<rootDir>/build/",
113 "<rootDir>/scripts/rollup/shims/",
114 "<rootDir>/scripts/bench/"
115 ],
@@ -132,16 +130,12 @@
130 "ts"
131 ],
132 "roots": [
135 - "<rootDir>/eslint-rules",
133 "<rootDir>/mocks",
134 "<rootDir>/scripts",
138 - "<rootDir>/src",
139 - "node_modules/fbjs"
135 + "<rootDir>/src"
136 ],
137 "collectCoverageFrom": [
142 - "src/**/*.js",
143 - "!src/__mocks__/vendor/third_party/*.js",
144 - "!src/test/*.js"
138 + "src/**/*.js"
139 ],
140 "timers": "fake"
141 }
scripts/eslint-rules/README.md renamed
scripts/eslint-rules/__tests__/no-primitive-constructors-test.js renamed
+3 -8
@@ -14,11 +14,7 @@ var RuleTester = require('eslint').RuleTester;
14 var ruleTester = new RuleTester();
15
16 ruleTester.run('eslint-rules/no-primitive-constructors', rule, {
17 - valid: [
18 - '!!obj',
19 - "'' + obj",
20 - '+string',
21 - ],
17 + valid: ['!!obj', "'' + obj", '+string'],
18 invalid: [
19 {
20 code: 'Boolean(obj)',
@@ -32,10 +28,9 @@ ruleTester.run('eslint-rules/no-primitive-constructors', rule, {
28 code: 'String(obj)',
29 errors: [
30 {
35 - message:
36 - 'Do not use the String constructor. ' +
31 + message: 'Do not use the String constructor. ' +
32 'To cast a value to a string, concat it with the empty string ' +
38 - '(unless it\'s a symbol, which has different semantics): \'\' + value',
33 + "(unless it's a symbol, which has different semantics): '' + value",
34 },
35 ],
36 },
scripts/eslint-rules/__tests__/warning-and-invariant-args-test.js renamed
+5 -10
@@ -49,8 +49,7 @@ ruleTester.run('eslint-rules/warning-and-invariant-args', rule, {
49 code: "warning(true, 'expected %s, got %s');",
50 errors: [
51 {
52 - message:
53 - 'Expected 4 arguments in call to warning based on the number of ' +
52 + message: 'Expected 4 arguments in call to warning based on the number of ' +
53 '"%s" substitutions, but got 2',
54 },
55 ],
@@ -59,8 +58,7 @@ ruleTester.run('eslint-rules/warning-and-invariant-args', rule, {
58 code: "warning(true, 'foo is a bar under foobar', 'junk argument');",
59 errors: [
60 {
62 - message:
63 - 'Expected 2 arguments in call to warning based on the number of ' +
61 + message: 'Expected 2 arguments in call to warning based on the number of ' +
62 '"%s" substitutions, but got 3',
63 },
64 ],
@@ -69,8 +67,7 @@ ruleTester.run('eslint-rules/warning-and-invariant-args', rule, {
67 code: "invariant(true, 'error!');",
68 errors: [
69 {
72 - message:
73 - 'The invariant format should be able to uniquely identify this ' +
70 + message: 'The invariant format should be able to uniquely identify this ' +
71 'invariant. Please, use a more descriptive format than: error!',
72 },
73 ],
@@ -79,8 +76,7 @@ ruleTester.run('eslint-rules/warning-and-invariant-args', rule, {
76 code: "warning(true, 'error!');",
77 errors: [
78 {
82 - message:
83 - 'The warning format should be able to uniquely identify this ' +
79 + message: 'The warning format should be able to uniquely identify this ' +
80 'warning. Please, use a more descriptive format than: error!',
81 },
82 ],
@@ -89,8 +85,7 @@ ruleTester.run('eslint-rules/warning-and-invariant-args', rule, {
85 code: "warning(true, '%s %s, %s %s: %s (%s)', 1, 2, 3, 4, 5, 6);",
86 errors: [
87 {
92 - message:
93 - 'The warning format should be able to uniquely identify this ' +
88 + message: 'The warning format should be able to uniquely identify this ' +
89 'warning. Please, use a more descriptive format than: ' +
90 '%s %s, %s %s: %s (%s)',
91 },
scripts/eslint-rules/index.js renamed
scripts/eslint-rules/no-primitive-constructors.js renamed
+2 -2
@@ -29,8 +29,8 @@ module.exports = function(context) {
29 node,
30 name,
31 'To cast a value to a string, concat it with the empty string ' +
32 - '(unless it\'s a symbol, which has different semantics): ' +
33 - '\'\' + value'
32 + "(unless it's a symbol, which has different semantics): " +
33 + "'' + value"
34 );
35 break;
36 case 'Number':
scripts/eslint-rules/package.json renamed
scripts/eslint-rules/warning-and-invariant-args.js renamed
+5 -7
@@ -40,11 +40,9 @@ module.exports = function(context) {
40 return;
41 }
42 if (node.arguments.length < 2) {
43 - context.report(
44 - node,
45 - '{{name}} takes at least two arguments',
46 - {name: node.callee.name}
47 - );
43 + context.report(node, '{{name}} takes at least two arguments', {
44 + name: node.callee.name,
45 + });
46 return;
47 }
48 var format = getLiteralString(node.arguments[1]);
@@ -60,7 +58,7 @@ module.exports = function(context) {
58 context.report(
59 node,
60 'The {{name}} format should be able to uniquely identify this ' +
63 - '{{name}}. Please, use a more descriptive format than: {{format}}',
61 + '{{name}}. Please, use a more descriptive format than: {{format}}',
62 {name: node.callee.name, format: format}
63 );
64 return;
@@ -71,7 +69,7 @@ module.exports = function(context) {
69 context.report(
70 node,
71 'Expected {{expectedNArgs}} arguments in call to {{name}} based on ' +
74 - 'the number of "%s" substitutions, but got {{length}}',
72 + 'the number of "%s" substitutions, but got {{length}}',
73 {
74 expectedNArgs: expectedNArgs,
75 name: node.callee.name,
src/renderers/dom/shared/__tests__/ReactRenderDocument-test.js
+10 -2
@@ -13,7 +13,16 @@ var React;
13 var ReactDOM;
14 var ReactDOMServer;
15
16 -var getTestDocument;
16 +function getTestDocument(markup) {
17 + var doc = document.implementation.createHTMLDocument('');
18 + doc.open();
19 + doc.write(
20 + markup ||
21 + '<!doctype html><html><meta charset=utf-8><title>test doc</title>',
22 + );
23 + doc.close();
24 + return doc;
25 +}
26
27 describe('rendering React components at document', () => {
28 beforeEach(() => {
@@ -22,7 +31,6 @@ describe('rendering React components at document', () => {
31 React = require('react');
32 ReactDOM = require('react-dom');
33 ReactDOMServer = require('react-dom/server');
25 - getTestDocument = require('getTestDocument');
34 });
35
36 describe('with old implicit hydration API', () => {
src/renderers/dom/shared/utils/__tests__/getNodeForCharacterOffset-test.js
+11 -2
@@ -9,8 +9,6 @@
9
10 'use strict';
11
12 -var getTestDocument = require('getTestDocument');
13 -
12 // TODO: can we express this test with only public API?
13 var getNodeForCharacterOffset = require('getNodeForCharacterOffset');
14
@@ -21,6 +19,17 @@ function createNode(html) {
19 return node;
20 }
21
22 +function getTestDocument(markup) {
23 + var doc = document.implementation.createHTMLDocument('');
24 + doc.open();
25 + doc.write(
26 + markup ||
27 + '<!doctype html><html><meta charset=utf-8><title>test doc</title>',
28 + );
29 + doc.close();
30 + return doc;
31 +}
32 +
33 // Check getNodeForCharacterOffset return value matches expected result.
34 function expectNodeOffset(result, textContent, nodeOffset) {
35 expect(result.node.textContent).toBe(textContent);
src/renderers/dom/test/__tests__/ReactTestUtils-test.js
+11 -2
@@ -15,6 +15,17 @@ let ReactDOM;
15 let ReactDOMServer;
16 let ReactTestUtils;
17
18 +function getTestDocument(markup) {
19 + var doc = document.implementation.createHTMLDocument('');
20 + doc.open();
21 + doc.write(
22 + markup ||
23 + '<!doctype html><html><meta charset=utf-8><title>test doc</title>',
24 + );
25 + doc.close();
26 + return doc;
27 +}
28 +
29 describe('ReactTestUtils', () => {
30 beforeEach(() => {
31 createRenderer = require('react-test-renderer/shallow').createRenderer;
@@ -131,8 +142,6 @@ describe('ReactTestUtils', () => {
142 });
143
144 it('should support injected wrapper components as DOM components', () => {
134 - const getTestDocument = require('getTestDocument');
135 -
145 const injectedDOMComponents = [
146 'button',
147 'form',
src/test/getTestDocument.js deleted
-23
@@ -1,23 +0,0 @@
1 -/**
2 - * Copyright (c) 2013-present, Facebook, Inc.
3 - *
4 - * This source code is licensed under the MIT license found in the
5 - * LICENSE file in the root directory of this source tree.
6 - *
7 - * @providesModule getTestDocument
8 - */
9 -
10 -'use strict';
11 -
12 -function getTestDocument(markup) {
13 - var doc = document.implementation.createHTMLDocument('');
14 - doc.open();
15 - doc.write(
16 - markup ||
17 - '<!doctype html><html><meta charset=utf-8><title>test doc</title>',
18 - );
19 - doc.close();
20 - return doc;
21 -}
22 -
23 -module.exports = getTestDocument;