Node.js Babel使用Webpack进行编译,但不使用玩笑
我正在尝试使用Babel withNode.js Babel使用Webpack进行编译,但不使用玩笑,node.js,webpack,babeljs,jestjs,es6-class,Node.js,Webpack,Babeljs,Jestjs,Es6 Class,我正在尝试使用Babel withenvpreset设置Jest来处理我的ES6项目。代码可以编译并使用Webpack,但不能使用Jest。问题似乎是从节点\u模块内部传输代码 package.json(纱线): toolbox.js中的定义: import EventPubSub from 'event-pubsub' class GUI { gui config values constructor() { // some valid code } } c
env
preset设置Jest来处理我的ES6项目。代码可以编译并使用Webpack,但不能使用Jest。问题似乎是从节点\u模块内部传输代码
package.json(纱线):
toolbox.js中的定义:
import EventPubSub from 'event-pubsub'
class GUI {
gui
config
values
constructor() {
// some valid code
}
}
class MIDI extends EventPubSub {
midi
constructor() {
super()
// some valid code down there
}
}
test.js:
import {GUI, MIDI} from './toolbox.js'
test('gui sanity', () => { // <--- pass
let gui = new GUI()
expect(gui).toBeTruthy()
});
test('midi sanity', () => { // <--- fail
let midi = new MIDI()
expect(midi).toBeTruthy()
});
从“/toolbox.js”导入{GUI,MIDI}
test('gui健全性',()=>{/{//101 |构造函数(){
102 | super()
103 |
104 |//请求MIDI访问
在新的MIDI上(toolbox.js:101:17)
at对象。(test.js:15:14)
所以,因为我想从node_modules
中扩展ES6类,所以我必须在jest配置中明确排除它:
"jest": {
"transformIgnorePatterns": [
"/node_modules/(?!event-pubsub).+\\.js$"
]
}
这样,模块将按原样导入到我的测试中(不传输)
import {GUI, MIDI} from './toolbox.js'
test('gui sanity', () => { // <--- pass
let gui = new GUI()
expect(gui).toBeTruthy()
});
test('midi sanity', () => { // <--- fail
let midi = new MIDI()
expect(midi).toBeTruthy()
});
TypeError: Class constructor EventPubSub cannot be invoked without 'new'
99 | midi
100 |
> 101 | constructor() {
102 | super()
103 |
104 | // request MIDI access
at new MIDI (toolbox.js:101:17)
at Object.<anonymous> (test.js:15:14)
"jest": {
"transformIgnorePatterns": [
"/node_modules/(?!event-pubsub).+\\.js$"
]
}