Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncaught Error: Unexpected reserved word #7

Closed
rburgst opened this issue Dec 13, 2015 · 4 comments
Closed

Uncaught Error: Unexpected reserved word #7

rburgst opened this issue Dec 13, 2015 · 4 comments

Comments

@rburgst
Copy link

rburgst commented Dec 13, 2015

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
Copy link
Owner

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
Copy link
Author

rburgst commented Dec 19, 2015

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
Copy link
Owner

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
Copy link
Owner

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 mochajs/mocha#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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants