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

RFC: Test runner integration #14

Closed
krzkaczor opened this issue May 14, 2020 · 3 comments
Closed

RFC: Test runner integration #14

krzkaczor opened this issue May 14, 2020 · 3 comments

Comments

@krzkaczor
Copy link
Contributor

Test runner integration (beforeEach/afterEach) /should be implemented to avoid repetition and hard to spot bugs. I propose to not worry about parallel test execution at this stage.

What should happen during integration?

Autoload all earl plugins (with external matchers).

After each test:

Before each test:

  • set context for earl like earl.setContext({name: "testSuite/testName"}) That would allow implementation of snapshots without a need to provide a name for it (same interface as jest). I don't want to dive into this now since I am not sure if we want to implement snapshots at all 🤔

How integration should look like

Perfectly it would be as simple as -r earl/integrate-mocha but I am not sure if this can be done like this or we need to force users to add somewhere in there test suite snippet like:

beforeEach(earl.beforeEach)
afterEach(earl.afterEach)

I think earl should ship with integrations for most popular test runners (at least for mocha).

@krzkaczor
Copy link
Contributor Author

krzkaczor commented May 14, 2020

I did a quick prototype. As I was suspecting, during require phase mocha is not yet fully initialized but you can just wait till it is :-> This works: (I am not sure if it's reliable)

async function main() {
  // sync setup like discovering and loading plugins

  // we need to delay execution after mocha finishes initialization
  await Promise.resolve()

  beforeEach(function(){
    console.log("Setting earl!")
    console.log(this.currentTest)
  })
}

main()

and it's super easy to configure with .mocharc.js just by placing:

module.exports = {
  require: ["earl/mocha"],
  // ...
};

@krzkaczor
Copy link
Contributor Author

Mocha's team works on "Root Hook Plugins", this would allow earl to work in parallel mode in mocha:

mochajs/mocha#4244

@krzkaczor
Copy link
Contributor Author

Basic implementation was just merged. I realized that it needs a little bit more work to properly support mocks created outside of "it" block.

@krzkaczor krzkaczor changed the title Test runner integration RFC: Test runner integration May 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant