mochajs / mocha

☕️ simple, flexible, fun javascript test framework for node.js & the browser
https://mochajs.org
MIT License
22.58k stars 3.01k forks source link

Failed test in Mocha source code #4020

Closed soobing closed 4 years ago

soobing commented 5 years ago

Prerequisites

Description

I Failed Test at context.spec.js these two methods

describe('slow()', function() {
    it('should return the slow', function() {
      expect(this.slow(), 'to be', 75);
    });
  });
  describe('enableTimeouts()', function() {
    it('should return the enableTimeouts', function() {
      expect(this.enableTimeouts(), 'to be', true);
    });
  });

Steps to Reproduce

  1. Cloned forked mocha source
  2. npm install
  3. npm test
  4. TEST FAILED (ERROR OCCURED)

Reproduces how often: 100%

Versions

Additional Information

Logged this
 describe('slow()', function() {
    console.log('@@this 1/', this);
    console.log('@@@LOGEND')
    it('should return the slow', function() {
      console.log('@@this 2/', this);
      console.log('@@@LOGEND')
      expect(this.slow(), 'to be', 75);
    });
  });

then

HeadlessChrome 76.0.3809 (Mac OS X 10.14.6) LOG: '@@this 1/', Suite{title: 'slow()', ctx: Context{}, suites: [], tests: [], pending: false, _beforeEach: [], _beforeAll: [], _afterEach: [], _afterAll: [], root: false, _timeout: 1000, _enableTimeouts: true, _slow: 75, _bail: undefined, _retries: -1, _onlyTests: [], _onlySuites: [], delayed: false, parent: Suite{title: 'methods', ctx: Context{}, suites: [..., ...], tests: [], pending: false, _beforeEach: [], _beforeAll: [], _afterEach: [], _afterAll: [], root: false, _timeout: 1000, _enableTimeouts: true, _slow: 75, _bail: undefined, _retries: -1, _onlyTests: [], _onlySuites: [], delayed: false, parent: Suite{title: ..., ctx: ..., suites: ..., tests: ..., pending: ..., _beforeEach: ..., _beforeAll: ..., _afterEach: ..., _afterAll: ..., root: ..., _timeout: ..., _enableTimeouts: ..., _slow: ..., _bail: ..., _retries: ..., _onlyTests: ..., _onlySuites: ..., delayed: ..., $events: ...}, file: null}, file: null}
HeadlessChrome 76.0.3809 (Mac OS X 10.14.6) LOG: '@@@LOGEND'

LOG: '@@this 2/', Context{_runnable: Test{title: 'should return the slow', fn: function() { ... }, body: 'function() {
      console.log('@@this 2/', this);
      console.log('@@@LOGEND')
      expect(this.slow(), 'to be', 75);
    }', async: 0, sync: true, _timeout: 1000, _slow: 75, _enableTimeouts: true, timedOut: false, _trace: Error: done() called multiple times
Error: done() called multiple times
    at Test.Runnable [as constructor] (http://localhost:9876/absolute/Users/soobing/node_modules/mocha/mocha.js?8bf1d1adf34e719cca6e8f6915b9cd6eabf83d6b:4191:17)
    at new Test (http://localhost:9876/absolute/Users/soobing/node_modules/mocha/mocha.js?8bf1d1adf34e719cca6e8f6915b9cd6eabf83d6b:5929:12)
    at context.it.context.specify (http://localhost:9876/absolute/Users/soobing/node_modules/mocha/mocha.js?8bf1d1adf34e719cca6e8f6915b9cd6eabf83d6b:786:18)
    at Suite.<anonymous> (http://localhost:9876/absolute/var/folders/f7/h6bz9xl12x72d8bk6dcwr5080000gn/T/9c646e44740086c0415cc577071ecce6.browserify.js?31a0f2863b715bc60c865483b2acf72af9ab66dc:48469:5)
    at Object.create (http://localhost:9876/absolute/Users/soobing/node_modules/mocha/mocha.js?8bf1d1adf34e719cca6e8f6915b9cd6eabf83d6b:931:19)
    at context.describe.context.context (http://localhost:9876/absolute/Users/soobing/node_modules/mocha/mocha.js?8bf1d1adf34e719cca6e8f6915b9cd6eabf83d6b:744:27)
    at Suite.<anonymous> (http://localhost:9876/absolute/var/folders/f7/h6bz9xl12x72d8bk6dcwr5080000gn/T/9c646e44740086c0415cc577071ecce6.browserify.js?31a0f2863b715bc60c865483b2acf72af9ab66dc:48466:3)
    at Object.create (http://localhost:9876/absolute/Users/soobing/node_modules/mocha/mocha.js?8bf1d1adf34e719cca6e8f6915b9cd6eabf83d6b:931:19)
    at context.describe.context.context (http://localhost:9876/absolute/Users/soobing/node_modules/mocha/mocha.js?8bf1d1adf34e719cca6e8f6915b9cd6eabf83d6b:744:27)
    at Object.require./Users/soobing/development/contributon-2019/mocha/test/unit/context.spec.js (http://localhost:9876/absolute/var/folders/f7/h6bz9xl12x72d8bk6dcwr5080000gn/T/9c646e44740086c0415cc577071ecce6.browserify.js?31a0f2863b715bc60c865483b2acf72af9ab66dc:48457:1)
    at o (http://localhost:9876/absolute/var/folders/f7/h6bz9xl12x72d8bk6dcwr5080000gn/T/9c646e44740086c0415cc577071ecce6.browserify.js?31a0f2863b715bc60c865483b2acf72af9ab66dc:1:273)
    at http://localhost:9876/base/test/unit/context.spec.js?a019ad80ee69bd1211f6333efdb073c6824552c5:1:34, _retries: -1, _currentRetry: 0, pending: false, type: 'test', file: null, parent: Suite{title: ..., ctx: ..., suites: ..., tests: ..., pending: ..., _beforeEach: ..., _beforeAll: ..., _afterEach: ..., _afterAll: ..., root: ..., _timeout: ..., _enableTimeouts: ..., _slow: ..., _bail: ..., _retries: ..., _onlyTests: ..., _onlySuites: ..., delayed: ..., parent: ..., file: ...}, ctx: Context{_runnable: ..., test: ...}, $startTime: 1568643967421, $errors: [], $assertionErrors: [], $events: Object{error: ...}, callback: function done (err) { ... }}, test: Test{title: 'should return the slow', fn: function() { ... }, body: 'function() {
      console.log('@@this 2/', this);
      console.log('@@@LOGEND')
      expect(this.slow(), 'to be', 75);
    }', async: 0, sync: true, _timeout: 1000, _slow: 75, _enableTimeouts: true, timedOut: false, _trace: Error: done() called multiple times
Error: done() called multiple times
    at Test.Runnable [as constructor] (http://localhost:9876/absolute/Users/soobing/node_modules/mocha/mocha.js?8bf1d1adf34e719cca6e8f6915b9cd6eabf83d6b:4191:17)
    at new Test (http://localhost:9876/absolute/Users/soobing/node_modules/mocha/mocha.js?8bf1d1adf34e719cca6e8f6915b9cd6eabf83d6b:5929:12)
    at context.it.context.specify (http://localhost:9876/absolute/Users/soobing/node_modules/mocha/mocha.js?8bf1d1adf34e719cca6e8f6915b9cd6eabf83d6b:786:18)
    at Suite.<anonymous> (http://localhost:9876/absolute/var/folders/f7/h6bz9xl12x72d8bk6dcwr5080000gn/T/9c646e44740086c0415cc577071ecce6.browserify.js?31a0f2863b715bc60c865483b2acf72af9ab66dc:48469:5)
    at Object.create (http://localhost:9876/absolute/Users/soobing/node_modules/mocha/mocha.js?8bf1d1adf34e719cca6e8f6915b9cd6eabf83d6b:931:19)
    at context.describe.context.context (http://localhost:9876/absolute/Users/soobing/node_modules/mocha/mocha.js?8bf1d1adf34e719cca6e8f6915b9cd6eabf83d6b:744:27)
    at Suite.<anonymous> (http://localhost:9876/absolute/var/folders/f7/h6bz9xl12x72d8bk6dcwr5080000gn/T/9c646e44740086c0415cc577071ecce6.browserify.js?31a0f2863b715bc60c865483b2acf72af9ab66dc:48466:3)
    at Object.create (http://localhost:9876/absolute/Users/soobing/node_modules/mocha/mocha.js?8bf1d1adf34e719cca6e8f6915b9cd6eabf83d6b:931:19)
    at context.describe.context.context (http://localhost:9876/absolute/Users/soobing/node_modules/mocha/mocha.js?8bf1d1adf34e719cca6e8f6915b9cd6eabf83d6b:744:27)
    at Object.require./Users/soobing/development/contributon-2019/mocha/test/unit/context.spec.js (http://localhost:9876/absolute/var/folders/f7/h6bz9xl12x72d8bk6dcwr5080000gn/T/9c646e44740086c0415cc577071ecce6.browserify.js?31a0f2863b715bc60c865483b2acf72af9ab66dc:48457:1)
    at o (http://localhost:9876/absolute/var/folders/f7/h6bz9xl12x72d8bk6dcwr5080000gn/T/9c646e44740086c0415cc577071ecce6.browserify.js?31a0f2863b715bc60c865483b2acf72af9ab66dc:1:273)
    at http://localhost:9876/base/test/unit/context.spec.js?a019ad80ee69bd1211f6333efdb073c6824552c5:1:34, _retries: -1, _currentRetry: 0, pending: false, type: 'test', file: null, parent: Suite{title: ..., ctx: ..., suites: ..., tests: ..., pending: ..., _beforeEach: ..., _beforeAll: ..., _afterEach: ..., _afterAll: ..., root: ..., _timeout: ..., _enableTimeouts: ..., _slow: ..., _bail: ..., _retries: ..., _onlyTests: ..., _onlySuites: ..., delayed: ..., parent: ..., file: ...}, ctx: Context{_runnable: ..., test: ...}, $startTime: 1568643967421, $errors: [], $assertionErrors: [], $events: Object{error: ...}, callback: function done (err) { ... }}}
LOG: '@@@LOGEND'
Error

SUMMARY:
✔ 363 tests completed
ℹ 5 tests skipped
✖ 2 tests failed

FAILED TESTS:
  methods
    slow()
      ✖ should return the slow
        HeadlessChrome 76.0.3809 (Mac OS X 10.14.6)
      UnexpectedError: 
      expected
      Context({
        _runnable: Test({
          title: 'should return the slow',
          fn: function () {
            expect(this.slow(), 'to be', 75);
          },
          body: 'function() {\n      expect(this.slow(), \'to be\', 75);\n    }',
          async: 0, sync: true, _timeout: 1000, _slow: 75, _enableTimeouts: true,
          timedOut: false, _trace: Error('done() called multiple times'),
          _retries: -1, _currentRetry: 0, pending: false, type: 'test', file: null,
          parent: Suite({
            title: 'slow()', ctx: ..., suites: ..., tests: ..., pending: false,
            _beforeEach: ..., _beforeAll: ..., _afterEach: ..., _afterAll: ...,
            root: false, _timeout: 1000, _enableTimeouts: true, _slow: 75,
            _bail: undefined, _retries: -1, _onlyTests: ..., _onlySuites: ...,
            delayed: false, parent: ..., file: null
          }),
          ctx: [Circular], $startTime: 1568550012952, $errors: [],
          $assertionErrors: [],
          $events: { error: function (err) { self.fail(test, err); } },
          callback: function done (err) {
            var ms = self.timeout();
            if (self.timedOut) {
              return;
              // ... lines removed ...
              'ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.');
            }
            fn(err);
          }
        }),
        test: Test({
          title: 'should return the slow',
          fn: function () {
            expect(this.slow(), 'to be', 75);
          },
          body: 'function() {\n      expect(this.slow(), \'to be\', 75);\n    }',
          async: 0, sync: true, _timeout: 1000, _slow: 75, _enableTimeouts: true,
          timedOut: false, _trace: Error('done() called multiple times'),
          _retries: -1, _currentRetry: 0, pending: false, type: 'test', file: null,
          parent: Suite({
            title: 'slow()', ctx: ..., suites: ..., tests: ..., pending: false,
            _beforeEach: ..., _beforeAll: ..., _afterEach: ..., _afterAll: ...,
            root: false, _timeout: 1000, _enableTimeouts: true, _slow: 75,
            _bail: undefined, _retries: -1, _onlyTests: ..., _onlySuites: ...,
            delayed: false, parent: ..., file: null
          }),
          ctx: [Circular], $startTime: 1568550012952, $errors: [],
          $assertionErrors: [],
          $events: { error: function (err) { self.fail(test, err); } },
          callback: function done (err) {
            var ms = self.timeout();
            if (self.timedOut) {
              return;
              // ... lines removed ...
              'ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.');
            }
            fn(err);
          }
        })
      })
      to be 75

          at Context.<anonymous> (/var/folders/f7/h6bz9xl12x72d8bk6dcwr5080000gn/T/test/unit/context.spec.js:89 <- /var/folders/f7/h6bz9xl12x72d8bk6dcwr5080000gn/T/baec19b04c2d7f25283084b914684ad2.browserify.js:48468:7)
          set UNEXPECTED_FULL_TRACE=true to see the full stack trace

    enableTimeouts()
      ✖ should return the enableTimeouts
        HeadlessChrome 76.0.3809 (Mac OS X 10.14.6)
      UnexpectedError: 
      expected
      Context({
        _runnable: Test({
          title: 'should return the enableTimeouts',
          fn: function () {
            expect(this.enableTimeouts(), 'to be', true);
          },
          body: 'function() {\n      expect(this.enableTimeouts(), \'to be\', true);\n    }',
          async: 0, sync: true, _timeout: 1000, _slow: 75,
          _enableTimeouts: undefined, timedOut: false,
          _trace: Error('done() called multiple times'), _retries: -1,
          _currentRetry: 0, pending: false, type: 'test', file: null,
          parent: Suite({
            title: 'enableTimeouts()', ctx: ..., suites: ..., tests: ...,
            pending: false, _beforeEach: ..., _beforeAll: ..., _afterEach: ...,
            _afterAll: ..., root: false, _timeout: 1000, _enableTimeouts: true,
            _slow: 75, _bail: undefined, _retries: -1, _onlyTests: ...,
            _onlySuites: ..., delayed: false, parent: ..., file: null
          }),
          ctx: [Circular], $startTime: 1568550012991, $errors: [],
          $assertionErrors: [],
          $events: { error: function (err) { self.fail(test, err); } },
          callback: function done (err) {
            var ms = self.timeout();
            if (self.timedOut) {
              return;
              // ... lines removed ...
              'ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.');
            }
            fn(err);
          }
        }),
        test: Test({
          title: 'should return the enableTimeouts',
          fn: function () {
            expect(this.enableTimeouts(), 'to be', true);
          },
          body: 'function() {\n      expect(this.enableTimeouts(), \'to be\', true);\n    }',
          async: 0, sync: true, _timeout: 1000, _slow: 75,
          _enableTimeouts: undefined, timedOut: false,
          _trace: Error('done() called multiple times'), _retries: -1,
          _currentRetry: 0, pending: false, type: 'test', file: null,
          parent: Suite({
            title: 'enableTimeouts()', ctx: ..., suites: ..., tests: ...,
            pending: false, _beforeEach: ..., _beforeAll: ..., _afterEach: ...,
            _afterAll: ..., root: false, _timeout: 1000, _enableTimeouts: true,
            _slow: 75, _bail: undefined, _retries: -1, _onlyTests: ...,
            _onlySuites: ..., delayed: false, parent: ..., file: null
          }),
          ctx: [Circular], $startTime: 1568550012991, $errors: [],
          $assertionErrors: [],
          $events: { error: function (err) { self.fail(test, err); } },
          callback: function done (err) {
            var ms = self.timeout();
            if (self.timedOut) {
              return;
              // ... lines removed ...
              'ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.');
            }
            fn(err);
          }
        })
      })
      to be true

          at Context.<anonymous> (/var/folders/f7/h6bz9xl12x72d8bk6dcwr5080000gn/T/test/unit/context.spec.js:95 <- /var/folders/f7/h6bz9xl12x72d8bk6dcwr5080000gn/T/baec19b04c2d7f25283084b914684ad2.browserify.js:48474:7)
          set UNEXPECTED_FULL_TRACE=true to see the full stack trace

The script called "test.browser.unit" which runs "cross-env NODE_PATH=. karma start --single-run" failed with exit code 1 https://github.com/kentcdodds/nps/blob/v5.9.5/other/ERRORS_AND_WARNINGS.md#failed-with-exit-code
The script called "test.browser" which runs "nps clean build test.browser.unit test.browser.bdd test.browser.tdd test.browser.qunit test.browser.esm" failed with exit code 1 https://github.com/kentcdodds/nps/blob/v5.9.5/other/ERRORS_AND_WARNINGS.md#failed-with-exit-code
The script called "test" which runs "nps lint test.node test.browser test.bundle" failed with exit code 1 https://github.com/kentcdodds/nps/blob/v5.9.5/other/ERRORS_AND_WARNINGS.md#failed-with-exit-code```
aishwaryabk commented 4 years ago

Hi, is this issue solved? I am facing the same issue on PowerPC ppc64le architecture.

Munter commented 4 years ago

Travis doesn't seem to be able to recreate this with node 10.20.1: https://travis-ci.org/github/mochajs/mocha/builds/675200024

I can't recreate what you see myself. My system information:

I tried installing node 10.16.3 that you are using, but I also can't recreate what you are seeing locally.

I'm closing this because we can't confirm it. @aishwaryabk If you have any more qualifying information for us with this apparently recent occurrence, please write it in here and we can re-open the issue

aishwaryabk commented 4 years ago

@Munter I am trying to build zeromq package from source, which fails due to mocha. So I am building mocha from source. My system information:

OS: rhel 7.6 architecture: ppc64le mocha --version: 7.1.1 node version: v12.16.1 npm version: 6.13.4 gcc version : Red Hat 7.3.1-5 Packages installed: libjpeg-devel, pkgconfig, cairo, giflib-devel.

Would like some help on understanding the same. Thank You.

Munter commented 4 years ago

There isn't really any build step in mocha when you run in node. Are you running in a browser? And which error is it you get from the official releases?

aishwaryabk commented 4 years ago

I am running it on a High end VM with good connectivity. The following is the result of npm install and npm test:

Install:

bash-4.2# npm install
npm WARN acorn-jsx@5.2.0 requires a peer of acorn@^6.0.0 || ^7.0.0 but none is installed. 
    You must install peer dependencies yourself.
audited 24310 packages in 14.516s

75 packages are looking for funding
  run `npm fund` for details

found 6 low severity vulnerabilities
  run `npm audit fix` to fix them, or `npm audit` for details

Test: test_mocha.log

Running mocha command from the zeromq directory gives the following error:

bash-4.2# cd ../zeromq.node/
bash-4.2# mocha
(node:25424) DeprecationWarning: Configuration via mocha.opts is DEPRECATED and will be removed from a future version of Mocha. Use RC files or package.json instead.

Error: Could not locate the bindings file. Tried:
 → /zeromq.node/build/zmq.node
 → /zeromq.node/build/Debug/zmq.node
 → /zeromq.node/build/Release/zmq.node
 → /zeromq.node/out/Debug/zmq.node
 → /zeromq.node/Debug/zmq.node
 → /zeromq.node/out/Release/zmq.node
 → /zeromq.node/Release/zmq.node
 → /zeromq.node/build/default/zmq.node
 → /zeromq.node/compiled/12.16.1/linux/ppc64/zmq.node
at bindings (/zeromq.node/node_modules/bindings/bindings.js:88:9)
at Object.<anonymous> (/zeromq.node/lib/index.js:6:30)
at Module._compile (internal/modules/cjs/loader.js:1158:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)
at Module.load (internal/modules/cjs/loader.js:1002:32)
at Function.Module._load (internal/modules/cjs/loader.js:901:14)
at Module.require (internal/modules/cjs/loader.js:1044:19)
at require (internal/modules/cjs/helpers.js:77:18)
at Object.<anonymous> (/zeromq.node/index.js:2:18)
at Module._compile (internal/modules/cjs/loader.js:1158:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)
at Module.load (internal/modules/cjs/loader.js:1002:32)
at Function.Module._load (internal/modules/cjs/loader.js:901:14)
at Module.require (internal/modules/cjs/loader.js:1044:19)
at require (internal/modules/cjs/helpers.js:77:18)
at Object.<anonymous> (/zeromq.node/test/context.js:1:11)
at Module._compile (internal/modules/cjs/loader.js:1158:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)
at Module.load (internal/modules/cjs/loader.js:1002:32)
at Function.Module._load (internal/modules/cjs/loader.js:901:14)
at Module.require (internal/modules/cjs/loader.js:1044:19)
at require (internal/modules/cjs/helpers.js:77:18)
at requireOrImport (/root/.nvm/versions/node/v12.16.1/lib/node_modules/mocha/lib/esm-utils.js:15:12)
at Object.exports.loadFilesAsync (/root/.nvm/versions/node/v12.16.1/lib/node_modules/mocha/lib/esm-utils.js:28:26)
at Mocha.loadFilesAsync (/root/.nvm/versions/node/v12.16.1/lib/node_modules/mocha/lib/mocha.js:351:19)
at singleRun (/root/.nvm/versions/node/v12.16.1/lib/node_modules/mocha/lib/cli/run-helpers.js:107:15)
at exports.runMocha (/root/.nvm/versions/node/v12.16.1/lib/node_modules/mocha/lib/cli/run-helpers.js:144:11)
at Object.exports.handler (/root/.nvm/versions/node/v12.16.1/lib/node_modules/mocha/lib/cli/run.js:306:11)
at Object.runCommand (/root/.nvm/versions/node/v12.16.1/lib/node_modules/mocha/node_modules/yargs/lib/command.js:242:26)
at Object.parseArgs [as _parseArgs] (/root/.nvm/versions/node/v12.16.1/lib/node_modules/mocha/node_modules/yargs/yargs.js:1113:24)
at Object.parse (/root/.nvm/versions/node/v12.16.1/lib/node_modules/mocha/node_modules/yargs/yargs.js:575:25)
at Object.exports.main (/root/.nvm/versions/node/v12.16.1/lib/node_modules/mocha/lib/cli/cli.js:68:6)
at Object.<anonymous> (/root/.nvm/versions/node/v12.16.1/lib/node_modules/mocha/bin/mocha:133:29)
at Module._compile (internal/modules/cjs/loader.js:1158:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)
at Module.load (internal/modules/cjs/loader.js:1002:32)
at Function.Module._load (internal/modules/cjs/loader.js:901:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)
at internal/main/run_main_module.js:18:47
Munter commented 4 years ago

@aishwaryabk Your errors in the log you link to are related to your local machine not being able to connect between karma and headless chrome. It's very unlikely to be a mocha issue.

The stack you post when running mocha is not related to mocha either. It's node not being able to require your zeromq node bindings.

I'm going to keep this ticket closed, since none of these errors seem related to neither mocha, or the original error reported in this ticket