question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

mocha test runner failing

See original GitHub issue

Hi, I’m trying out the latest test feature on alm, and the console is reporting

MOCHA STDERR:   ...\node_modules\alm\src\server\workers\tested\runners\mochaInstrumenter.ts:9
import * as common from "./instrumenterCommon";     
^^^^^^                                              
SyntaxError: Unexpected token import                
    at Object.exports.runInThisContext (vm.js:76:16)            

Error was reproduced on OS X as well as Windows 10, running Node 6.x.

$ npm list -g alm
`-- alm@2.0.2
$ typescript --init
$ typings init
$ typings install --global mocha
$ cat alm.json
{
  "tests": {
    "include": [
       "./tests/*.ts"
    ]
  }
}
$ cat tests/sample.ts                         
/// <reference path="../typings/index.d.ts" />

describe('simple test', () => {               
  it('adds 2 + 2', () => {                    
    throw 'bad stuff'                         
  })                                          
}) 

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
basaratcommented, Sep 18, 2016

@teyc thanks for the fix 🎉 🎈 ! What a great day to wake up to ❤️

Released with 2.0.4 🌹

image

1reaction
teyccommented, Sep 18, 2016

Thanks. Documenting this for someone like myself in the future - able to reproduce error executing

$ C:/Users/Chui/AppData/Roaming/npm/node_modules/alm/node_modules/mocha/bin/_mocha \
  --require C:/Users/Chui/AppData/Roaming/npm/node_modules/alm/node_modules/ts-node/register  \
  --require C:/Users/Chui/AppData/Roaming/npm/node_modules/alm/src/server/workers/tested/runners/mochaInstrumenter.ts \
  --reporter json --full-trace tests/sample.ts

It appears that ts-config shouldIgnore is skipping the compilation of .ts files because they occur in node_modules directory.

https://github.com/TypeStrong/ts-node/blob/master/src/index.ts#L292-L294

The following patch fixes the issue

mochaRunner.ts
-----
- var instrumentationPath = __dirname + '/mochaInstrumenter.ts';
+ var instrumentationPath = __dirname + '/mochaInstrumenter.js';
Read more comments on GitHub >

github_iconTop Results From Across the Web

Mocha test fails without giving proper error - node.js
Answer to this problem was very quite simple. My node server was already running on port 3000. now when I ran npm test,...
Read more >
Mocha exits with 0 exit code with failing tests #3893 - GitHub
Working to determine outside of our test suite. Running sub-suites alone seems to work fine, but running the entire suite does not. Possibly...
Read more >
mocha not running tests after first failure - Google Groups
Mocha is the testrunner. Problem: Both tests run just fine if they pass. But when I force the first one to fail via...
Read more >
Mocha | WebStorm Documentation - JetBrains
You can run Mocha tests from outside WebStorm, examine test results arranged in ... In the Test Runner tab, click Rerun Failed Tests...
Read more >
Faster way to run, debug and view results of Mocha tests
Mocha test output is hard to read, search and act upon, especially when many tests are failing. 100. Wallaby test output is ergonomic, ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found