Skip to content
This repository has been archived by the owner on Dec 28, 2023. It is now read-only.

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
lib/adapter.js
# lib/adapter.js
node_modules
npm-debug.log
.idea
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,35 @@ module.exports = function(config) {
};
```

If you want to use rootHooks, convert to ESM module file.
```js
mocha.setup({
...
rootHooks: {afterAll},
})
```
```js
// <project>/path/to/myMochaHooks.mjs
export const mochaHooks = {afterAll}
```

```js
module.exports = function(config) {
config.set({
...
client: {
mocha: {
rootHooks: {
type: 'import',
value: '/base/path/to/myMochaHooks.mjs'
}
}
...
}
});
};
```

## Internals

On the end of each test `karma-mocha` passes to `karma` result object with fields:
Expand Down
30 changes: 28 additions & 2 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,15 @@ module.exports = function (config) {

files: [
'src/*.js',
'test/src/*.js'
'test/**/*.js',
{
pattern: 'test/**/*.mjs',
type: 'module'
}
],
exclude: [
// exclude nodejs only stuff
'test/lib/index.spec.js'
],

browsers: process.env.TRAVIS ? ['Firefox'] : ['Chrome'],
Expand All @@ -17,6 +25,24 @@ module.exports = function (config) {
'karma-sinon',
'karma-firefox-launcher',
'karma-chrome-launcher'
]
],

client: {
mocha: {
rootHooks: {
type: 'import',
value: '/base/test/esm/mochaHooks.mjs'
}
},

mocha$Unsupported: {
rootHooks: {
beforeAll () {
throw new Error('not supported')
}
}
}

}
})
}
Loading