Skip to content

Commit

Permalink
test: fix jest.config.js
Browse files Browse the repository at this point in the history
From jestjs/jest#12689, jest passes `rootDir` option to babel-jest.
If rootDir is project sub-directory (e.g. `src/`, `__tests__/`),
babel cannot load babel.config.js in project root.
  • Loading branch information
tasshi-me committed May 17, 2022
1 parent 415b1de commit 6e36924
Show file tree
Hide file tree
Showing 17 changed files with 333 additions and 43 deletions.
8 changes: 5 additions & 3 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
module.exports = {
rootDir: "__tests__",
testPathIgnorePatterns: ["lib/"],
/** @type {import('@jest/types').Config.InitialOptions} */
const config = {
roots: ["<rootDir>/__tests__"],
testPathIgnorePatterns: ["<rootDir>/node_modules/", "lib/"],
};
module.exports = config;
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"initial:release": "lerna publish from-package --conventional-commits",
"prerelease": "npm-run-all -s build -p lint test",
"release": "lerna publish --conventional-commits --create-release github",
"pretest": "jest --rootDir __tests__",
"pretest": "jest",
"start": "yarn build --watch",
"test": "lerna run test --parallel",
"pretest:ci": "yarn pretest",
Expand All @@ -41,6 +41,7 @@
"@cybozu/eslint-config": "^17.0.1",
"@types/jest": "^27.5.1",
"@types/node": "^13.13.52",
"babel-jest": "^28.1.0",
"comment-json": "^4.2.2",
"eslint": "^8.15.0",
"jest": "^28.1.0",
Expand Down
7 changes: 4 additions & 3 deletions packages/create-plugin/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module.exports = {
testRegex: "/test/.*\\.ts$",
/** @type {import('@jest/types').Config.InitialOptions} */
const config = {
testRegex: "<rootDir>/test/.*\\.ts$",
testEnvironment: "node",
testPathIgnorePatterns: ["node_modules"],
};
module.exports = config;
4 changes: 2 additions & 2 deletions packages/customize-uploader/babel.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = {
presets: [
["@babel/preset-env", { targets: { node: "current" } }],
"@babel/preset-typescript"
]
"@babel/preset-typescript",
],
};
5 changes: 4 additions & 1 deletion packages/customize-uploader/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
module.exports = {
/** @type {import('@jest/types').Config.InitialOptions} */
const config = {
roots: ["<rootDir>/src"],
testRegex: "/__tests__/.*\\.test\\.ts$",
testEnvironment: "node",
};
module.exports = config;
4 changes: 2 additions & 2 deletions packages/customize-uploader/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
"prebuild": "yarn clean",
"build": "tsc --build --force",
"lint": "eslint --ext .ts src",
"test": "jest --rootDir src",
"test:ci": "jest --rootDir src --runInBand",
"test": "jest",
"test:ci": "jest --runInBand",
"clean": "rimraf dist",
"start": "yarn build --watch"
},
Expand Down
8 changes: 5 additions & 3 deletions packages/data-loader/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module.exports = {
rootDir: "src",
/** @type {import('@jest/types').Config.InitialOptions} */
const config = {
roots: ["<rootDir>/src"],
clearMocks: true,
testPathIgnorePatterns: ["fixtures"],
testPathIgnorePatterns: ["<rootDir>/node_modules/", "fixtures"],
};
module.exports = config;
11 changes: 4 additions & 7 deletions packages/dts-gen/babel.config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
module.exports = {
presets: [
[
"@babel/preset-env",
{ targets: { node: "current" } },
],
"@babel/preset-typescript",
],
presets: [
["@babel/preset-env", { targets: { node: "current" } }],
"@babel/preset-typescript",
],
};
8 changes: 5 additions & 3 deletions packages/dts-gen/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
module.exports = {
rootDir: "src",
testEnvironment: "node",
/** @type {import('@jest/types').Config.InitialOptions} */
const config = {
roots: ["<rootDir>/src"],
testEnvironment: "node",
};
module.exports = config;
7 changes: 4 additions & 3 deletions packages/plugin-manifest-validator/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module.exports = {
/** @type {import('@jest/types').Config.InitialOptions} */
const config = {
roots: ["<rootDir>/src"],
clearMocks: true,
rootDir: "src",
testPathIgnorePatterns: ["node_modules"],
testEnvironment: "node",
};
module.exports = config;
4 changes: 3 additions & 1 deletion packages/plugin-packer/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
module.exports = {
/** @type {import('@jest/types').Config.InitialOptions} */
const config = {
testRegex: "(?<!site)/test/[^\\/]*\\.spec.ts$",
testEnvironment: "node",
};
module.exports = config;
2 changes: 1 addition & 1 deletion packages/plugin-packer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
"ajv": "^6.12.6",
"array-flatten": "^3.0.0",
"assert": "^2.0.0",
"babel-jest": "^28.1.0",
"babel-plugin-replace-ts-export-assignment": "^0.0.2",
"browserify-zlib": "^0.2.0",
"buffer": "^6.0.3",
Expand All @@ -67,6 +66,7 @@
"cssnano": "^5.1.7",
"execa": "^5.1.1",
"glob": "^7.2.3",
"jest-environment-jsdom": "^28.1.0",
"normalize.css": "^8.0.1",
"path-browserify": "^1.0.1",
"postcss": "^8.4.13",
Expand Down
4 changes: 3 additions & 1 deletion packages/plugin-packer/site/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
module.exports = {
/** @type {import('@jest/types').Config.InitialOptions} */
const config = {
testRegex: "/test/.*-test\\.js$",
testEnvironment: "jsdom",
};
module.exports = config;
6 changes: 4 additions & 2 deletions packages/profile-loader/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
module.exports = {
rootDir: "src",
/** @type {import('@jest/types').Config.InitialOptions} */
const config = {
roots: ["<rootDir>/src"],
testEnvironment: "node",
};
module.exports = config;
13 changes: 9 additions & 4 deletions packages/rest-api-client/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
module.exports = {
/** @type {import('@jest/types').Config.InitialOptions} */
const config = {
clearMocks: true,
rootDir: "src",
setupFilesAfterEnv: ["<rootDir>/__tests__/setup.ts"],
testPathIgnorePatterns: ["node_modules", "<rootDir>/__tests__/setup.ts"],
roots: ["<rootDir>/src"],
setupFilesAfterEnv: ["<rootDir>/src/__tests__/setup.ts"],
testPathIgnorePatterns: [
"<rootDir>/node_modules/",
"<rootDir>/src/__tests__/setup.ts",
],
testEnvironment: "node",
};
module.exports = config;
11 changes: 8 additions & 3 deletions packages/webpack-plugin-kintone-plugin/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
module.exports = {
rootDir: "src",
/** @type {import('@jest/types').Config.InitialOptions} */
const config = {
roots: ["<rootDir>/src"],
testEnvironment: "node",
testPathIgnorePatterns: ["node_modules", "<rootDir>/__tests__/sample"],
testPathIgnorePatterns: [
"<rootDir>/node_modules/",
"<rootDir>/src/__tests__/sample",
],
testTimeout: 30000,
};
module.exports = config;
Loading

0 comments on commit 6e36924

Please sign in to comment.