karma-runner / karma-mocha

A Karma plugin. Adapter for Mocha testing framework.
MIT License
379 stars 94 forks source link

Await before `mocha.run` and support `mocha.requireHooks` #245

Open loynoir opened 3 years ago

loynoir commented 3 years ago

Related issues

https://github.com/karma-runner/karma-mocha/issues/243

Changes

  1. Await all script type="module" before mocha.run. If await failed, add a unit test, and throw error within.
  2. Remove lib/adapter.js from gitignore, so can use npm install <repo>.
  3. mocha.requireHooks now supported, load thru {type:"import", value:"/base/my/path/to/mochaHooks.mjs"}
  4. Add unit test to verify mocha.requireHooks.beforeAll works.
  5. Using mocha.requireHooks.afterAll to verify mocha.run run after all slow ESM modules.
  6. devDependencies updated, to support requireHooks and type = 'module'

```txt Uncaught TypeError: this[opt] is not a function ``` Update mocha from 3.5.3 to 9.1.3, to support rootHooks ```txt Uncaught SyntaxError: Unexpected token 'export' ``` Update karma from 1.7.1 to 6.3.6, to support files.type = 'module' ```txt WARN [karma-server]: Passing raw CLI options to `new Server(config, done)` is deprecated. Use `parseConfig(c onfigFilePath, cliOptions, {promiseConfig: true, throwErrors: true})` to prepare a processed `Config` instance and pass that as the `config` argument instead. ``` Update grunt-karma from 2.0.0 to 4.0.2, to get rid of warning.

  1. README.md updated for requireHooks

TODO

  1. import(), reported SyntaxError by low version eslint
  2. Remove importSync() and importSyncFallback() when mocha accept serializable .requireHooks, or accept import() as .requireHooks input.
scottohara commented 2 years ago

Is there any likelihood of this PR getting merged, or is karma-mocha essentially an abandoned/unmaintained project at this point?

(Please accept that this is a genuine question, I'm not trying to be rude.)

It's been a while since I've done anything with karma, but recently I had cause to revisit an old project to upgrade the version of sinon.js it used, and in the process I discovered that as of SinonJS v11, potential memory leaks are reported and the recommendation is to call sinon.restore() in an afterEach hook of every test suite.

This would seem to be a perfect use case for Mocha v8.0.0+ root hooks, hence what has led me to this PR.

I also note that in https://github.com/karma-runner/karma-mocha/issues/209 it was mentioned that

218 should allow release to be driven by successful post-commit tests.

...but it is unclear what in practice that means for this project as there has only been 1 release since that comment, despite the backlog of PRs such as this one that appear to have passed all checks?

If the answer is that yes, there are no maintainers and/or volunteers are wanted (which is perfectly understandable), perhaps a note could be added to the README?