我有一个带有打字稿的反应应用程序,我使用 Jest 作为测试运行程序。我正在尝试使用 Jimp 从 base64 字符串创建图像。它在运行应用程序时工作正常,但我的测试因错误而崩溃:
ENAMETOOLONG: name too long, open 'data:image/png;base64,iVBORw0KG...
测试使用存储在文件中的字符串:
const importResults = await artifactsImporter.importFromImage(artifactsSourceImagesMock[0]);
并且图像是importFromImage()
使用 Jimp.create() 方法创建的(如果我console.log(base64Image)
在浏览器中添加并复制/粘贴它,图像会正确显示):
jimpImage = await Jimp.create(base64Image);
我的客人是 Jimp 以某种方式尝试使用字符串作为路径加载文件,而不是从 base64 字符串创建它。我不知道这是配置问题还是来自 jest、jsdom、Jimp 或任何其他库的错误。
我的 jest.config
{
collectCoverage: true,
coverageDirectory: 'coverage',
coverageReporters: ['json', 'text', 'lcov', 'clover'],
moduleFileExtensions: ['js', 'json', 'jsx', 'ts', 'tsx', 'node'],
moduleNameMapper: {
'\\.((s)?css|less|jpg|png)$': '<rootDir>/src/test/style-mock.ts',
},
preset: 'ts-jest',
setupFilesAfterEnv: ['<rootDir>/src/react-app/setupTests.ts'],
testMatch: ['**/__tests__/**/*.[jt]s?(x)', '**/?(*.)+(spec|test).[tj]s?(x)'],
testPathIgnorePatterns: ['\\\\node_modules\\\\', '/.stryker-tmp/', '/dist/'],
transform: {
'^.+\\.jsx?$': 'babel-jest',
},
}
我的 tsconfig.json
{
"compilerOptions": {
"target": "es6",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"outDir": "dist",
"module": "esnext",
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noFallthroughCasesInSwitch": true,
"moduleResolution": "node",
"resolveJsonModule": true,
"noEmit": true,
"jsx": "react-jsx",
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitAny": true,
"allowJs": true,
"isolatedModules": true
},
"include": [
"src",
"src/index.tsx"
]
}