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:
parent
9ed78ad277
commit
49d4381c67
12
package.json
12
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/",
|
||||
"<rootDir>/build/",
|
||||
"<rootDir>/scripts/rollup/shims/",
|
||||
"<rootDir>/scripts/bench/"
|
||||
],
|
||||
|
@ -132,16 +130,12 @@
|
|||
"ts"
|
||||
],
|
||||
"roots": [
|
||||
"<rootDir>/eslint-rules",
|
||||
"<rootDir>/mocks",
|
||||
"<rootDir>/scripts",
|
||||
"<rootDir>/src",
|
||||
"node_modules/fbjs"
|
||||
"<rootDir>/src"
|
||||
],
|
||||
"collectCoverageFrom": [
|
||||
"src/**/*.js",
|
||||
"!src/__mocks__/vendor/third_party/*.js",
|
||||
"!src/test/*.js"
|
||||
"src/**/*.js"
|
||||
],
|
||||
"timers": "fake"
|
||||
}
|
||||
|
|
|
@ -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",
|
||||
},
|
||||
],
|
||||
},
|
|
@ -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)',
|
||||
},
|
|
@ -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':
|
|
@ -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,
|
|
@ -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 ||
|
||||
'<!doctype html><html><meta charset=utf-8><title>test doc</title>',
|
||||
);
|
||||
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', () => {
|
||||
|
|
|
@ -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 ||
|
||||
'<!doctype html><html><meta charset=utf-8><title>test doc</title>',
|
||||
);
|
||||
doc.close();
|
||||
return doc;
|
||||
}
|
||||
|
||||
// Check getNodeForCharacterOffset return value matches expected result.
|
||||
function expectNodeOffset(result, textContent, nodeOffset) {
|
||||
expect(result.node.textContent).toBe(textContent);
|
||||
|
|
|
@ -15,6 +15,17 @@ let ReactDOM;
|
|||
let ReactDOMServer;
|
||||
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', () => {
|
||||
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',
|
||||
|
|
|
@ -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;
|
Loading…
Reference in New Issue