From 54ee9c2c9f244adcc9d7d84953b1084a10549cc5 Mon Sep 17 00:00:00 2001
From: moonrailgun
Date: Mon, 2 Jan 2023 20:58:34 +0800
Subject: [PATCH] =?UTF-8?q?test:=20=E4=BF=AE=E5=A4=8DCI=E6=8A=A5=E9=94=99?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
client/web/jest.config.js | 33 +++++++-
.../__snapshots__/Markdown.spec.tsx.snap | 82 +++++++++++++++++--
client/web/tsconfig.test.json | 1 +
3 files changed, 107 insertions(+), 9 deletions(-)
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`] = `
-
+
+

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

+
+
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/*"],