2aa9d73325
集中保留原版权声明,移除文件头检查和全局测试忽略规则。验证:全量单测、受影响用例复测及静态检查通过。
29 lines
867 B
JavaScript
29 lines
867 B
JavaScript
import assert from 'node:assert/strict';
|
|
import { readFile } from 'node:fs/promises';
|
|
import { transformWithEsbuild } from 'vite';
|
|
import * as actionIcons from '../../../src/components/common/icons/ActionIcons.js';
|
|
|
|
export async function loadFrontendModule(filename, mocks) {
|
|
const { code } = await transformWithEsbuild(
|
|
await readFile(filename, 'utf8'),
|
|
filename.pathname,
|
|
{
|
|
loader: 'jsx',
|
|
format: 'cjs',
|
|
jsx: 'transform',
|
|
define: { 'import.meta.env': '{}' },
|
|
},
|
|
);
|
|
const module = { exports: {} };
|
|
new Function('require', 'module', 'exports', code)(
|
|
(name) => {
|
|
if (name.endsWith('/common/icons/ActionIcons')) return actionIcons;
|
|
assert.ok(Object.hasOwn(mocks, name), 'Missing test dependency: ' + name);
|
|
return mocks[name];
|
|
},
|
|
module,
|
|
module.exports,
|
|
);
|
|
return module.exports;
|
|
}
|