Skip to content

Commit

Permalink
fix(jest): fix config dependency jsdom/typeahead may not exist.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Sep 19, 2023
1 parent 89b2927 commit 7c55d2f
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 14 deletions.
5 changes: 2 additions & 3 deletions packages/babel/tsconfig.json
@@ -1,13 +1,12 @@
{
"compilerOptions": {
"target": "esnext",
"module": "esnext",
"module": "node16",
"target": "ESNext",
"outDir": "./lib",
"strict": true,
"declaration": true,
"esModuleInterop": true,
"resolveJsonModule": true,
"moduleResolution": "node",
"skipLibCheck": true
},
"include": ["./src/**/*.ts"],
Expand Down
3 changes: 1 addition & 2 deletions packages/core/src/index.ts
Expand Up @@ -54,8 +54,7 @@ export async function tsbb() {
} else if (/^(watch|start|dev)/i.test(commandName)) {
compile({ ...flags, watch: true, entry } as CompileOptions);
} else if (/^(test)/i.test(commandName)) {
// @ts-ignore
jest.default(flags as unknown as JestOptions);
jest(flags as unknown as JestOptions);
} else {
console.error('\n \x1b[31;1m The build/watch/jest parameter must be passed in\x1b[0m\n');
process.exitCode = 1;
Expand Down
5 changes: 2 additions & 3 deletions packages/core/tsconfig.json
@@ -1,13 +1,12 @@
{
"compilerOptions": {
"target": "esnext",
"module": "esnext",
"module": "node16",
"target": "ESNext",
"outDir": "./lib",
"strict": true,
"declaration": true,
"esModuleInterop": true,
"resolveJsonModule": true,
"moduleResolution": "node",
"skipLibCheck": true
},
"include": ["./src/**/*.ts"],
Expand Down
1 change: 1 addition & 0 deletions packages/jest/package.json
Expand Up @@ -5,6 +5,7 @@
"author": "kenny wang <wowohoo@qq.com>",
"homepage": "https://jaywcjlove.github.io/tsbb",
"license": "MIT",
"type": "module",
"types": "./lib/index.d.ts",
"main": "./lib/index.js",
"scripts": {
Expand Down
6 changes: 5 additions & 1 deletion packages/jest/src/index.ts
@@ -1,8 +1,12 @@
import path from 'path';
import path, { dirname } from 'path';
import { runCLI } from '@jest/core';
import { Config } from '@jest/types';
import { fileURLToPath } from 'url';
import createJestConfig from './jest.config.js';

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

export type JestOptions = Partial<Config.Argv>;
export default async function jest(options: JestOptions = {}) {
const { env, coverage = false, rootDir = process.cwd() } = options;
Expand Down
9 changes: 7 additions & 2 deletions packages/jest/src/jest.config.ts
@@ -1,6 +1,9 @@
import path from 'path';
import Jest from 'jest';
import fs from 'fs-extra';
import { createRequire } from 'module';

const require = createRequire(import.meta.url);

const moduleFileExtensions = [
'web.mjs',
Expand Down Expand Up @@ -28,7 +31,8 @@ export default async function jestConfig(resolve: Function, rootDir: string): Pr
'<rootDir>/src/**/*.{spec,test}.{js,jsx,ts,tsx}',
],
// testEnvironment: 'jsdom',
testEnvironment: 'jest-environment-jsdom',
// testEnvironment: 'jest-environment-jsdom',
testEnvironment: require.resolve('jest-environment-jsdom'),
// testEnvironment: resolve('node_modules/jest-environment-jsdom/build/index.js'),
// testEnvironmentOptions: {
// url: 'http://localhost', // Your testing URL
Expand Down Expand Up @@ -58,7 +62,8 @@ export default async function jestConfig(resolve: Function, rootDir: string): Pr
'^.+\\.module\\.(css|less|styl|sass|scss)$': 'identity-obj-proxy',
},
moduleFileExtensions: [...moduleFileExtensions, 'node'].filter((ext) => !ext.includes('mjs')),
watchPlugins: ['jest-watch-typeahead/filename', 'jest-watch-typeahead/testname'],
// watchPlugins: ['jest-watch-typeahead/filename', 'jest-watch-typeahead/testname'],
watchPlugins: [require.resolve('jest-watch-typeahead/filename'), require.resolve('jest-watch-typeahead/testname')],
resetMocks: true,
coverageReporters: ['lcov', 'json-summary'],
};
Expand Down
3 changes: 3 additions & 0 deletions packages/jest/src/transform/babel.ts
@@ -1,4 +1,7 @@
import babelJest from 'babel-jest';
import { createRequire } from 'module';

const require = createRequire(import.meta.url);

const hasJsxRuntime = (() => {
if (process.env.DISABLE_NEW_JSX_TRANSFORM === 'true') {
Expand Down
5 changes: 2 additions & 3 deletions packages/jest/tsconfig.json
@@ -1,13 +1,12 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "esnext",
"module": "node16",
"target": "ESNext",
"outDir": "./lib",
"strict": true,
"declaration": true,
"esModuleInterop": true,
"resolveJsonModule": true,
"moduleResolution": "node",
"skipLibCheck": true
},
"include": ["./src/**/*.ts"],
Expand Down

0 comments on commit 7c55d2f

Please sign in to comment.