diff --git a/client/web/jest.config.js b/client/web/jest.config.js index 8095289e..267eb97a 100644 --- a/client/web/jest.config.js +++ b/client/web/jest.config.js @@ -2,6 +2,36 @@ const regeneratorRuntime = require('regenerator-runtime'); const { pathsToModuleNameMapper } = require('ts-jest'); const webCompilerOptions = require('./tsconfig.test.json').compilerOptions; +// 用于处理编译出来是esmodule会抛出 SyntaxError: Unexpected token 'export' 问题的包 +const esModules = [ + 'react-markdown', + 'vfile', + 'unist-util-stringify-position', + 'unified', + 'bail', + 'is-plain-obj', + 'trough', + 'remark-parse', + 'mdast-util-from-markdown', + 'mdast-util-to-string', + 'micromark', + 'decode-named-character-reference', + 'character-entities', + 'remark-rehype', + 'mdast-util-to-hast', + 'unist-builder', + 'unist-util-visit', + 'unist-util-is', + 'unist-util-position', + 'unist-util-generated', + 'mdast-util-definitions', + 'trim-lines', + 'property-information', + 'hast-util-whitespace', + 'space-separated-tokens', + 'comma-separated-tokens', +].join('|'); + /** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */ module.exports = { preset: 'ts-jest', @@ -19,8 +49,9 @@ module.exports = { transform: { '\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$': '/test/fileTransformer.js', + [`(${esModules}).+\\.(j|t)sx?$`]: 'ts-jest', }, - transformIgnorePatterns: ['/node_modules/'], + transformIgnorePatterns: [`/node_modules/\.pnpm/(?!(${esModules}))`], setupFiles: ['/test/setup.js'], setupFilesAfterEnv: [], globals: { diff --git a/client/web/src/components/__tests__/__snapshots__/Markdown.spec.tsx.snap b/client/web/src/components/__tests__/__snapshots__/Markdown.spec.tsx.snap index 3c1a4942..008509ee 100644 --- a/client/web/src/components/__tests__/__snapshots__/Markdown.spec.tsx.snap +++ b/client/web/src/components/__tests__/__snapshots__/Markdown.spec.tsx.snap @@ -52,10 +52,43 @@ exports[`Markdown link with baseUrl 1`] = ` - +
+ +
+
+ + + + Preview +
+
+

@@ -81,10 +114,43 @@ exports[`Markdown link without baseUrl 1`] = ` - +
+ +
+
+ + + + Preview +
+
+

diff --git a/client/web/tsconfig.test.json b/client/web/tsconfig.test.json index 4f7b0369..62427d3b 100644 --- a/client/web/tsconfig.test.json +++ b/client/web/tsconfig.test.json @@ -1,6 +1,7 @@ { "extends": "./tsconfig.json", "compilerOptions": { + "allowJs": true, "paths": { "@/*": ["./src/*"], "@test/*": ["./test/*"],