swagger project test shows [SyntaxError: Unexpected identifier]


I’ve been working with Swagger to make an API server. With it, I created https://myopenbazaar.top. Pretty cool software, but I found testing with it pretty confusing. Swagger abstracts away mochajs, and for whatever reason, Swagger was hiding a stack trace of a failure when I was doing testing.

$ swagger project test
Running tests in: /Users/chrisgrimmett/scripts/imobso2/test...
[SyntaxError: Unexpected identifier]

That’s so not helpful!

Looking for a fix, I found that running mocha directly did the trick. It needed to be called with the --recursive flag, because swagger creates tests several levels deep in a directory tree.

$ mocha --recursive
/Users/chrisgrimmett/scripts/imobso2/test/api/controllers/online_controller.js:1
(function (exports, require, module, __filename, __dirname) { cvar request = require('supertest');
                                                                   ^^^^^^^

SyntaxError: Unexpected identifier
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:387:25)
    at Object.Module._extensions..js (module.js:422:10)
    at Module.load (module.js:357:32)
    at Function.Module._load (module.js:314:12)
    at Module.require (module.js:367:17)
    at require (internal/module.js:16:19)
    at /usr/local/lib/node_modules/mocha/lib/mocha.js:216:27
    at Array.forEach (native)
    at Mocha.loadFiles (/usr/local/lib/node_modules/mocha/lib/mocha.js:213:14)
    at Mocha.run (/usr/local/lib/node_modules/mocha/lib/mocha.js:453:10)
    at Object.<anonymous> (/usr/local/lib/node_modules/mocha/bin/_mocha:393:18)
    at Module._compile (module.js:413:34)
    at Object.Module._extensions..js (module.js:422:10)
    at Module.load (module.js:357:32)
    at Function.Module._load (module.js:314:12)
    at Function.Module.runMain (module.js:447:10)
    at startup (node.js:146:18)
    at node.js:404:3

Much better. Now I can actually tell what the problem is!

Looking for VOCALOID trading cards?

Check out Sakura Blossom Trading Post