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

Cannot run the same suite multiple times #3027

Closed
markb-trustifi opened this issue Sep 28, 2017 · 7 comments
Closed

Cannot run the same suite multiple times #3027

markb-trustifi opened this issue Sep 28, 2017 · 7 comments
Labels
type: question support question

Comments

@markb-trustifi
Copy link

Description

I want to run mocha tests programmatically multiple times.
I'm aware of the workaround with deleting require.cache but it works only for a small number of tests.

Steps to Reproduce

let mocha = new Mocha({
            ui: 'bdd',
            reporter: 'spec',
            useColors: true,
            timeout: 50000,
            fullTrace: true
        });
        let alltests = 10, finished = 0;
        for(let id=0;id<alltests;id++) {
            let filename = '../test/sometest.spec.js';
            mocha.addFile(filename);

            mocha.run(failures => {
                if(failures)
                    logger.error('#' +id + ' All done - test failures: ', failures);
            })
            .on('test', function(test) {
                logger.info('#' +id + ' Test started: '+test.title);
            })
            .on('test end', function(test) {
                logger.info('#' +id + ' Test done: '+test.title);
            })
            .on('pass', function(test) {
                logger.info('#' +id + ' Test passed: '+test.title);
            })
            .on('fail', function(test, err) {
                logger.info('#' +id + ' Test fail: '+test.title, err);
            })
            .on('end', function() {
                logger.info('#' +id + ' All done');
            });

            //mocha.suite.suites = [];
            let p = path.resolve(path.join(__dirname, filename));
            let rp = require.resolve(p);

            delete require.cache[rp];
        }

Expected behavior:
All 10 runs should pass

Actual behavior:
First 7 runs pass, the last 3 runs fail with error:
TypeError: Cannot read property 'call' of undefined

If I uncomment mocha.suite.suites = [], all tests end right away.

Reproduces how often:
always

Versions

mocha --version: 3.5.3
node node_modules/.bin/mocha --version: 3.5.3
node --version: v6.11.1

@boneskull
Copy link
Contributor

would need the test file to help further

@boneskull boneskull added the status: waiting for author waiting on response from OP - more information needed label Sep 29, 2017
@markb-trustifi
Copy link
Author

This is the test file.
If it runs on first time, continue running the test - sometimes it should fail.

const request = require('supertest');
const expect = require('chai').expect;
const path = require('path');

describe('attachments', () => {
    it('test1', done => {
        request('http://services.odata.org')
            .get('/TripPinRESTierService/(S(32zs1aehc5ajm1i2fpx3mi2j))/People')
            .set("header-header-header-header-header-header", 'header-header-header-header-header-header')
            .expect(res => {
                expect(res.status, res.text).to.be.within(200, 302);
            })
            .end(function (err, res) {
                done(err);
            });
    });

    it('test2', done => {
        request('http://services.odata.org')
            .get('/TripPinRESTierService/People(\'keithpinckney\')?$expand=Trips')
            .set("header-header-header-header-header-header", 'header-header-header-header-header-header')
            .expect(res => {
                expect(res.status, res.text).to.be.within(200, 302);
            })
            .end(function (err, res) {
                done(err);
            });
    });

    it('test3', done => {
        request('http://services.odata.org')
            .get('/TripPinRESTierService/Airports(\'KSFO\')/Location/Address ')
            .set("header-header-header-header-header-header", 'header-header-header-header-header-header')
            .expect(res => {
                expect(res.status, res.text).to.be.within(200, 302);
            })
            .end(function (err, res) {
                done(err);
            });
    });
});

@stale
Copy link

stale bot commented Jan 31, 2018

I am a bot that watches issues for inactivity.
This issue hasn't had any recent activity, and I'm labeling it stale. In 14 days, if there are no further comments or activity, I will close this issue.
Thanks for contributing to Mocha!

@stale stale bot added the stale this has been inactive for a while... label Jan 31, 2018
@markb-trustifi
Copy link
Author

What is going on with this issue?

@stale stale bot removed the stale this has been inactive for a while... label Feb 5, 2018
@stale
Copy link

stale bot commented Jun 5, 2018

I am a bot that watches issues for inactivity.
This issue hasn't had any recent activity, and I'm labeling it stale. In 14 days, if there are no further comments or activity, I will close this issue.
Thanks for contributing to Mocha!

@stale stale bot added the stale this has been inactive for a while... label Jun 5, 2018
@outsideris
Copy link
Contributor

Could you provide MCVE to reproduce it. The test files which you provided are depend on your applications, so we can't check it.

@stale stale bot removed the stale this has been inactive for a while... label Jun 6, 2018
@boneskull boneskull added the type: question support question label Jun 6, 2018
@boneskull
Copy link
Contributor

  • Why are you running Mocha programatically?
  • Upgrade Mocha
  • See --retry
  • Provide MCVE
  • Ask in chat room or stackoverflow

@boneskull boneskull removed the status: waiting for author waiting on response from OP - more information needed label Jun 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: question support question
Projects
None yet
Development

No branches or pull requests

3 participants