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

How to refactor global hooks ? #203

Open
BourgoisMickael opened this issue Aug 14, 2019 · 1 comment
Open

How to refactor global hooks ? #203

BourgoisMickael opened this issue Aug 14, 2019 · 1 comment
Labels

Comments

@BourgoisMickael
Copy link
Contributor

I'd like to comply to mocha/no-top-level-hooks but I'm using global hooks to initialize my tests, an init.js file is executed before all of my tests:

const helper = require('./helper')

// GLOBAL HOOKS
before(async function () {
  // Make a connection to the database to be used in all tests
  await helper.db.start()
  // Run the server
  helper.app.run()
})

// Used to gracefully shutdown at the end
after(async function () {
  const server = helper.app.getServer()
  server.close()
  await helper.db.stop()
})

Note that in all my tests I have an afterEach hook to clean the db

With this implementation all my tests (107) are executed in 2 seconds.
However, I tried to move that in beforeEach and afterEach in all my tests files to see if I can run the setup in each tests an now all the tests are executed in 2 minutes.

So should I just turn off this rule or is there a way to replace global hooks but keep nice performances ?

@rosschapman
Copy link

If @BourgoisMickael is using "globals" to refer to Root Hook Plugins, then I have the same question and a potential suggestion. The suggestion being to add an argument to this rule definition that accepts an array of root hook file names, which will then be excluded from the linter parsing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants