[英]Angular: Component is not resolved when using Speedy Web Compiler (SWC) for TestBed tests
The tests in my Nx Angular 10 repo have been running very slow so I decided to switch from using jest-ts to @swc/jest.我的 Nx Angular 10 存储库中的测试运行速度非常慢,所以我决定从使用 jest-ts 切换到 @swc/jest。
jest.presets.ts开玩笑.presets.ts
const nxPreset = require('@nrwl/jest/preset');
module.exports = {
...nxPreset,
resolver: '@nrwl/jest/plugins/resolver',
moduleFileExtensions: ['ts', 'html', 'js', 'json'],
testEnvironment: 'jsdom',
transform: {
['.+\\.js$']: 'babel-jest',
'^.+\\.(ts|html)$': '@swc/jest',
},
}
.swcrc .swcrc文件
{
"jsc": {
"target": "es2020",
"parser": {
"tsx": false,
"syntax": "typescript",
"dynamicImport": true,
"privateMethod": false,
"functionBind": true,
"exportDefaultFrom": true,
"exportNamespaceFrom": true,
"decorators": true,
"topLevelAwait": true,
"importMeta": true
},
"transform": {
"decoratorMetadata": true,
"legacyDecorator": false,
"optimizer": {
"globals": {
"vars": {
"__DEBUG__": "true"
}
}
}
},
"keepClassNames": true,
"externalHelpers": true,
"loose": true
},
"minify": false,
"module": {
"type": "commonjs",
"strict": true,
"strictMode": true,
"lazy": false,
"noInterop": true
},
"sourceMaps": "inline",
"inlineSourcesContent": true
}
The component is a freshly made Angular component with 0 extra logic, the test that fails looks like该组件是一个新制作的 Angular 组件,具有 0 个额外逻辑,失败的测试看起来像
describe('SpeedTestComponent', () => {
let component: SpeedTestComponent;
let fixture: ComponentFixture<SpeedTestComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [SpeedTestComponent],
}).compileComponents();
});
beforeEach(() => {
fixture = TestBed.createComponent(SpeedTestComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
When I run the test it gives me this error当我运行测试时,它给了我这个错误
This only happens for TestBed tests.这只发生在 TestBed 测试中。
The ideal behaviour is for the test to past.理想的行为是通过测试。
packages包裹
"@swc/core": "^1.2.152",
"@swc/helpers": "^0.3.6",
"@swc/jest": "^0.2.20",
"jest": "^26.2.2",
Angular doesn't directly compile using SWC or TS. Angular 不直接使用 SWC 或 TS 编译。 This is likely the cause of the issue.
这可能是问题的原因。 It's way we started work on @nxext/angular-swc
这是我们开始@nxext/angular-swc 工作的方式
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.