当我在Azure管道中运行LWC的Jest测试时,我得到了奇怪的错误
Cannot find module 'c/myComponent' from 'force-app/main/default/lwc/myComponent/__tests__/myComponent.test.js'
1 | import { createElement } from 'lwc';
> 2 | import myComponent from 'c/myComponent';
| ^
3 | import fetchTopics from '@salesforce/apex/MyComponentController.getAllContentTopics';
4 |
5 | const mockGetTopics = require('./data/getTopics.json');
at Resolver.resolveModule (node_modules/jest-resolve/build/resolver.js:324:11)
at Object.<anonymous> (force-app/main/default/lwc/myComponent/__tests__/myComponent.test.js:2:1)
字符串
这是我的jest.config.js
module.exports = {
...jestConfig,
coverageReporters: ['clover', 'json', 'text', 'lcov', 'cobertura'],
modulePathIgnorePatterns: ['/.localdevserver'],
modulePaths: ["<rootDir>"],
reporters: [
'default',
[
'jest-junit',
{
outputDirectory: 'tests',
outputName: 'test-results-lwc.xml'
}
]
]
};
型
在Azure Devops中,我在ubuntu上运行jest测试-最新图像Node.js是19.9.0,Npm是9.6.3版本
当我运行相同的测试和相同的配置,我得到了100%的覆盖率,所有的测试都通过了什么可以是这个测试运行之间的差异?
1条答案
按热度按时间xdnvmnnf1#
除非你有明确的路径,否则你不需要查看modulePaths属性。另外,看起来你在配置文件中缺少导入。
字符串