Skip to content

Commit

Permalink
fix: remark-gfm、mdx-js esm module cause jest run error
Browse files Browse the repository at this point in the history
  • Loading branch information
pointhalo committed Jul 9, 2024
1 parent bfe3843 commit 12b16e7
Show file tree
Hide file tree
Showing 7 changed files with 32,574 additions and 30 deletions.
34 changes: 33 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,25 @@ let ModuleNeedCompile2Cjs = [
'lodash-es',
'react-dnd',
'dnd-core',
'react-dnd-html5-backend'
'react-dnd-html5-backend',
'lottie'
// 'remark-gfm',
// 'mdast-util-gfm',
// 'mdast-util-find-and-replace',
// 'mdast-util-to-markdown',
// 'mdast-util-phrasing',
// 'micromark-util-character',
// 'micromark-util-normalize-identifier',
// 'unist-util-visit-parents',
// 'unist-util-stringify-position',
// 'decode-named-character-reference'
// 'devlop',
// 'vfile',
// 'vfile-location',
// 'vfile-message',
// 'markdown-extensions',
// '@mdx-js/mdx',
// 'mdast-util-mdx',
].join('|');

let config = {
Expand All @@ -22,11 +40,25 @@ let config = {
// 忽略出lodash-es、react-dnd、dnd-core外的node_modules中的所有内容,即node_modules中只有lodash-es、react-dnd、dnd-core需要被babel-jest处理
transformIgnorePatterns: [`<rootDir>/node_modules/(?!(${ModuleNeedCompile2Cjs}))`],
snapshotSerializers: ['enzyme-to-json/serializer'],
moduleFileExtensions: ['js', 'json', 'jsx', 'ts', 'tsx', 'node'],
// moduleDirectories: ["node_modules"],
moduleNameMapper: {
'\\.(css|scss)$': '<rootDir>/test/__mocks__/styleMock.js',
'\\.(jpg|jpeg|png|gif|eot|otf|webp|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$':
'<rootDir>/test/__mocks__/fileMock.js',
// 'vfile': '<rootDir>/packages/semi-foundation/node_modules/vfile',
// 'remark-mdx': '<rootDir>/packages/semi-foundation/node_modules/remark-mdx',
// 'unist-util-is': '<rootDir>/packages/semi-foundation/node_modules/unist-util-is',
// 'unist-util-visit': '<rootDir>/packages/semi-foundation/node_modules/unist-util-visit',
// 'vfile/do-not-use-conditional-minpath': '<rootDir>/packages/semi-foundation/node_modules/vfile/lib/minpath.js',
// 'vfile/do-not-use-conditional-minproc': '<rootDir>/packages/semi-foundation/node_modules/vfile/lib/minproc.js',
// 'vfile/do-not-use-conditional-minurl': '<rootDir>/packages/semi-foundation/node_modules/vfile/lib/minurl.js',
// 'devlop': '<rootDir>/test/__mocks__/devlop.js',
// 'unist-util-visit-parents/do-not-use-color': '<rootDir>/node_modules/unist-util-visit-parents/lib/color.node.js',

'@mdx-js/mdx': '<rootDir>/test/__mocks__/mdx-3.0.1-cjs.js',
'remark-gfm': '<rootDir>/test/__mocks__/remark-gfm-4.0.0-cjs.js',

'@douyinfe/semi-ui(.*)$': '<rootDir>/packages/semi-ui/$1',
'@douyinfe/semi-foundation(.*)$': '<rootDir>/packages/semi-foundation/$1',
'@douyinfe/semi-illustrations(.*)$': '<rootDir>/packages/semi-illustrations/src/$1',
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
"gatsby-source-filesystem": "^2.11.1",
"grapheme-splitter": "^1.0.4",
"immutability-helper": "^3.1.1",
"jest-canvas-mock": "^2.5.2",
"lodash-es": "^4.17.21",
"memoize-one": "^5.2.1",
"normalize.css": "^8.0.1",
Expand Down
45 changes: 45 additions & 0 deletions test/__mocks__/devlop.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// devlop.js
var devlop_exports = {};
__export(devlop_exports, {
deprecate: () => deprecate,
equal: () => equal,
ok: () => ok,
unreachable: () => unreachable
});
module.exports = __toCommonJS(devlop_exports);

// node_modules/devlop/lib/default.js
function deprecate(fn) {
return fn;
}
function equal() {
}
function ok() {
}
function unreachable() {
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
deprecate,
equal,
ok,
unreachable
});
Loading

0 comments on commit 12b16e7

Please sign in to comment.