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

❓A global before in parallel mode. #4424

Closed
sarbbottam opened this issue Aug 26, 2020 · 4 comments
Closed

❓A global before in parallel mode. #4424

sarbbottam opened this issue Aug 26, 2020 · 4 comments
Labels
duplicate been there, done that, got the t-shirt...

Comments

@sarbbottam
Copy link

mocha version: 8.10

//.mocharc.yml
file: 'lib/utils/setup.js'
require: 'lib/bootstrap.js'
//lib/utils/setup.js
const {environment} = require('./environment.js');
const {TIMEOUT_DURATION, TEST_USERS} = require('../configs/test-config.js');
const { cacheCookies } = require('./cookie-jar');

const roles = Object.keys(TEST_USERS[environment]);
// for the current environment create login session for all the test users
before(async function() {``
  this.timeout(TIMEOUT_DURATION * roles.length);
  console.log('warming up cookie jar for all the test users');
  return cacheCookies(environment);
});

When I run mocha --exit it works fine, however when I run mocha -p --exit I get the following error

ERROR: --parallel runs test files in a non-deterministic order, and is mutually exclusive with --file

How can I have a global before in parallel mode?

Thanks!

@nicojs
Copy link
Contributor

nicojs commented Aug 27, 2020

I think you're looking for the root hooks plugin system, right? It works with --parallel and non-parallel mode. (introduced in 7.2)

@sarbbottam
Copy link
Author

Thanks, @nicojs for sharing your thoughts.

beforeAll:

  • In serial mode (Mocha’s default), before all tests begin, once only
  • In parallel mode, run before all tests begin, for each file

I am wondering if there is a way to run the beforeAll or something similar only once not for each file in parallel mode.

@nicojs nicojs added the duplicate been there, done that, got the t-shirt... label Aug 28, 2020
@nicojs
Copy link
Contributor

nicojs commented Aug 28, 2020

Ah, thanks for the clarification. I think #4360 is what you're looking for. Marking it as a duplicate, if you disagree please let me know.

Duplicate of: #4308

@sarbbottam
Copy link
Author

Thank you @nicojs, yea this is the same as #4308.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate been there, done that, got the t-shirt...
Projects
None yet
Development

No branches or pull requests

2 participants