tswaters / atom-mocha-runner

atom mocha test runner.
https://atom.io/packages/mocha-runner
MIT License
4 stars 0 forks source link

Uncaught Error: Unexpected reserved word #7

Closed rburgst closed 8 years ago

rburgst commented 8 years ago

just try and run tests in a mocha project.

Atom Version: 1.3.1 System: Mac OS X 10.11.2 Thrown From: mocha-runner package, v1.1.8

Stack Trace

Uncaught Error: Unexpected reserved word

At /Users/rainer/.atom/packages/mocha-runner/lib/runner.js:47

SyntaxError: Unexpected reserved word
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:413:25)
    at Object.Module._extensions..js (module.js:452:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)
    at /Users/rainer/.atom/packages/mocha-runner/node_modules/mocha/lib/mocha.js:216:27
    at Array.forEach (native)
    at Mocha.loadFiles (/Users/rainer/.atom/packages/mocha-runner/node_modules/mocha/lib/mocha.js:213:14)

Commands

     -0:32.4.0 command-palette:toggle (atom-text-editor.editor.is-focused)
     -0:29.7.0 core:confirm (atom-text-editor.editor.mini.is-focused)
     -0:29.7.0 mocha-test-runner:run (atom-text-editor.editor)
     -0:04.4.0 command-palette:toggle (atom-text-editor.editor.is-focused)
     -0:02.4.0 core:move-down (atom-text-editor.editor.mini.is-focused)
     -0:02.1.0 core:confirm (atom-text-editor.editor.mini.is-focused)
     -0:02.1.0 mocha-runner:run-specs (atom-text-editor.editor)

Config

{
  "core": {}
}

Installed Packages

# User
atom-terminal-panel, v4.4.4
atom-ternjs, v0.11.3
atom-wallaby, v1.0.7
jsformat, v0.9.0
linter, v1.11.3
linter-eslint, v5.2.6
mocha-runner, v1.1.8
mocha-test-runner, v0.4.6
npm, v0.1.0
terminal-plus, v0.14.5

# Dev
No dev packages
tswaters commented 8 years ago

If you run mocha from the command line does it work?

Unexpected reserved word points at using es6 features that aren't available in the atom context without a transpiler in play. You can use the require parameter in mocha.opts to include babel or traceur.

rburgst commented 8 years ago

Yes, from the command line it works fine. You can reproduce this problem by running atom in the "todomvc" example dir from redux: https://github.com/rackt/redux/tree/master/examples/todomvc

tswaters commented 8 years ago

Ah, it works using npm test I imagine?

That npm test command does a few things including passing the compiler and require parameters.

This extension requires parameters passed through mocha.opts .... if these same parameters were present i imagine it would work.

With straight mocha I'm not sure if it will work.... although this likely depends what they are doing and whether these symbols are available in the installed node runtime (off hand I'm not sure if atom has updated their runtime to >= 4... even then, moot point if they use import over require)

I'm just responding via phone at the airport.... will look into this more in depth when I reach my destination.

tswaters commented 8 years ago

Ah yes, here's the full stack running just mocha -- they do indeed use import so it totally dies in the absence of the babel.

C:\code\redux\examples\todomvc>node_modules\.bin\mocha.cmd
C:\code\redux\examples\todomvc\test\setup.js:1
(function (exports, require, module, __filename, __dirname) { import { jsdom } from 'jsdom'
                                                              ^^^^^^

SyntaxError: Unexpected token import
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:374:25)
    at Object.Module._extensions..js (module.js:405:10)
    at Module.load (module.js:344:32)
    at Function.Module._load (module.js:301:12)
    at Module.require (module.js:354:17)
    at require (internal/module.js:12:17)
    at C:\code\redux\examples\todomvc\node_modules\mocha\lib\mocha.js:216:27
    at Array.forEach (native)
    at Mocha.loadFiles (C:\code\redux\examples\todomvc\node_modules\mocha\lib\mocha.js:213:14)
    at Mocha.run (C:\code\redux\examples\todomvc\node_modules\mocha\lib\mocha.js:453:10)
    at Object.<anonymous> (C:\code\redux\examples\todomvc\node_modules\mocha\bin\_mocha:393:18)
    at Module._compile (module.js:398:26)
    at Object.Module._extensions..js (module.js:405:10)
    at Module.load (module.js:344:32)
    at Function.Module._load (module.js:301:12)
    at Function.Module.runMain (module.js:430:10)
    at startup (node.js:141:18)
    at node.js:980:3

C:\code\redux\examples\todomvc>node --version
v5.3.0

One thing though, the npm test command also sets up NODE_ENV to be testing which cannot be done in mocha.opts (see https://github.com/mochajs/mocha/issues/185)

There's not much the extension can do here aside from executing what is in the npm test command. For what it's worth, the way in which the todomvs sets the environment variable is not done in a platform indepdendent way - even if I passed whatrever it was to the shell module it would have failed on my system.

Most of the options here around fixing the unexpected token can be fixed by passing the compile and require parameters via mocha.opts.... and there's not much the plugin can do around their reliance on NODE_ENV being testing.