From ddab875d6a14d3b026d3bd8380d8db83e4973b0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Grzegorz=20=28Greg=29=20Zi=C3=B3=C5=82kowski?= Date: Thu, 14 Mar 2019 17:39:59 +0100 Subject: [PATCH] Improve handling of transpiled packages in unit tests (#14432) --- package.json | 2 +- .../test/index.js | 2 +- .../components/src/disabled/test/index.js | 2 +- test/unit/jest.config.js | 30 +++++++++++++++++++ test/unit/jest.config.json | 22 -------------- 5 files changed, 33 insertions(+), 25 deletions(-) create mode 100644 test/unit/jest.config.js delete mode 100644 test/unit/jest.config.json diff --git a/package.json b/package.json index 6e071182be1a5..f9ada126e5e1b 100644 --- a/package.json +++ b/package.json @@ -186,7 +186,7 @@ "test-e2e": "wp-scripts test-e2e --config packages/e2e-tests/jest.config.js", "test-e2e:watch": "npm run test-e2e -- --watch", "test-php": "npm run lint-php && npm run test-unit-php", - "test-unit": "wp-scripts test-unit-js --config test/unit/jest.config.json", + "test-unit": "wp-scripts test-unit-js --config test/unit/jest.config.js", "test-unit:update": "npm run test-unit -- --updateSnapshot", "test-unit:watch": "npm run test-unit -- --watch", "test-unit-php": "docker-compose run --rm wordpress_phpunit phpunit", diff --git a/packages/block-serialization-default-parser/test/index.js b/packages/block-serialization-default-parser/test/index.js index 72f4121ce1944..068db2ef14c72 100644 --- a/packages/block-serialization-default-parser/test/index.js +++ b/packages/block-serialization-default-parser/test/index.js @@ -12,7 +12,7 @@ import { jsTester, phpTester } from '@wordpress/block-serialization-spec-parser/ /** * Internal dependencies */ -import { parse } from '../'; +import { parse } from '../src'; describe( 'block-serialization-default-parser-js', jsTester( parse ) ); diff --git a/packages/components/src/disabled/test/index.js b/packages/components/src/disabled/test/index.js index 36fdf3a85524d..bd7c556163e4e 100644 --- a/packages/components/src/disabled/test/index.js +++ b/packages/components/src/disabled/test/index.js @@ -14,7 +14,7 @@ import { Component } from '@wordpress/element'; import Disabled from '../'; jest.mock( '@wordpress/dom', () => { - const focus = require.requireActual( '@wordpress/dom' ).focus; + const focus = require.requireActual( '../../../../dom/src' ).focus; return { focus: { diff --git a/test/unit/jest.config.js b/test/unit/jest.config.js new file mode 100644 index 0000000000000..6c5db3c8db011 --- /dev/null +++ b/test/unit/jest.config.js @@ -0,0 +1,30 @@ +/** + * External dependencies + */ +const glob = require( 'glob' ).sync; + +// Finds all packages which are transpiled with Babel to force Jest to use their source code. +const transpiledPackageNames = glob( 'packages/*/src/index.js' ) + .map( ( fileName ) => fileName.split( '/' )[ 1 ] ); + +module.exports = { + rootDir: '../../', + moduleNameMapper: { + [ `@wordpress\\/(${ transpiledPackageNames.join( '|' ) })$` ]: 'packages/$1/src', + }, + preset: '@wordpress/jest-preset-default', + setupFiles: [ + 'core-js/fn/symbol/async-iterator', + '/test/unit/config/gutenberg-phase.js', + ], + testURL: 'http://localhost', + testPathIgnorePatterns: [ + '/node_modules/', + '/packages/e2e-tests', + '/.*/build/', + '/.*/build-module/', + ], + transformIgnorePatterns: [ + 'node_modules/(?!(simple-html-tokenizer)/)', + ], +}; diff --git a/test/unit/jest.config.json b/test/unit/jest.config.json deleted file mode 100644 index 3b7d0ca732a99..0000000000000 --- a/test/unit/jest.config.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "rootDir": "../../", - "moduleNameMapper": { - "@wordpress\\/(block-serialization-spec-parser|is-shallow-equal)$": "packages/$1", - "@wordpress\\/([a-z0-9-]+)$": "packages/$1/src" - }, - "preset": "@wordpress/jest-preset-default", - "setupFiles": [ - "core-js/fn/symbol/async-iterator", - "/test/unit/config/gutenberg-phase.js" - ], - "testURL": "http://localhost", - "testPathIgnorePatterns": [ - "/node_modules/", - "/packages/e2e-tests", - "/.*/build/", - "/.*/build-module/" - ], - "transformIgnorePatterns": [ - "node_modules/(?!(simple-html-tokenizer)/)" - ] -}