-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Improve handling of transpiled packages in unit tests #14432
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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' ) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will also pick
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, this is the same story as with transpliling it :) We should address it separately.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm wondering if we ought to start codifying / documenting where we have these conventions, i.e. "sources should have a
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would not only document them but maybe try to go further and centralize the source of those lists. I will open a follow-up issue.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. #14508 is up for grabs :) |
||
| .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)/)', | ||
| ], | ||
| }; | ||
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add
@worpress/domback to the jest config?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
require.requireActualis problematic. If you use as@wordpress/dom, it will load it fromnode_modulesand try to usemainfrompackages.json- it skips module name mapper (edited). The mocking logic has its own life 🙂