0

I've been using the vue-cli browserify template and have been doing some unit testing. However I can't get proxyquireify to work. If you look in the tests folder there is a test there that references this file to test with mocks. However whenever I follow that example I get the following:

{ [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)

So I guess my question is twofold.

  1. Has anyone got a working setup with Vue, Browserify and Proxyquerify
  2. If not does anyone have a working way to mock external dependencies?

To test:

  1. install the template via vue-cli
  2. Edit test/unit/Hello.spec.js to include the mocked dep as specified in: this file
  3. run npm test
  4. You should receive an error.

Cheers

Matt Sanders
  • 370
  • 2
  • 12
  • Could you include your configuration (i.e. your gulp task that calls browserify to build the bundle) and your code in the question? The error you are seeing results from Browserify receiving an ES module. – cartant Sep 19 '16 at 02:19
  • yea sure, it's actually all in this link: https://github.com/vuejs-templates/browserify as I literally followed the instructions to install that template and added the test. If you don't have vue-cli you can check out the template that it creates here: https://github.com/vuejs-templates/browserify/tree/master/template Also just edited the question as I realised I'm not even using gulp (*duh*) got confused working on two projects at once – Matt Sanders Sep 19 '16 at 02:54
  • You mentioned gulp, but - looking quickly at it - I don't see any gulp tasks in the template. There is an NPM [`build` script](https://github.com/vuejs-templates/browserify/blob/master/template/package.json#L18) that appears calls browserify, but I don't see proxyquerify being specified. The important parts are the browserify call and the test that uses proxyquire, etc. It should be possible to get it to work, as I managed to do so [with TypeScript](https://github.com/TypeStrong/tsify/tree/master/examples/proxyquireify). – cartant Sep 19 '16 at 03:02
  • Yea, my mistake there, I was working on a similar project at the very same time with gulp and got my wires crossed. It's not using gulp, just run `npm test` which runs karma. – Matt Sanders Sep 19 '16 at 03:37

0 Answers0