prepack/test/react/FunctionalComponents-test.js
Dan Abramov 5159b0d832 Make React tests fast (#2187)
Summary:
Currently we have a single giant file with all tests, and a giant snapshot. This is both slow, and hard to work with and iterate on.

In this PR I will refactor our test setup.

- [x] Split it up into multiple files (gets the test running from 45s to 27s)
- [x] Run Prettier on test files
- [x] Split tests further for better performance
- [x] Make it possible to run one test file
- [x] Fix the issue with double test re-runs in watch mode on changes in the test file
- [x] Refactor error handling
- [x] Run Prettier on fixtures
- [x] Add a fast mode with `yarn test-react-fast <Filename>`
- [x] Fix double reruns on failure

Potential followups:
- [x] Figure out why test interruption broke (need https://github.com/facebook/jest/issues/6599 and https://github.com/facebook/jest/issues/6598 fixed)
- [x] Revisit weird things like `this['React']` assignment with a funny comment in every test
Closes https://github.com/facebook/prepack/pull/2187

Differential Revision: D8713639

Pulled By: gaearon

fbshipit-source-id: 5edbfa4e61610ecafff17c0e5e7f84d44cd51168
2018-07-02 11:25:58 -07:00

314 lines
7.9 KiB
JavaScript

/**
* Copyright (c) 2017-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.
*/
/* @flow */
const React = require("react");
const setupReactTests = require("./setupReactTests");
const { runTest } = setupReactTests();
/* eslint-disable no-undef */
const { expect, it } = global;
it("Simple", () => {
runTest(__dirname + "/FunctionalComponents/simple.js");
});
it("Simple 2", () => {
runTest(__dirname + "/FunctionalComponents/simple-2.js");
});
it("Simple 3", () => {
runTest(__dirname + "/FunctionalComponents/simple-3.js");
});
it("Simple 4", () => {
runTest(__dirname + "/FunctionalComponents/simple-4.js");
});
it("Simple 5", () => {
runTest(__dirname + "/FunctionalComponents/simple-5.js");
});
it("Simple 6", () => {
runTest(__dirname + "/FunctionalComponents/simple-6.js");
});
it("Simple 7", () => {
runTest(__dirname + "/FunctionalComponents/simple-7.js");
});
it("Simple 8", () => {
runTest(__dirname + "/FunctionalComponents/simple-8.js", {
expectReconcilerError: true,
});
});
it("Simple 9", () => {
runTest(__dirname + "/FunctionalComponents/simple-9.js", {
expectReconcilerError: true,
});
});
it("Simple 10", () => {
runTest(__dirname + "/FunctionalComponents/simple-10.js", {
expectReconcilerError: true,
});
});
it("Simple 11", () => {
runTest(__dirname + "/FunctionalComponents/simple-11.js", {
expectReconcilerError: true,
});
});
it("Simple 12", () => {
runTest(__dirname + "/FunctionalComponents/simple-12.js");
});
it("Runtime error", () => {
runTest(__dirname + "/FunctionalComponents/runtime-error.js", {
expectReconcilerError: true,
});
});
it("Simple 13", () => {
runTest(__dirname + "/FunctionalComponents/simple-13.js", {
expectReconcilerError: true,
});
});
it("Simple 14", () => {
runTest(__dirname + "/FunctionalComponents/simple-14.js");
});
it("Simple 15", () => {
runTest(__dirname + "/FunctionalComponents/simple-15.js");
});
it("Simple 16", () => {
runTest(__dirname + "/FunctionalComponents/simple-16.js");
});
it("Simple 17", () => {
runTest(__dirname + "/FunctionalComponents/simple-17.js");
});
it("Simple 18", () => {
runTest(__dirname + "/FunctionalComponents/simple-18.js");
});
it("Simple 19", () => {
runTest(__dirname + "/FunctionalComponents/simple-19.js");
});
it("Simple 20", () => {
runTest(__dirname + "/FunctionalComponents/simple-20.js");
});
it("Simple 21", () => {
runTest(__dirname + "/FunctionalComponents/simple-21.js");
});
it("Two roots", () => {
runTest(__dirname + "/FunctionalComponents/two-roots.js");
});
it("Havocing of ReactElements should not result in property assignments", () => {
runTest(__dirname + "/FunctionalComponents/react-element-havoc.js");
});
it("__reactCompilerDoNotOptimize", () => {
runTest(__dirname + "/FunctionalComponents/do-not-optimize.js");
});
it("Mutations - not-safe 1", () => {
runTest(__dirname + "/FunctionalComponents/not-safe.js", {
expectReconcilerError: true,
});
});
it("Mutations - not-safe 2", () => {
runTest(__dirname + "/FunctionalComponents/not-safe2.js", {
expectReconcilerError: true,
});
});
it("Mutations - not-safe 3", () => {
runTest(__dirname + "/FunctionalComponents/not-safe3.js", {
expectReconcilerError: true,
});
});
it("Mutations - safe 1", () => {
runTest(__dirname + "/FunctionalComponents/safe.js");
});
it("Mutations - safe 2", () => {
runTest(__dirname + "/FunctionalComponents/safe2.js");
});
it("Mutations - safe 3", () => {
runTest(__dirname + "/FunctionalComponents/safe3.js");
});
it("Handle mapped arrays", () => {
runTest(__dirname + "/FunctionalComponents/array-map.js");
});
it("Handle mapped arrays 2", () => {
runTest(__dirname + "/FunctionalComponents/array-map2.js");
});
it("Handle mapped arrays from Array.from", () => {
runTest(__dirname + "/FunctionalComponents/array-from.js");
});
it("Simple fragments", () => {
runTest(__dirname + "/FunctionalComponents/simple-fragments.js");
});
it("Simple children", () => {
runTest(__dirname + "/FunctionalComponents/simple-children.js");
});
it("Simple with new expression", () => {
runTest(__dirname + "/FunctionalComponents/simple-with-new-expression.js");
});
it("Simple refs", () => {
runTest(__dirname + "/FunctionalComponents/simple-refs.js");
});
it("16.3 refs", () => {
runTest(__dirname + "/FunctionalComponents/refs.js");
});
it("16.3 refs 2", () => {
runTest(__dirname + "/FunctionalComponents/refs2.js");
});
it("16.3 refs 3", () => {
runTest(__dirname + "/FunctionalComponents/refs3.js");
});
it("defaultProps", () => {
runTest(__dirname + "/FunctionalComponents/default-props.js");
});
it("Simple with abstract props", () => {
runTest(__dirname + "/FunctionalComponents/simple-with-abstract-props.js");
});
it("Simple with unary expressions", () => {
runTest(__dirname + "/FunctionalComponents/simple-with-unary.js");
});
it("Circular reference", () => {
runTest(__dirname + "/FunctionalComponents/circular-reference.js");
});
it("Conditional", () => {
runTest(__dirname + "/FunctionalComponents/conditional.js");
});
it("Equivalence", () => {
runTest(__dirname + "/FunctionalComponents/equivalence.js", {
expectedCreateElementCalls: /* original */ 20 + /* prepacked: many deduplicated */ 8,
});
});
it("Delete element prop key", () => {
runTest(__dirname + "/FunctionalComponents/delete-element-prop-key.js");
});
it("Dynamic props", () => {
runTest(__dirname + "/FunctionalComponents/dynamic-props.js");
});
it("Dynamic context", () => {
runTest(__dirname + "/FunctionalComponents/dynamic-context.js");
});
it("React.cloneElement", () => {
runTest(__dirname + "/FunctionalComponents/clone-element.js");
});
it("Return text", () => {
runTest(__dirname + "/FunctionalComponents/return-text.js");
});
it("Render array twice", () => {
runTest(__dirname + "/FunctionalComponents/array-twice.js");
});
it("Render nested array children", () => {
runTest(__dirname + "/FunctionalComponents/nested-array-children.js");
});
it("Return undefined", () => {
runTest(__dirname + "/FunctionalComponents/return-undefined.js");
});
it("Null or undefined props", () => {
runTest(__dirname + "/FunctionalComponents/null-or-undefined-props.js");
});
it("Event handlers", () => {
runTest(__dirname + "/FunctionalComponents/event-handlers.js");
});
it("Class component as root", () => {
runTest(__dirname + "/FunctionalComponents/class-root.js");
});
it("Class component as root with multiple render methods", () => {
runTest(__dirname + "/FunctionalComponents/class-root-with-render-methods.js");
});
it("Class component as root with props", () => {
runTest(__dirname + "/FunctionalComponents/class-root-with-props.js");
});
it("Class component as root with state", () => {
runTest(__dirname + "/FunctionalComponents/class-root-with-state.js");
});
it("Class component as root with refs", () => {
runTest(__dirname + "/FunctionalComponents/class-root-with-refs.js");
});
it("Class component as root with instance variables", () => {
runTest(__dirname + "/FunctionalComponents/class-root-with-instance-vars.js");
});
it("Class component as root with instance variables #2", () => {
runTest(__dirname + "/FunctionalComponents/class-root-with-instance-vars-2.js");
});
it("Additional functions closure scope capturing", () => {
runTest(__dirname + "/FunctionalComponents/additional-function-regression.js");
});
it("Dynamic ReactElement type", () => {
runTest(__dirname + "/FunctionalComponents/dynamic-type.js");
});
it("Dynamic ReactElement type #2", () => {
runTest(__dirname + "/FunctionalComponents/dynamic-type2.js");
});
it("Dynamic ReactElement type #3", () => {
runTest(__dirname + "/FunctionalComponents/dynamic-type3.js");
});
it("Dynamic ReactElement type #4", () => {
runTest(__dirname + "/FunctionalComponents/dynamic-type4.js");
});