-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Migrate apps unit tests away from wp scripts #79097
Changes from all commits
6eadef9
ad678fc
599b03e
8f008af
dcb6fbd
2d1c522
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1 @@ | ||
import '@testing-library/jest-dom/extend-expect'; | ||
|
||
jest.mock( 'a8c-fse-common-data-stores', () => {}, { virtual: true } ); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,4 @@ | ||
/** | ||
* Test configuration for the FSE plugin. | ||
* | ||
* Will match files such that: | ||
* 1. Must be in the apps/editing-toolkit/ directory | ||
* 2. Must have .test.EXT at the end of the filename | ||
* 3. EXT (above) must be one of js, ts, jsx, or tsx. | ||
* | ||
* Note: In order to use a different jest config for e2e tests, this config file | ||
* must be kept in the bin/ folder to prevent it from being detected as the | ||
* config file for e2e tests. | ||
*/ | ||
|
||
const path = require( 'path' ); | ||
const base = require( '@automattic/calypso-jest' ); | ||
// @wordpress/scripts manually adds additional Jest config ontop of | ||
// @wordpress/jest-preset-default so we pull in this file to extend it | ||
const defaults = require( '@wordpress/scripts/config/jest-unit.config.js' ); | ||
|
||
// Basically, CWD, so 'apps/editing-toolkit'. | ||
// Without this, it tries to use 'apps/editing-toolkit/bin' | ||
const pluginRoot = path.resolve( './' ); | ||
|
||
const config = { | ||
...base, | ||
...defaults, | ||
rootDir: path.normalize( '../../' ), // To detect wp-calypso root node_modules | ||
testMatch: [ `${ pluginRoot }/**/?(*.)test.[jt]s?(x)` ], | ||
transform: { '^.+\\.[jt]sx?$': path.join( __dirname, 'bin', 'babel-transform' ) }, | ||
testEnvironment: 'jsdom', | ||
setupFilesAfterEnv: [ | ||
...( defaults.setupFilesAfterEnv || [] ), // extend if present | ||
'<rootDir>/apps/editing-toolkit/bin/js-unit-setup', | ||
], | ||
module.exports = { | ||
preset: '../../test/apps/jest-preset.js', | ||
setupFilesAfterEnv: [ require.resolve( './bin/js-unit-setup' ) ], | ||
}; | ||
|
||
module.exports = config; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,10 +40,8 @@ | |
"lint:php": "../../vendor/bin/phpcs --standard=../phpcs.xml ./ ", | ||
"lint:php:fix": "../../vendor/bin/phpcbf --standard=../phpcs.xml ./ ", | ||
"sync:newspack-blocks": "./bin/sync-newspack-blocks.sh", | ||
"test:js": "npx wp-scripts test-unit-js --config='jest.config.js' --colors", | ||
"test:js:help": "npx wp-scripts test-unit-js --config='jest.config.js' --help --colors", | ||
"test:js:update-snapshots": "npx wp-scripts test-unit-js -u --config='jest.config.js' --colors", | ||
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 don't think these are useful -- |
||
"test:js:watch": "npx wp-scripts test-unit-js --config='jest.config.js' --watch --colors", | ||
"test:js": "yarn run -T test-apps apps/editing-toolkit", | ||
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.
|
||
"test:js:watch": "yarn test:js --watch", | ||
"test:php": "npx wp-env run phpunit 'phpunit -c /var/www/html/wp-content/plugins/editing-toolkit-plugin/phpunit.xml.dist'", | ||
"wpcom-sync": "./bin/wpcom-watch-and-sync.sh" | ||
}, | ||
|
@@ -98,7 +96,6 @@ | |
"@wordpress/primitives": "^3.21.0", | ||
"@wordpress/private-apis": "^0.9.0", | ||
"@wordpress/rich-text": "^6.0.0", | ||
"@wordpress/scripts": "^25.0.0", | ||
"@wordpress/server-side-render": "^4.0.0", | ||
"@wordpress/url": "^3.24.0", | ||
"calypso": "workspace:^", | ||
|
@@ -121,21 +118,18 @@ | |
"devDependencies": { | ||
"@automattic/calypso-apps-builder": "workspace:^", | ||
"@automattic/calypso-eslint-overrides": "workspace:^", | ||
"@automattic/calypso-jest": "workspace:^", | ||
"@tanstack/eslint-plugin-query": "^4.29.8", | ||
"@testing-library/jest-dom": "^5.16.5", | ||
"@testing-library/react": "^14.0.0", | ||
"@types/node": "^18.11.18", | ||
"@types/wordpress__plugins": "^3.0.0", | ||
"@wordpress/eslint-plugin": "^13.7.0", | ||
"@wordpress/jest-preset-default": "^10.4.0", | ||
"@wordpress/readable-js-assets-webpack-plugin": "^2.6.0", | ||
"babel-jest": "^27.5.1", | ||
"eslint-plugin-inclusive-language": "^2.2.0", | ||
"eslint-plugin-json-es": "^1.5.7", | ||
"eslint-plugin-md": "^1.0.19", | ||
"eslint-plugin-you-dont-need-lodash-underscore": "^6.12.0", | ||
"jest-teamcity": "^1.9.0", | ||
"wait-for-expect": "^3.0.2", | ||
"webpack": "^5.68.0" | ||
} | ||
|
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,3 @@ | ||
/** | ||
* Test configuration for the Odyssey Stats. | ||
* | ||
* Will match files such that: | ||
* 1. Must be in the apps/odyssey-stats/ directory | ||
* 2. Must have .test.EXT at the end of the filename | ||
* 3. EXT (above) must be one of js, ts, jsx, or tsx. | ||
*/ | ||
|
||
const path = require( 'path' ); | ||
const base = require( '@automattic/calypso-jest' ); | ||
// @wordpress/scripts manually adds additional Jest config ontop of | ||
// @wordpress/jest-preset-default so we pull in this file to extend it | ||
const defaults = require( '@wordpress/scripts/config/jest-unit.config.js' ); | ||
|
||
// Basically, CWD, so 'apps/odyssey-stats'. | ||
// Without this, it tries to use 'apps/odyssey-stats/bin' | ||
const pluginRoot = path.resolve( './' ); | ||
|
||
const config = { | ||
...base, | ||
...defaults, | ||
rootDir: path.normalize( '../../' ), // To detect wp-calypso root node_modules | ||
testMatch: [ `${ pluginRoot }/**/?(*.)test.[jt]s?(x)` ], | ||
transform: { '^.+\\.[jt]sx?$': path.join( __dirname, 'bin', 'babel-transform' ) }, | ||
testEnvironment: 'jsdom', | ||
setupFilesAfterEnv: [ | ||
...( defaults.setupFilesAfterEnv || [] ), // extend if present | ||
], | ||
module.exports = { | ||
preset: '../../test/apps/jest-preset.js', | ||
}; | ||
|
||
module.exports = config; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
const path = require( 'path' ); | ||
const base = require( '@automattic/calypso-jest' ); | ||
|
||
module.exports = { | ||
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 copies a lot of things from |
||
...base, | ||
cacheDirectory: path.join( __dirname, '../../.cache/jest' ), | ||
testEnvironment: 'jsdom', | ||
transformIgnorePatterns: [ | ||
'node_modules[\\/\\\\](?!.*\\.(?:gif|jpg|jpeg|png|svg|scss|sass|css)$)', | ||
], | ||
setupFiles: [ 'jest-canvas-mock' ], | ||
// This includes a lot of globals that don't exist, like fetch, matchMedia, etc. | ||
setupFilesAfterEnv: [ require.resolve( '../client/setup-test-framework.js' ) ], | ||
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. Worth evaluating if we need all those mocks and polyfills or if we can include a more minimal version. 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 was looked into this, but we'd need to duplicate at least a few things from that file. From what I could tell, none of it was specific enough to the client setup to justify splitting it out. I think it'd be good to keep this in mind in the future though. I personally like having this shared as much as possible, since there aren't big differences in the environments! Both the client and ETK run in a browser, after all. |
||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module.exports = { | ||
rootDir: './../../', | ||
// run tests for all packages that have a Jest config file | ||
projects: [ '<rootDir>/apps/*/jest.config.js' ], | ||
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. basically same approach as packages. |
||
}; |
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.
This is handled by the calypso-jest setup file.