mocha-parallel / mocha-parallel-tests

Parallel test runner for mocha tests. Looking for maintainer.
MIT License
200 stars 45 forks source link

Tests aren't running when running programmatically #235

Closed danlomantoSamsungNext closed 5 years ago

danlomantoSamsungNext commented 5 years ago

I'm trying to run my tests in parallel programmatically, but it looks like the tests aren't being kicked off. When I run my tests just using pure Mocha, my tests run (in serial of course). However when I change my import to just use mocha-parallel-tests, my tests are never actually started. To run my tests I just have a js function that wraps the kicking off of the tests. I'll put the sample code below.

How Tests are Run:

    // import * as Mocha from 'mocha';
    import Mocha from 'mocha-parallel-tests';
    import * as path from 'path';

    import { GetTestFiles } from './get-test-files';

    module.exports.runTests = function () {

        let mocha = new Mocha();

        // First, let's get all the test files in the output directory.
        const filelist = GetTestFiles.getFiles(path.join(__dirname, "../tests/apps"), []);

        console.log("FILE LIST", filelist);

        filelist.forEach((filePath) => {
            mocha = mocha.addFile(filePath);
        });

        const runner = mocha.run();
    };

Example Test:

  import { expect } from 'chai';

    describe('Example App', function () {

      beforeEach(async function () {
        console.log('THIS IS IN THE BEFOREEACH()');
      });

      it('Expect True to Equal True', function () {
        console.log('THIS IS IN THE TEST');
        expect(true).to.equal(true);
      });

      afterEach(async function () {
        console.log('THIS IS IN THE AFTEREACH()');
      });
    });

When running that function using the regular Mocha library, that tests executes and I see the console output. When I change the function to use mocha-parallel-tests, the test isn't started at all.

Is there something that I'm missing? I'm sorta at a loss. Thanks for any help you might be able to provide!!!!

danlomantoSamsungNext commented 5 years ago

I've done some digging as well and I'm seeing test execution error out due to an error code of 12. Here's a screenshot of where I'm seeing this.

Screenshot of Error Code

danlomantoSamsungNext commented 5 years ago

I've also create a repo that can reproduce this issue. Steps to reproduce are in the README.

https://github.com/DanLomanto/mocha-parallel-tests-repro

watson28 commented 5 years ago

Hi @danlomantoSamsungNext I think the problem is related to the -e flag (--eval). I cloned your repo and executed the function in REPL mode and it works. Also, you can create a small index.js file with the same line you are passing to --eval param (require("./.build/test-runner/run-tests.js").runTests()) and it works too.

Is there any reason to execute the tests using --eval ??

danlomantoSamsungNext commented 5 years ago

Thanks for the reply @watson28 !

I think I'm a little confused. I'm not using the -e or --eval flag at all, as far as I can tell. Are you saying that I should be using the eval flag?

watson28 commented 5 years ago

@danlomantoSamsungNext I was following the repo you posted https://github.com/DanLomanto/mocha-parallel-tests-repro.

In steps to reproduce, step 5, the tests are executed using node -e 'require("./.build/test-runner/run-tests.js").runTests()';

That's why I was talking about the -e/--eval flag.

danlomantoSamsungNext commented 5 years ago

Ohhhh I'm sorry! I was thinking about the actual mocha command. I'll give that a try. Thanks!!!

danlomantoSamsungNext commented 5 years ago

That was it, thanks!!!

1999 commented 5 years ago

@watson28 kudos for sorting this out!