From e73139a476e873d3563b18c241fc4930d65404d0 Mon Sep 17 00:00:00 2001 From: moonrailgun Date: Thu, 1 Jul 2021 23:21:29 +0800 Subject: [PATCH] test: global test --- web/jest.config.js => jest.config.js | 6 ++++-- package.json | 10 +++++++++- {web/test => test}/client.ts | 0 {web/test => test}/fileTransformer.js | 0 tsconfig.json | 12 ++++++++++++ web/package.json | 6 +----- web/tsconfig.json | 11 +---------- yarn.lock | 2 +- 8 files changed, 28 insertions(+), 19 deletions(-) rename web/jest.config.js => jest.config.js (66%) rename {web/test => test}/client.ts (100%) rename {web/test => test}/fileTransformer.js (100%) create mode 100644 tsconfig.json diff --git a/web/jest.config.js b/jest.config.js similarity index 66% rename from web/jest.config.js rename to jest.config.js index 0965729b..56d4adf0 100644 --- a/web/jest.config.js +++ b/jest.config.js @@ -1,19 +1,21 @@ -const { compilerOptions } = require('./tsconfig'); const regeneratorRuntime = require('regenerator-runtime'); +/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */ module.exports = { preset: 'ts-jest', testEnvironment: 'jsdom', moduleNameMapper: { '\\.(css|less|scss)$': 'identity-obj-proxy', }, - // projects: ['', '/web/*'], // https://jestjs.io/docs/next/configuration#projects-arraystring--projectconfig + // projects: ['/web/'], // https://jestjs.io/docs/configuration#projects-arraystring--projectconfig rootDir: '.', testRegex: '.*\\.(test|spec)\\.tsx?$', testPathIgnorePatterns: ['/node_modules/'], transform: { '\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$': '/test/fileTransformer.js', + '^.+\\.jsx?$': 'babel-jest', //这个是jest的默认配置 + '^.+\\.ts?$': 'ts-jest' //typescript转换 }, transformIgnorePatterns: ['/node_modules/'], setupFilesAfterEnv: [], diff --git a/package.json b/package.json index ba5094c1..ffb6ecce 100644 --- a/package.json +++ b/package.json @@ -10,5 +10,13 @@ "repository": "https://github.com/pawchat/pawchat.git", "author": "moonrailgun ", "license": "GPLv3", - "private": true + "private": true, + "scripts": { + "test": "jest" + }, + "devDependencies": { + "@types/jest": "^26.0.23", + "jest": "^27.0.6", + "ts-jest": "^27.0.3" + } } diff --git a/web/test/client.ts b/test/client.ts similarity index 100% rename from web/test/client.ts rename to test/client.ts diff --git a/web/test/fileTransformer.js b/test/fileTransformer.js similarity index 100% rename from web/test/fileTransformer.js rename to test/fileTransformer.js diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 00000000..d41cf869 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,12 @@ +{ + "compilerOptions": { + "target": "esnext", + "lib": ["DOM"], + "jsx": "react", + "esModuleInterop": true, + "isolatedModules": true, + "module": "ESNext", + "moduleResolution": "node", + "typeRoots": ["./node_modules/@types", "../node_modules/@types", "./types"] + } +} diff --git a/web/package.json b/web/package.json index e4e95d12..828ef789 100644 --- a/web/package.json +++ b/web/package.json @@ -8,8 +8,7 @@ "private": true, "scripts": { "build": "cross-env TS_NODE_PROJECT='tsconfig.node.json' webpack", - "dev": "cross-env TS_NODE_PROJECT='tsconfig.node.json' NODE_ENV=development webpack serve", - "test": "jest" + "dev": "cross-env TS_NODE_PROJECT='tsconfig.node.json' NODE_ENV=development webpack serve" }, "dependencies": { "@iconify/iconify": "^2.0.2", @@ -27,7 +26,6 @@ "tailwindcss": "^2.2.4" }, "devDependencies": { - "@types/jest": "^26.0.23", "@types/mini-css-extract-plugin": "^1.4.3", "@types/node": "^15.12.5", "@types/react": "^17.0.11", @@ -42,14 +40,12 @@ "esbuild-loader": "^2.13.1", "file-loader": "^6.2.0", "html-webpack-plugin": "^5.3.2", - "jest": "^27.0.6", "less": "^4.1.1", "less-loader": "^10.0.0", "mini-css-extract-plugin": "^1.6.2", "postcss": "^8.3.5", "postcss-loader": "^6.1.0", "style-loader": "^3.0.0", - "ts-jest": "^27.0.3", "ts-node": "^10.0.0", "tsconfig-paths": "^3.9.0", "typescript": "^4.3.4", diff --git a/web/tsconfig.json b/web/tsconfig.json index d41cf869..3c43903c 100644 --- a/web/tsconfig.json +++ b/web/tsconfig.json @@ -1,12 +1,3 @@ { - "compilerOptions": { - "target": "esnext", - "lib": ["DOM"], - "jsx": "react", - "esModuleInterop": true, - "isolatedModules": true, - "module": "ESNext", - "moduleResolution": "node", - "typeRoots": ["./node_modules/@types", "../node_modules/@types", "./types"] - } + "extends": "../tsconfig.json" } diff --git a/yarn.lock b/yarn.lock index a5ac7400..59fef895 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4243,7 +4243,7 @@ jest-worker@^27.0.2, jest-worker@^27.0.6: jest@^27.0.6: version "27.0.6" - resolved "https://registry.npmjs.org/jest/-/jest-27.0.6.tgz#10517b2a628f0409087fbf473db44777d7a04505" + resolved "https://registry.yarnpkg.com/jest/-/jest-27.0.6.tgz#10517b2a628f0409087fbf473db44777d7a04505" integrity sha512-EjV8aETrsD0wHl7CKMibKwQNQc3gIRBXlTikBmmHUeVMKaPFxdcUIBfoDqTSXDoGJIivAYGqCWVlzCSaVjPQsA== dependencies: "@jest/core" "^27.0.6"