From cea87740d969442d8b8178af30fc78c11c277d36 Mon Sep 17 00:00:00 2001 From: Nico Jansen Date: Tue, 9 Mar 2021 08:50:51 +0100 Subject: [PATCH 1/2] feat(jest-runner): drop projectType "create-react-app-ts" Drop support for "react-scripts-ts" by removing "create-react-app-ts" project type from the jest-runner. Note: react with typescript is still supported, either by projectType custom or `create-react-app` dependend on the use case. See #2787 Closes #2787 --- packages/jest-runner/package.json | 5 +- .../schema/jest-runner-options.json | 3 +- .../jest-runner/src/config-loaders/index.ts | 6 +- .../react-scripts-ts-jest-config-loader.ts | 45 ----------- .../integration/create-react-app.it.spec.ts | 37 +++++++++ .../integration/jest-test-runner.it.spec.ts | 31 +------- .../config-loader-factory.spec.ts | 21 ------ ...eact-scripts-ts-jest-config-loader.spec.ts | 75 ------------------- .../testResources/my-react-app/package.json | 38 ++++++++++ .../testResources/my-react-app/src/App.css | 38 ++++++++++ .../testResources/my-react-app/src/App.js | 25 +++++++ .../my-react-app/src/App.test.js | 8 ++ .../testResources/my-react-app/src/index.css | 13 ++++ .../testResources/my-react-app/src/index.js | 17 +++++ .../testResources/my-react-app/src/logo.svg | 1 + .../my-react-app/src/reportWebVitals.js | 13 ++++ .../my-react-app/src/setupTests.js | 5 ++ 17 files changed, 203 insertions(+), 178 deletions(-) delete mode 100644 packages/jest-runner/src/config-loaders/react-scripts-ts-jest-config-loader.ts create mode 100644 packages/jest-runner/test/integration/create-react-app.it.spec.ts delete mode 100644 packages/jest-runner/test/unit/config-loaders/react-scripts-ts-jest-config-loader.spec.ts create mode 100644 packages/jest-runner/testResources/my-react-app/package.json create mode 100644 packages/jest-runner/testResources/my-react-app/src/App.css create mode 100644 packages/jest-runner/testResources/my-react-app/src/App.js create mode 100644 packages/jest-runner/testResources/my-react-app/src/App.test.js create mode 100644 packages/jest-runner/testResources/my-react-app/src/index.css create mode 100644 packages/jest-runner/testResources/my-react-app/src/index.js create mode 100644 packages/jest-runner/testResources/my-react-app/src/logo.svg create mode 100644 packages/jest-runner/testResources/my-react-app/src/reportWebVitals.js create mode 100644 packages/jest-runner/testResources/my-react-app/src/setupTests.js diff --git a/packages/jest-runner/package.json b/packages/jest-runner/package.json index 7052d10fca..0218692dce 100644 --- a/packages/jest-runner/package.json +++ b/packages/jest-runner/package.json @@ -42,6 +42,8 @@ "devDependencies": { "@jest/types": "~26.6.1", "@stryker-mutator/test-helpers": "4.5.0", + "@testing-library/jest-dom": "^5.11.9", + "@testing-library/react": "^11.2.5", "@types/node": "^14.0.1", "@types/semver": "~7.3.1", "jest": "~26.6.1", @@ -49,8 +51,7 @@ "jest-environment-jsdom-sixteen": "^1.0.3", "react": "~17.0.1", "react-dom": "~17.0.1", - "react-scripts": "~4.0.0", - "react-scripts-ts": "~3.1.0" + "react-scripts": "~4.0.3" }, "peerDependencies": { "@stryker-mutator/core": "~4.4.0", diff --git a/packages/jest-runner/schema/jest-runner-options.json b/packages/jest-runner/schema/jest-runner-options.json index 0c21d94807..e45ffb3b04 100644 --- a/packages/jest-runner/schema/jest-runner-options.json +++ b/packages/jest-runner/schema/jest-runner-options.json @@ -38,10 +38,9 @@ }, "definitions": { "jestProjectType": { - "description": "The type of project you are working on. \n* `custom` uses the `config` option. \n*`create-react-app` when you are using [create-react-app](https://github.com/facebook/create-react-app)\n* `create-react-app-ts` when you are using [create-react-app-typescript](https://github.com/wmonk/create-react-app-typescript)\n* `react`: DEPRECATED, please use `create-react-app`.", + "description": "The type of project you are working on. \n* `custom` uses the `config` option. \n*`create-react-app` when you are using [create-react-app](https://github.com/facebook/create-react-app)\n* `react`: DEPRECATED, please use `create-react-app`.", "enum": [ "create-react-app", - "create-react-app-ts", "custom" ] } diff --git a/packages/jest-runner/src/config-loaders/index.ts b/packages/jest-runner/src/config-loaders/index.ts index 347ba69cab..d6910c4d8c 100644 --- a/packages/jest-runner/src/config-loaders/index.ts +++ b/packages/jest-runner/src/config-loaders/index.ts @@ -9,14 +9,13 @@ import * as pluginTokens from '../plugin-tokens'; import { CustomJestConfigLoader } from './custom-jest-config-loader'; import { ReactScriptsJestConfigLoader } from './react-scripts-jest-config-loader'; -import { ReactScriptsTSJestConfigLoader } from './react-scripts-ts-jest-config-loader'; configLoaderFactory.inject = tokens(commonTokens.options, commonTokens.injector, commonTokens.logger); export function configLoaderFactory( options: StrykerOptions, injector: Injector, log: Logger -): CustomJestConfigLoader | ReactScriptsJestConfigLoader | ReactScriptsTSJestConfigLoader { +): CustomJestConfigLoader | ReactScriptsJestConfigLoader { const warnAboutConfigFile = (projectType: string, configFile: string | undefined) => { if (configFile) { log.warn(`Config setting "configFile" is not supported for projectType "${projectType}"`); @@ -35,9 +34,6 @@ export function configLoaderFactory( case 'create-react-app': warnAboutConfigFile(optionsWithJest.jest.projectType, optionsWithJest.jest.configFile); return configLoaderInjector.injectClass(ReactScriptsJestConfigLoader); - case 'create-react-app-ts': - warnAboutConfigFile(optionsWithJest.jest.projectType, optionsWithJest.jest.configFile); - return configLoaderInjector.injectClass(ReactScriptsTSJestConfigLoader); default: throw new Error(`No configLoader available for ${optionsWithJest.jest.projectType}`); } diff --git a/packages/jest-runner/src/config-loaders/react-scripts-ts-jest-config-loader.ts b/packages/jest-runner/src/config-loaders/react-scripts-ts-jest-config-loader.ts deleted file mode 100644 index 86b573a2fb..0000000000 --- a/packages/jest-runner/src/config-loaders/react-scripts-ts-jest-config-loader.ts +++ /dev/null @@ -1,45 +0,0 @@ -import path from 'path'; - -import { Logger } from '@stryker-mutator/api/logging'; -import { tokens, commonTokens } from '@stryker-mutator/api/plugin'; - -import { Config } from '@jest/types'; - -import { createReactTsJestConfig } from '../utils'; -import * as pluginTokens from '../plugin-tokens'; - -import { JestConfigLoader } from './jest-config-loader'; - -export class ReactScriptsTSJestConfigLoader implements JestConfigLoader { - public static inject = tokens(commonTokens.logger, pluginTokens.resolve, pluginTokens.projectRoot); - - constructor(private readonly log: Logger, private readonly resolve: RequireResolve, private readonly projectRoot: string) {} - - public loadConfig(): Config.InitialOptions { - try { - // Get the location of react-ts script, this is later used to generate the Jest configuration used for React projects. - const reactScriptsTsLocation = path.join(this.resolve('react-scripts-ts/package.json'), '..'); - - // Create the React configuration for Jest - const jestConfiguration = this.createJestConfig(reactScriptsTsLocation); - jestConfiguration.testEnvironment = 'jsdom'; - this.log.warn( - 'DEPRECATED: The support for create-react-app-ts projects is deprecated and will be removed in the future. Please migrate your project to create-react-app and update your Stryker config setting to "create-react-app" (see https://create-react-app.dev/docs/adding-typescript/)' - ); - return jestConfiguration; - } catch (e) { - if (this.isNodeErrnoException(e) && e.code === 'MODULE_NOT_FOUND') { - throw Error('Unable to locate package react-scripts-ts. ' + 'This package is required when projectType is set to "create-react-app-ts".'); - } - throw e; - } - } - - private isNodeErrnoException(arg: any): arg is NodeJS.ErrnoException { - return arg.code !== undefined; - } - - private createJestConfig(reactScriptsTsLocation: string): Config.InitialOptions { - return createReactTsJestConfig((relativePath: string): string => path.join(reactScriptsTsLocation, relativePath), this.projectRoot, false); - } -} diff --git a/packages/jest-runner/test/integration/create-react-app.it.spec.ts b/packages/jest-runner/test/integration/create-react-app.it.spec.ts new file mode 100644 index 0000000000..1b1360d020 --- /dev/null +++ b/packages/jest-runner/test/integration/create-react-app.it.spec.ts @@ -0,0 +1,37 @@ +import { commonTokens } from '@stryker-mutator/api/plugin'; +import { SuccessTestResult } from '@stryker-mutator/api/test-runner'; +import { assertions, factory, testInjector } from '@stryker-mutator/test-helpers'; +import { expect } from 'chai'; + +import { JestRunnerOptionsWithStrykerOptions } from '../../src/jest-runner-options-with-stryker-options'; +import { JestTestRunner, jestTestRunnerFactory } from '../../src/jest-test-runner'; +import { createJestOptions } from '../helpers/producers'; +import { resolveTestResource } from '../helpers/resolve-test-resource'; + +describe('JestTestRunner with "create-react-app" project type', () => { + let sut: JestTestRunner; + + beforeEach(() => { + process.chdir(resolveTestResource('my-react-app')); + const options: JestRunnerOptionsWithStrykerOptions = factory.strykerWithPluginOptions({ + jest: createJestOptions({ + projectType: 'create-react-app', + }), + }); + sut = testInjector.injector.provideValue(commonTokens.options, options).injectFunction(jestTestRunnerFactory); + }); + + it.only('should be able to run the tests', async () => { + const result = await sut.dryRun({ coverageAnalysis: 'perTest' }); + + const expectedTest: Omit = { + id: 'renders learn react link', + name: 'renders learn react link', + status: 0, + }; + + assertions.expectCompleted(result); + expect(result.tests).lengthOf(1); + expect(result.tests[0]).deep.contains(expectedTest); + }); +}); diff --git a/packages/jest-runner/test/integration/jest-test-runner.it.spec.ts b/packages/jest-runner/test/integration/jest-test-runner.it.spec.ts index 72ce53d70f..317c2989db 100644 --- a/packages/jest-runner/test/integration/jest-test-runner.it.spec.ts +++ b/packages/jest-runner/test/integration/jest-test-runner.it.spec.ts @@ -1,5 +1,4 @@ import path from 'path'; -import { platform } from 'os'; import { expect } from 'chai'; import { commonTokens } from '@stryker-mutator/api/plugin'; @@ -12,11 +11,6 @@ import { JestOptions } from '../../src-generated/jest-runner-options'; import { createJestOptions } from '../helpers/producers'; import { resolveTestResource } from '../helpers/resolve-test-resource'; -// eslint-disable-next-line @typescript-eslint/no-require-imports -const paths = require('react-scripts-ts/config/paths'); -// It's a bit hacky, but we need to tell create-react-app-ts to pick a different tsconfig.test.json -paths.appTsTestConfig = resolveTestResource('reactTsProject/tsconfig.test.json'); - // Needed for Jest in order to run tests process.env.BABEL_ENV = 'test'; @@ -42,33 +36,14 @@ describe(`${JestTestRunner.name} integration test`, () => { }; describe('dryRun', () => { - it('should run tests on the example React + TypeScript project', async function () { - if (platform() === 'win32') { - console.log("[SKIP] Skipping this test on windows, react ts doesn't work there."); - this.skip(); - } - // TODO: Get a proper React TS project that works on Windows - process.chdir(resolveTestResource('reactTsProject')); - const jestTestRunner = createSut({ projectType: 'create-react-app-ts' }); - - const runResult = await jestTestRunner.dryRun({ coverageAnalysis: 'off' }); - - assertions.expectCompleted(runResult); - expectToHaveSuccessfulTests(runResult, 1); - }); - it('should set the test name and timeSpentMs', async function () { - if (platform() === 'win32') { - console.log("[SKIP] Skipping this test on windows, react ts doesn't work there."); - this.skip(); - } - process.chdir(resolveTestResource('reactTsProject')); - const jestTestRunner = createSut({ projectType: 'create-react-app-ts' }); + process.chdir(resolveTestResource('jasmine2-node')); + const jestTestRunner = createSut(); const runResult = await jestTestRunner.dryRun({ coverageAnalysis: 'off' }); assertions.expectCompleted(runResult); - expect(runResult.tests[0].name).to.equal('renders without crashing'); + expect(runResult.tests[0].name).to.equal('Add should be able to add two numbers'); expect(runResult.tests[0].timeSpentMs).to.be.above(-1); }); diff --git a/packages/jest-runner/test/unit/config-loaders/config-loader-factory.spec.ts b/packages/jest-runner/test/unit/config-loaders/config-loader-factory.spec.ts index a9b0f10973..270be5fcde 100644 --- a/packages/jest-runner/test/unit/config-loaders/config-loader-factory.spec.ts +++ b/packages/jest-runner/test/unit/config-loaders/config-loader-factory.spec.ts @@ -6,24 +6,20 @@ import { Config } from '@jest/types'; import * as customJestConfigLoader from '../../../src/config-loaders/custom-jest-config-loader'; import * as reactScriptsJestConfigLoader from '../../../src/config-loaders/react-scripts-jest-config-loader'; -import * as reactScriptsTSJestConfigLoader from '../../../src/config-loaders/react-scripts-ts-jest-config-loader'; import { JestRunnerOptionsWithStrykerOptions } from '../../../src/jest-runner-options-with-stryker-options'; import { configLoaderFactory } from '../../../src/config-loaders'; describe(configLoaderFactory.name, () => { let customConfigLoaderStub: sinon.SinonStubbedInstance; let reactScriptsJestConfigLoaderStub: sinon.SinonStubbedInstance; - let reactScriptsTSJestConfigLoaderStub: sinon.SinonStubbedInstance; let options: JestRunnerOptionsWithStrykerOptions; beforeEach(() => { customConfigLoaderStub = sinon.createStubInstance(customJestConfigLoader.CustomJestConfigLoader); reactScriptsJestConfigLoaderStub = sinon.createStubInstance(reactScriptsJestConfigLoader.ReactScriptsJestConfigLoader); - reactScriptsTSJestConfigLoaderStub = sinon.createStubInstance(reactScriptsTSJestConfigLoader.ReactScriptsTSJestConfigLoader); sinon.stub(customJestConfigLoader, 'CustomJestConfigLoader').returns(customConfigLoaderStub); sinon.stub(reactScriptsJestConfigLoader, 'ReactScriptsJestConfigLoader').returns(reactScriptsJestConfigLoaderStub); - sinon.stub(reactScriptsTSJestConfigLoader, 'ReactScriptsTSJestConfigLoader').returns(reactScriptsTSJestConfigLoaderStub); const defaultOptions: Partial = { collectCoverage: true, @@ -33,7 +29,6 @@ describe(configLoaderFactory.name, () => { }; customConfigLoaderStub.loadConfig.returns(defaultOptions); reactScriptsJestConfigLoaderStub.loadConfig.returns(defaultOptions); - reactScriptsTSJestConfigLoaderStub.loadConfig.returns(defaultOptions); options = factory.strykerWithPluginOptions({ jest: { @@ -65,22 +60,6 @@ describe(configLoaderFactory.name, () => { testConfigFileWarning(options); }); }); - - describe('with "projectType": "create-react-app-ts"', () => { - beforeEach(() => { - options.jest.projectType = 'create-react-app-ts'; - }); - - it('should create a ReactScriptsTSJestConfigLoader', () => { - const sut = testInjector.injector.provideValue(commonTokens.options, options).injectFunction(configLoaderFactory); - - expect(sut).eq(reactScriptsTSJestConfigLoaderStub); - }); - - it('should warn when a configFile is set', () => { - testConfigFileWarning(options); - }); - }); }); function testConfigFileWarning(options: JestRunnerOptionsWithStrykerOptions) { diff --git a/packages/jest-runner/test/unit/config-loaders/react-scripts-ts-jest-config-loader.spec.ts b/packages/jest-runner/test/unit/config-loaders/react-scripts-ts-jest-config-loader.spec.ts deleted file mode 100644 index 9ec75f5f0b..0000000000 --- a/packages/jest-runner/test/unit/config-loaders/react-scripts-ts-jest-config-loader.spec.ts +++ /dev/null @@ -1,75 +0,0 @@ -import path from 'path'; - -import { Logger } from '@stryker-mutator/api/logging'; -import { factory } from '@stryker-mutator/test-helpers'; - -import { assert, expect } from 'chai'; -import sinon from 'sinon'; - -import { ReactScriptsTSJestConfigLoader } from '../../../src/config-loaders/react-scripts-ts-jest-config-loader'; -import * as helper from '../../../src/utils/create-react-jest-config'; - -describe(ReactScriptsTSJestConfigLoader.name, () => { - let sut: ReactScriptsTSJestConfigLoader; - let requireResolveStub: sinon.SinonStub; - let createReactJestConfigStub: sinon.SinonStub; - let loggerStub: sinon.SinonStubbedInstance; - - const projectRoot = '/path/to/project'; - const reactScriptsTsPackagePath = './node_modules/react-scripts-ts/package.json'; - - beforeEach(() => { - createReactJestConfigStub = sinon.stub(helper, 'createReactTsJestConfig'); - createReactJestConfigStub.callsFake((resolve: any, root: string, eject: boolean) => ({ - eject, - projectRoot: root, - relativePath: resolve('test'), - })); - - requireResolveStub = sinon.stub(); - requireResolveStub.returns(reactScriptsTsPackagePath); - - loggerStub = factory.logger(); - - sut = new ReactScriptsTSJestConfigLoader(loggerStub, (requireResolveStub as unknown) as RequireResolve, projectRoot); - }); - - it('should load the configuration via the createJestConfig method provided by react-scripts-ts', () => { - sut.loadConfig(); - - assert(requireResolveStub.calledWith('react-scripts-ts/package.json')); - }); - - it('should log a deprecation warning', () => { - sut.loadConfig(); - - assert( - loggerStub.warn.calledWith( - 'DEPRECATED: The support for create-react-app-ts projects is deprecated and will be removed in the future. Please migrate your project to create-react-app and update your Stryker config setting to "create-react-app" (see https://create-react-app.dev/docs/adding-typescript/)' - ) - ); - }); - - it('should generate a configuration', () => { - const config = sut.loadConfig(); - - expect(config).to.deep.equal({ - eject: false, - projectRoot: '/path/to/project', - relativePath: path.join('node_modules', 'react-scripts-ts', 'test'), - testEnvironment: 'jsdom', - }); - }); - - it('should throw an error when react-scripts could not be found', () => { - // Arrange - const error: NodeJS.ErrnoException = new Error(''); - error.code = 'MODULE_NOT_FOUND'; - requireResolveStub.throws(error); - - // Act & Assert - expect(() => sut.loadConfig()).throws( - 'Unable to locate package react-scripts-ts. This package is required when projectType is set to "create-react-app-ts".' - ); - }); -}); diff --git a/packages/jest-runner/testResources/my-react-app/package.json b/packages/jest-runner/testResources/my-react-app/package.json new file mode 100644 index 0000000000..0f8b6cf7b2 --- /dev/null +++ b/packages/jest-runner/testResources/my-react-app/package.json @@ -0,0 +1,38 @@ +{ + "name": "my-react-app", + "version": "0.1.0", + "private": true, + "dependencies": { + "@testing-library/jest-dom": "^5.11.4", + "@testing-library/react": "^11.1.0", + "@testing-library/user-event": "^12.1.10", + "react": "^17.0.1", + "react-dom": "^17.0.1", + "react-scripts": "4.0.3", + "web-vitals": "^1.0.1" + }, + "scripts": { + "start": "react-scripts start", + "build": "react-scripts build", + "test": "react-scripts test", + "eject": "react-scripts eject" + }, + "eslintConfig": { + "extends": [ + "react-app", + "react-app/jest" + ] + }, + "browserslist": { + "production": [ + ">0.2%", + "not dead", + "not op_mini all" + ], + "development": [ + "last 1 chrome version", + "last 1 firefox version", + "last 1 safari version" + ] + } +} diff --git a/packages/jest-runner/testResources/my-react-app/src/App.css b/packages/jest-runner/testResources/my-react-app/src/App.css new file mode 100644 index 0000000000..74b5e05345 --- /dev/null +++ b/packages/jest-runner/testResources/my-react-app/src/App.css @@ -0,0 +1,38 @@ +.App { + text-align: center; +} + +.App-logo { + height: 40vmin; + pointer-events: none; +} + +@media (prefers-reduced-motion: no-preference) { + .App-logo { + animation: App-logo-spin infinite 20s linear; + } +} + +.App-header { + background-color: #282c34; + min-height: 100vh; + display: flex; + flex-direction: column; + align-items: center; + justify-content: center; + font-size: calc(10px + 2vmin); + color: white; +} + +.App-link { + color: #61dafb; +} + +@keyframes App-logo-spin { + from { + transform: rotate(0deg); + } + to { + transform: rotate(360deg); + } +} diff --git a/packages/jest-runner/testResources/my-react-app/src/App.js b/packages/jest-runner/testResources/my-react-app/src/App.js new file mode 100644 index 0000000000..3784575723 --- /dev/null +++ b/packages/jest-runner/testResources/my-react-app/src/App.js @@ -0,0 +1,25 @@ +import logo from './logo.svg'; +import './App.css'; + +function App() { + return ( +
+
+ logo +

+ Edit src/App.js and save to reload. +

+ + Learn React + +
+
+ ); +} + +export default App; diff --git a/packages/jest-runner/testResources/my-react-app/src/App.test.js b/packages/jest-runner/testResources/my-react-app/src/App.test.js new file mode 100644 index 0000000000..1f03afeece --- /dev/null +++ b/packages/jest-runner/testResources/my-react-app/src/App.test.js @@ -0,0 +1,8 @@ +import { render, screen } from '@testing-library/react'; +import App from './App'; + +test('renders learn react link', () => { + render(); + const linkElement = screen.getByText(/learn react/i); + expect(linkElement).toBeInTheDocument(); +}); diff --git a/packages/jest-runner/testResources/my-react-app/src/index.css b/packages/jest-runner/testResources/my-react-app/src/index.css new file mode 100644 index 0000000000..ec2585e8c0 --- /dev/null +++ b/packages/jest-runner/testResources/my-react-app/src/index.css @@ -0,0 +1,13 @@ +body { + margin: 0; + font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', + 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', + sans-serif; + -webkit-font-smoothing: antialiased; + -moz-osx-font-smoothing: grayscale; +} + +code { + font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', + monospace; +} diff --git a/packages/jest-runner/testResources/my-react-app/src/index.js b/packages/jest-runner/testResources/my-react-app/src/index.js new file mode 100644 index 0000000000..ef2edf8ea3 --- /dev/null +++ b/packages/jest-runner/testResources/my-react-app/src/index.js @@ -0,0 +1,17 @@ +import React from 'react'; +import ReactDOM from 'react-dom'; +import './index.css'; +import App from './App'; +import reportWebVitals from './reportWebVitals'; + +ReactDOM.render( + + + , + document.getElementById('root') +); + +// If you want to start measuring performance in your app, pass a function +// to log results (for example: reportWebVitals(console.log)) +// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals +reportWebVitals(); diff --git a/packages/jest-runner/testResources/my-react-app/src/logo.svg b/packages/jest-runner/testResources/my-react-app/src/logo.svg new file mode 100644 index 0000000000..9dfc1c058c --- /dev/null +++ b/packages/jest-runner/testResources/my-react-app/src/logo.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/packages/jest-runner/testResources/my-react-app/src/reportWebVitals.js b/packages/jest-runner/testResources/my-react-app/src/reportWebVitals.js new file mode 100644 index 0000000000..5253d3ad9e --- /dev/null +++ b/packages/jest-runner/testResources/my-react-app/src/reportWebVitals.js @@ -0,0 +1,13 @@ +const reportWebVitals = onPerfEntry => { + if (onPerfEntry && onPerfEntry instanceof Function) { + import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => { + getCLS(onPerfEntry); + getFID(onPerfEntry); + getFCP(onPerfEntry); + getLCP(onPerfEntry); + getTTFB(onPerfEntry); + }); + } +}; + +export default reportWebVitals; diff --git a/packages/jest-runner/testResources/my-react-app/src/setupTests.js b/packages/jest-runner/testResources/my-react-app/src/setupTests.js new file mode 100644 index 0000000000..8f2609b7b3 --- /dev/null +++ b/packages/jest-runner/testResources/my-react-app/src/setupTests.js @@ -0,0 +1,5 @@ +// jest-dom adds custom jest matchers for asserting on DOM nodes. +// allows you to do things like: +// expect(element).toHaveTextContent(/react/i) +// learn more: https://github.com/testing-library/jest-dom +import '@testing-library/jest-dom'; From acf70b7b001897dae654ecf499af0b7fe95dea5f Mon Sep 17 00:00:00 2001 From: Nico Jansen Date: Tue, 9 Mar 2021 12:13:40 +0100 Subject: [PATCH 2/2] test: use correct coverage analysis --- .../jest-runner/test/integration/create-react-app.it.spec.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/jest-runner/test/integration/create-react-app.it.spec.ts b/packages/jest-runner/test/integration/create-react-app.it.spec.ts index 1b1360d020..87c439625c 100644 --- a/packages/jest-runner/test/integration/create-react-app.it.spec.ts +++ b/packages/jest-runner/test/integration/create-react-app.it.spec.ts @@ -21,8 +21,8 @@ describe('JestTestRunner with "create-react-app" project type', () => { sut = testInjector.injector.provideValue(commonTokens.options, options).injectFunction(jestTestRunnerFactory); }); - it.only('should be able to run the tests', async () => { - const result = await sut.dryRun({ coverageAnalysis: 'perTest' }); + it('should be able to run the tests', async () => { + const result = await sut.dryRun({ coverageAnalysis: 'off' }); const expectedTest: Omit = { id: 'renders learn react link',