From 18a6df527fdf40779c8b0a4ad3ef9feacd798563 Mon Sep 17 00:00:00 2001 From: Sergey Makarov Date: Tue, 8 Dec 2020 07:46:41 +0300 Subject: [PATCH] Recovered some integration tests (#10091) --- packages/react-dev-utils/package.json | 2 +- .../src/__tests__/extract-source-map.js | 6 +++--- .../src/__tests__/get-source-map.js | 10 ++++++---- .../src/__tests__/parser/generic.js | 18 ++++++++++-------- .../config/jest/babelTransform.js | 3 ++- .../fixtures/kitchensink/template.json | 2 +- .../template/integration/webpack.test.js | 2 +- .../scripts/utils/createJestConfig.js | 6 +++--- 8 files changed, 27 insertions(+), 22 deletions(-) diff --git a/packages/react-dev-utils/package.json b/packages/react-dev-utils/package.json index b200f6b2e48..a65692dd866 100644 --- a/packages/react-dev-utils/package.json +++ b/packages/react-dev-utils/package.json @@ -79,7 +79,7 @@ }, "devDependencies": { "cross-env": "^7.0.2", - "jest": "26.4.2" + "jest": "26.6.0" }, "scripts": { "test": "cross-env FORCE_COLOR=true jest" diff --git a/packages/react-error-overlay/src/__tests__/extract-source-map.js b/packages/react-error-overlay/src/__tests__/extract-source-map.js index b47f5ab5f6d..70118234d49 100644 --- a/packages/react-error-overlay/src/__tests__/extract-source-map.js +++ b/packages/react-error-overlay/src/__tests__/extract-source-map.js @@ -16,15 +16,15 @@ test('extracts last source map directive', async () => { }); test('errors when no source map', async () => { - expect.assertions(1); - const testFileName = 'test.js'; + let error; try { await extractSourceMapUrl( testFileName, `console.log('hi')\n\nconsole.log('bye')` ); } catch (e) { - expect(e).toBe(`Cannot find a source map directive for ${testFileName}.`); + error = e; } + expect(error).toBe(`Cannot find a source map directive for ${testFileName}.`); }); diff --git a/packages/react-error-overlay/src/__tests__/get-source-map.js b/packages/react-error-overlay/src/__tests__/get-source-map.js index 27c6d5f7893..072854842e7 100644 --- a/packages/react-error-overlay/src/__tests__/get-source-map.js +++ b/packages/react-error-overlay/src/__tests__/get-source-map.js @@ -52,12 +52,14 @@ test('error on a source map with unsupported encoding', async () => { const file = fs .readFileSync(resolve(__dirname, '../../fixtures/junk-inline.mjs')) .toString('utf8'); + let error; try { await getSourceMap('/', file); } catch (e) { - expect(e instanceof Error).toBe(true); - expect(e.message).toBe( - 'Sorry, non-base64 inline source-map encoding is not supported.' - ); + error = e; } + expect(error instanceof Error).toBe(true); + expect(error.message).toBe( + 'Sorry, non-base64 inline source-map encoding is not supported.' + ); }); diff --git a/packages/react-error-overlay/src/__tests__/parser/generic.js b/packages/react-error-overlay/src/__tests__/parser/generic.js index 32bade9311f..a0110c37795 100644 --- a/packages/react-error-overlay/src/__tests__/parser/generic.js +++ b/packages/react-error-overlay/src/__tests__/parser/generic.js @@ -8,23 +8,25 @@ import { parse } from '../../utils/parser'; test('throws on null', () => { - expect.assertions(2); + let error; try { parse(null); } catch (e) { - expect(e instanceof Error).toBe(true); - expect(e.message).toBe('You cannot pass a null object.'); + error = e; } + expect(error instanceof Error).toBe(true); + expect(error.message).toBe('You cannot pass a null object.'); }); test('throws on unparsable', () => { - expect.assertions(2); + let error; try { parse({}); } catch (e) { - expect(e instanceof Error).toBe(true); - expect(e.message).toBe( - 'The error you provided does not contain a stack trace.' - ); + error = e; } + expect(error instanceof Error).toBe(true); + expect(error.message).toBe( + 'The error you provided does not contain a stack trace.' + ); }); diff --git a/packages/react-scripts/config/jest/babelTransform.js b/packages/react-scripts/config/jest/babelTransform.js index c3848181f1b..c5830153e80 100644 --- a/packages/react-scripts/config/jest/babelTransform.js +++ b/packages/react-scripts/config/jest/babelTransform.js @@ -1,10 +1,11 @@ -// @remove-file-on-eject +// @remove-on-eject-begin /** * Copyright (c) 2014-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. */ +// @remove-on-eject-end 'use strict'; const babelJest = require('babel-jest'); diff --git a/packages/react-scripts/fixtures/kitchensink/template.json b/packages/react-scripts/fixtures/kitchensink/template.json index 461bb5e60e5..c859e7a14cd 100644 --- a/packages/react-scripts/fixtures/kitchensink/template.json +++ b/packages/react-scripts/fixtures/kitchensink/template.json @@ -2,7 +2,7 @@ "package": { "dependencies": { "bootstrap": "4.3.1", - "jest": "26.4.2", + "jest": "26.6.0", "node-sass": "4.x", "normalize.css": "7.0.0", "prop-types": "15.7.2", diff --git a/packages/react-scripts/fixtures/kitchensink/template/integration/webpack.test.js b/packages/react-scripts/fixtures/kitchensink/template/integration/webpack.test.js index 0f5a70b2667..fcb61f50ec9 100644 --- a/packages/react-scripts/fixtures/kitchensink/template/integration/webpack.test.js +++ b/packages/react-scripts/fixtures/kitchensink/template/integration/webpack.test.js @@ -86,7 +86,7 @@ describe('Integration', () => { doc = await initDOM('image-inclusion'); expect(doc.getElementById('feature-image-inclusion').src).toMatch( - /^data:image\/jpeg;base64.+==$/ + /^data:image\/jpeg;base64.+=$/ ); }); diff --git a/packages/react-scripts/scripts/utils/createJestConfig.js b/packages/react-scripts/scripts/utils/createJestConfig.js index 78a63571b26..ca316aab5c5 100644 --- a/packages/react-scripts/scripts/utils/createJestConfig.js +++ b/packages/react-scripts/scripts/utils/createJestConfig.js @@ -41,9 +41,9 @@ module.exports = (resolve, rootDir, isEjecting) => { testEnvironment: 'jsdom', testRunner: require.resolve('jest-circus/runner'), transform: { - '^.+\\.(js|jsx|mjs|cjs|ts|tsx)$': isEjecting - ? '/node_modules/babel-jest' - : resolve('config/jest/babelTransform.js'), + '^.+\\.(js|jsx|mjs|cjs|ts|tsx)$': resolve( + 'config/jest/babelTransform.js' + ), '^.+\\.css$': resolve('config/jest/cssTransform.js'), '^(?!.*\\.(js|jsx|mjs|cjs|ts|tsx|css|json)$)': resolve( 'config/jest/fileTransform.js'