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

mocha test runner failures #74

Open
getify opened this issue Jun 9, 2015 · 7 comments
Open

mocha test runner failures #74

getify opened this issue Jun 9, 2015 · 7 comments

Comments

@getify
Copy link

getify commented Jun 9, 2015

I am getting mocha crashes while trying to debug problems with my promises lib and running the test suite:

/tmp/node_modules/promises-aplus-tests/node_modules/mocha/lib/reporters/spec.js:32
    return Array(indents).join('  ')
           ^
RangeError: Invalid array length
    at indent (/tmp/node_modules/promises-aplus-tests/node_modules/mocha/lib/reporters/spec.js:32:12)
    at Runner.<anonymous> (/tmp/node_modules/promises-aplus-tests/node_modules/mocha/lib/reporters/spec.js:73:17)
    at Runner.emit (events.js:117:20)
    at Runner.fail (/tmp/node_modules/promises-aplus-tests/node_modules/mocha/lib/runner.js:199:8)
    at Runner.uncaught (/tmp/node_modules/promises-aplus-tests/node_modules/mocha/lib/runner.js:549:8)
    at process.uncaught (/tmp/node_modules/promises-aplus-tests/node_modules/mocha/lib/runner.js:580:10)
    at process.emit (events.js:95:17)
    at process._fatalException (node.js:272:26)
npm ERR! Test failed.  See above for more details.
npm ERR! not ok code 0

Any ideas what's going on?

Here's another variation I get of the error:

/tmp/node_modules/promises-aplus-tests/node_modules/mocha/lib/reporters/spec.js:0
(function (exports, require, module, __filename, __dirname) {

RangeError: Invalid array length
    at indent (/tmp/node_modules/promises-aplus-tests/node_modules/mocha/lib/reporters/spec.js:32:12)
    at Runner.<anonymous> (/tmp/node_modules/promises-aplus-tests/node_modules/mocha/lib/reporters/spec.js:73:17)
    at emitTwo (events.js:92:20)
    at Runner.emit (events.js:172:7)
    at Runner.fail (/tmp/node_modules/promises-aplus-tests/node_modules/mocha/lib/runner.js:199:8)
    at Runner.uncaught (/tmp/node_modules/promises-aplus-tests/node_modules/mocha/lib/runner.js:549:8)
    at process.uncaught (/tmp/node_modules/promises-aplus-tests/node_modules/mocha/lib/runner.js:580:10)
    at emitOne (events.js:77:13)
    at process.emit (events.js:169:7)
    at process._fatalException (node.js:211:26)
npm ERR! Test failed.  See above for more details.
@domenic
Copy link
Member

domenic commented Jun 10, 2015

Can you provide a more full repo? E.g. what version of Mocha are you using? Does it occur when using only the exact code in the readme, or does it only happen when there are other Mocha tests for the library involved as well?

My guess is that something changed in Mocha 2.x.

@getify
Copy link
Author

getify commented Jun 10, 2015

I am using exactly and only the promises-aplus-tests (v2.1.0) package from npm, which has [email protected]. I've tried on Node 0.10.x, 0.12.x, and iojs 1.x and 2.x. This is what my test_adapter.js looks like:

// Adapter for "promises-aplus-tests" test runner

var path = require("path");
var Promise = require(path.join(__dirname,"lib","npo.src.js"));

module.exports.deferred = function __deferred__() {
    var o = {};
    o.promise = new Promise(function __Promise__(resolve,reject){
        o.resolve = resolve;
        o.reject = reject;
    });
    return o;
};

module.exports.resolved = function __resolved__(val) {
    return Promise.resolve(val);
};

module.exports.rejected = function __rejected__(reason) {
    return Promise.reject(reason);
};

I run the tests with:

$] npm test

It passes most of the tests, but starts adding up some test failures, usually somewhere between 20-100 failures (intermittently different numbers of failures).

The problem occurs at the end of the test suite (after all tests run), whenever it tries to list the summary of test failures.

Whenever I try to change internal details about sync/async scheduling of NPO, this failure crops up. If I leave NPO alone at its current release (v0.7.8), it passes the entire test suite and npm test runs fine to completion of all 872 tests. But whenever I start having some breakage of tests, virtually all of the time the breakage described above starts happening.

@domenic
Copy link
Member

domenic commented Jun 10, 2015

Thanks! Can you upload a branch or something with the changes that cause these failures so I can dig into this? Obviously the test runner itself should not be breaking, so this is on us or Mocha or someone.

@getify
Copy link
Author

getify commented Jun 10, 2015

Sure, here's a branch:

https://github.com/getify/native-promise-only/tree/mocha-test-failure

As you can see with this diff, the only change I made to NPO was to try to defer (async) the calling of then(..) on a thenable:

getify/native-promise-only@8c84f85

Thanks!

@pygy
Copy link

pygy commented Dec 18, 2015

I run into this with the Mithril promises as implemented in git HEAD (it's based on Promiz, but modified).

Here's the test runner:

var promisesAplusTests = require("promises-aplus-tests");
var m = require('mithril');

// Uncomment the next line to fix the crash:
// m.deferred.onerror = function(){};

promisesAplusTests(m, function (err) {
    // All done; output is in the console. Or check `err` for number of failures.
});

That implementation is not compliant at all, intentionally (then callbacks may be called synchronously if the promise is resolved, some errors are rethrown rather than rejecting the promise) and it regressed quite a bit recently on other fronts, but still...

m.deferred.onerror is the function that rethrows native errors, but it can be overridden in user code, as I do in the line commented out above. It looks like this:

function isNativeError(e) {
    return e instanceof EvalError ||
        e instanceof RangeError ||
        e instanceof ReferenceError ||
        e instanceof SyntaxError ||
        e instanceof TypeError ||
        e instanceof URIError
}

mdeferred.onerror = function (e) {
    if (isNativeError(e)) {
        pendingRequests = 0
        throw e
    }
}

Here's the stack trace:

2.3.3.4: If `then` is not a function, fulfill promise with `x`
`then` is `5`
  ✓ via return from a fulfilled promise
  360) via return from a fulfilled promise
/Users/pygy/dev/mithril.js/node_modules/promises-aplus-tests/node_modules/mocha/lib/reporters/spec.js:32
    return Array(indents).join('  ')
           ^

RangeError: Invalid array length
    at indent (/Users/pygy/dev/mithril.js/node_modules/promises-aplus-tests/node_modules/mocha/lib/reporters/spec.js:32:12)
    at Runner.<anonymous> (/Users/pygy/dev/mithril.js/node_modules/promises-aplus-tests/node_modules/mocha/lib/reporters/spec.js:73:17)
    at emitTwo (events.js:92:20)
    at Runner.emit (events.js:172:7)
    at Runner.fail (/Users/pygy/dev/mithril.js/node_modules/promises-aplus-tests/node_modules/mocha/lib/runner.js:199:8)
    at Runner.uncaught (/Users/pygy/dev/mithril.js/node_modules/promises-aplus-tests/node_modules/mocha/lib/runner.js:549:8)
    at process.uncaught (/Users/pygy/dev/mithril.js/node_modules/promises-aplus-tests/node_modules/mocha/lib/runner.js:580:10)
    at emitOne (events.js:77:13)
    at process.emit (events.js:169:7)
    at process._fatalException (node.js:234:26)

Edit: using Node 5.1.1

@pygy
Copy link

pygy commented Dec 19, 2015

I know it has, I know it's intentional, but it got worse recently #dontskim
;-)

—Pierre-Yves

On Sat, Dec 19, 2015 at 3:51 AM, Isiah Meadows [email protected]
wrote:

@pygy https://github.com/pygy Mithril intentionally deviates with its
deferreds.
https://github.com/lhorie/mithril.js/blob/next/test/mithril.deferred.js#L4-L31 This
has been documented for over a year at this point.
MithrilJS/mithril.js@36999e6#diff-7bd5bba178ccef1cbc1ff1695667aa8cR84


Reply to this email directly or view it on GitHub
#74 (comment)
.

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

4 participants