karma-runner / karma-runner/karma-coverage
[preprocessor.coverage]: 'import' and 'export' may appear only with 'sourceType: "module"'
- Dominant language
- JavaScript
- Stars
- 771
- Forks
- 242
- PR merge metrics
- No merged PRs in 30d
Description
karma.conf.js
```
...
files: [
{ pattern: 'js/add.js', type: 'module' },
{ pattern: 'test/add.spec.js', type: 'module' }
],
preprocessors: {
'./js/add.js': ['coverage']
},
...
```
add.js
```
let add = n => ++n;
export { add };
```
add.spec.js
```
import { add } from '../js/add.js';
describe('test', function() {
it('add', function() {
expect(add(2)).toBe(3);
});
});
```
文件以引用,
使用了import,报错不知到怎么处理,
更换插件就好了
```
preprocessors: {
'./js/add.js': ['karma-coverage-istanbul-instrumenter']
},
coverageIstanbulInstrumenter: {
esModules: true
},
```
Contributor guide
Research direction
Reproduce the error with the karma.conf.js configuration and the example js/add.js and test/add.spec.js files, focusing on the coverage preprocessor handling of module scripts. Compare the failing coverage setup with the shown karma-coverage-istanbul-instrumenter configuration using esModules: true; done means module imports and exports are instrumented without the sourceType error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- testing
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100