单元测试Vuejs与Karma,Browserify和Proxyquireify抛出错误

时间:2016-09-19 00:31:59

标签: browserify karma-jasmine vue.js proxyquire

我一直在使用vue-cli browserify模板并且已经进行了一些单元测试。但是,我无法获得proxyquireify工作。如果你查看tests文件夹,那里有一个测试引用this file来测试模拟。但是,无论何时我遵循该示例,我都会得到以下结果:

{ [SyntaxError: 'import' and 'export' may appear only with 'sourceType: module' (1:0)] pos: 0, loc: Position { line: 1, column: 0 }, raisedAt: 6 }
SyntaxError: 'import' and 'export' may appear only with 'sourceType: module' (1:0)
    at Parser.pp.raise (/home/mattsanders/Downloads/NewVue/node_modules/proxyquireify/node_modules/detective/node_modules/acorn/dist/acorn.js:1745:13)
    at Parser.pp.parseStatement (/home/mattsanders/Downloads/NewVue/node_modules/proxyquireify/node_modules/detective/node_modules/acorn/dist/acorn.js:2450:34)
    at Parser.pp.parseTopLevel (/home/mattsanders/Downloads/NewVue/node_modules/proxyquireify/node_modules/detective/node_modules/acorn/dist/acorn.js:2379:21)
    at parse (/home/mattsanders/Downloads/NewVue/node_modules/proxyquireify/node_modules/detective/node_modules/acorn/dist/acorn.js:101:12)
    at parse (/home/mattsanders/Downloads/NewVue/node_modules/proxyquireify/node_modules/detective/index.js:9:12)
    at walk (/home/mattsanders/Downloads/NewVue/node_modules/proxyquireify/node_modules/detective/index.js:43:15)
    at Function.exports.find (/home/mattsanders/Downloads/NewVue/node_modules/proxyquireify/node_modules/detective/index.js:72:5)
    at findProxyquireVars (/home/mattsanders/Downloads/NewVue/node_modules/proxyquireify/lib/find-dependencies.js:31:6)
    at module.exports (/home/mattsanders/Downloads/NewVue/node_modules/proxyquireify/lib/find-dependencies.js:47:14)
    at requireDependencies (/home/mattsanders/Downloads/NewVue/node_modules/proxyquireify/lib/transform.js:9:14)
    at Stream.end (/home/mattsanders/Downloads/NewVue/node_modules/proxyquireify/lib/transform.js:24:16)
    at _end (/home/mattsanders/Downloads/NewVue/node_modules/proxyquireify/node_modules/through/index.js:61:9)
    at Stream.stream.end (/home/mattsanders/Downloads/NewVue/node_modules/proxyquireify/node_modules/through/index.js:70:5)
    at DestroyableTransform.onend (/home/mattsanders/Downloads/NewVue/node_modules/browserify/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:495:10)
    at DestroyableTransform.g (events.js:260:16)
    at emitNone (events.js:72:20)

所以我想我的问题是双重的。

  1. 有没有人使用Vue,Browserify和Proxyquerify进行工作设置
  2. 如果没有,有没有人有办法模拟外部依赖?
  3. 测试:

    1. 通过vue-cli安装模板
    2. 编辑test / unit / Hello.spec.js以包含模拟的dep,如下所示:this file
    3. 运行npm test
    4. 您应该收到错误。
    5. 干杯

0 个答案:

没有答案