这是indexloc提供的服务,不要输入任何密码
Skip to content

Add js unit testing config using Jest #20

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

Merged
merged 4 commits into from
Apr 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,19 @@
"rules": {
"jsdoc/check-indentation": "error",
"@wordpress/dependency-group": "error"
}
},
"overrides": [{
"files": [
"**/__tests__/**/*.js",
"**/test/*.js",
"**/?(*.)test.js",
"tests/js/**/*.js"
],
"extends": [
"plugin:jest/all"
],
"rules": {
// Add Rules for Jest here
}
}]
}
137 changes: 137 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@
"@babel/core": "7.17.8",
"@wordpress/babel-preset-default": "6.7.0",
"@wordpress/browserslist-config": "4.1.2",
"@wordpress/eslint-plugin": "11.1.0",
"@wordpress/env": "^4.4.0",
"@wordpress/eslint-plugin": "11.1.0",
"@wordpress/jest-preset-default": "8.1.1",
"@wordpress/scripts": "22.2.1",
"browserslist": "4.20.0",
"cross-env": "7.0.3",
Expand All @@ -33,6 +34,7 @@
"eslint-plugin-import": "2.25.4",
"eslint-plugin-jest": "26.1.3",
"husky": "7.0.4",
"jest-silent-reporter": "0.5.0",
"lint-staged": "12.3.7",
"npm-run-all": "4.1.5",
"webpack-remove-empty-scripts": "0.7.3"
Expand All @@ -54,6 +56,9 @@
"lint:staged": "lint-staged",
"prepare": "husky install",
"start": "wp-scripts start",
"test": "npm-run-all --parallel test:*",
"test:js": "wp-scripts test-unit-js --config=tests/js/jest.config.js",
"test:js:watch": "npm run test:js -- --watch",
"pretest:php": "wp-env run composer 'install --no-interaction'",
"test:php": "wp-env run phpunit 'phpunit -c /var/www/html/wp-content/themes/$(basename \"$PWD\")/phpunit.xml.dist --verbose'",
"wp-env": "wp-env"
Expand Down
32 changes: 32 additions & 0 deletions tests/js/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
module.exports = {
rootDir: '../../',
...require( '@wordpress/scripts/config/jest-unit.config' ),
transform: {
'^.+\\.[jt]sx?$': '<rootDir>/node_modules/@wordpress/scripts/config/babel-transform',
},
setupFiles: [
'<rootDir>/tests/js/setup-globals',
],
preset: '@wordpress/jest-preset-default',
testPathIgnorePatterns: [
'<rootDir>/.git',
'<rootDir>/node_modules',
'<rootDir>/assets/build',
'<rootDir>/vendor',
// Add more specific patterns here if needed.
],
coveragePathIgnorePatterns: [
'<rootDir>/node_modules',
'<rootDir>/assets/build/',
// Add more specific patterns here if needed.
],
modulePathIgnorePatterns: [
// Add more specific patterns here if needed.
],
coverageReporters: [ 'lcov' ],
coverageDirectory: '<rootDir>/tests/logs',
reporters: [
[ 'jest-silent-reporter', { useDots: true } ],
'<rootDir>/node_modules/@wordpress/scripts/config/jest-github-actions-reporter',
],
};
2 changes: 2 additions & 0 deletions tests/js/setup-globals.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Define globals for the test
// global.CSS = {};