Skip to content

Commit

Permalink
Improve handling of transpiled packages in unit tests (#14432)
Browse files Browse the repository at this point in the history
  • Loading branch information
gziolo authored and youknowriad committed Mar 20, 2019
1 parent f62fa36 commit ddab875
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 25 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion packages/block-serialization-default-parser/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) );

Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/disabled/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
30 changes: 30 additions & 0 deletions test/unit/jest.config.js
Original file line number Diff line number Diff line change
@@ -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',
'<rootDir>/test/unit/config/gutenberg-phase.js',
],
testURL: 'http://localhost',
testPathIgnorePatterns: [
'/node_modules/',
'/packages/e2e-tests',
'<rootDir>/.*/build/',
'<rootDir>/.*/build-module/',
],
transformIgnorePatterns: [
'node_modules/(?!(simple-html-tokenizer)/)',
],
};
22 changes: 0 additions & 22 deletions test/unit/jest.config.json

This file was deleted.

0 comments on commit ddab875

Please sign in to comment.