mocha-parallel / mocha-parallel-tests

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

Type​Error: "x" is not a constructor #240

Open fasatrix opened 5 years ago

fasatrix commented 5 years ago

Hi, I am experiencing the following error running one of my test suites.

Command: mocha-parallel-tests --opts ./mocha.opts --max-parallel 5 --slow 50

mocha.opts content as follows --reporter mocha-jenkins-reporter --timeout 300000 --require ts-node/register --require tsconfig-paths/register tests/*/.ts

error: testfile.ts:15 const httpService: ApiService = new ApiService();

class instance : const httpService: ApiService = new ApiService();

class constructor:

constructor( jwtType: JWTType = 'defaultValue' ) {
    this._environmentUrl = `${environmentUrl}`;
    this.jwtType = jwtType ;
}

Any help would be much appreciated Thanks

1999 commented 5 years ago

Thanks for posting this issue @fasatrix. Still, it's not enough information to reproduce this issue.

  1. Does it happen when you run tests in only one file testfile.ts? Can you publish it here?
  2. Could you please show the whole stack trace with --full-trace?
  3. Does this error occur when you run your tests with mocha?
  4. Can you publish any small repo where this error is reproducible?
fasatrix commented 5 years ago

HI , thanks for the quick response.

1) I am not sure what answer to this question, parallel test will run the entire suite which is comprised of several files and folders. What I have noticed is that if I reduce the number of threads to 1 then the tests start being executed and only when the runner gets to the one that instantiate the class breaks. 2) the output of this command (mocha-parallel-tests --opts ./mocha.opts --max-parallel 5 --slow 50 --full-trace) does produce the same results as if --full-trace was not included, I added more info from the error below 3) No it does not this is the reason of why I believe there might be a bug with the package 4) Sorry I am unable to share/publish the repo unfortunately as it is sensitive

TypeError: api_services_1.ApiService is not a constructor at Object. (C:\dev\repo\mocha-test\services\apiservice.ts:15:33) at Module._compile (internal/modules/cjs/loader.js:701:30) at Module.m._compile (C:\dev\repo\mocha-test\node_modules\ts-node\src\index.ts:403:23) at Module._extensions..js (internal/modules/cjs/loader.js:712:10) at Object.require.extensions.(anonymous function) [as .ts] (C:\dev\repo\mocha-test\node_modules\ts-node\src\index.ts:406:12) at Module.load (internal/modules/cjs/loader.js:600:32) at tryModuleLoad (internal/modules/cjs/loader.js:539:12) at Function.Module._load (internal/modules/cjs/loader.js:531:3) at Module.require (internal/modules/cjs/loader.js:637:17) at require (internal/modules/cjs/helpers.js:22:18)

1999 commented 5 years ago

This will be hard to reproduce since we have only these two things as an input:

mocha.opts file

--reporter mocha-jenkins-reporter
--timeout 300000
--require ts-node/register
--require tsconfig-paths/register
tests/**/*.ts

And some test TS file with this:

type JWTType = 'defaultValue';

class ApiService {
  _environmentUrl: string;
  jwtType: JWTType;

  constructor( jwtType: JWTType = 'defaultValue' ) {
    this._environmentUrl = `${environmentUrl}`;
    this.jwtType = jwtType ;
  }
}

describe('suite', () => {
  it('case', () => {
    const obj = new ApiService();
  });
});

If it works, I will not have any other ideas other than close this issue.

fasatrix commented 5 years ago

No worries lets close it

1999 commented 5 years ago

Nah, let's keep it open so that someone can take a look at it.