-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: use mocha global hook to register before/after
- Loading branch information
Showing
5 changed files
with
50 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
let agent; | ||
|
||
const Agent = require('./parallel/agent'); | ||
const { getEggOptions } = require('./utils'); | ||
|
||
exports.setupAgent = async () => { | ||
if (process.env.ENABLE_MOCHA_PARALLEL && process.env.AUTO_AGENT) { | ||
agent = Agent(getEggOptions()); | ||
await agent.ready(); | ||
} | ||
return agent; | ||
}; | ||
|
||
exports.closeAgent = async () => { | ||
if (agent) { | ||
await agent.close(); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,3 @@ | ||
const Agent = require('./agent'); | ||
const { getEggOptions } = require('../utils'); | ||
const mock = require('../../index').default; | ||
console.warn('[deprecated] use `egg-mock/register.js` instead of `egg-mock/lib/parallel/agent_register.js`'); | ||
|
||
let agent; | ||
exports.mochaGlobalSetup = async () => { | ||
agent = Agent(getEggOptions()); | ||
await agent.ready(); | ||
}; | ||
|
||
exports.mochaGlobalTeardown = async () => { | ||
if (agent) { | ||
await agent.close(); | ||
} | ||
}; | ||
|
||
exports.mochaHooks = { | ||
async beforeAll() { | ||
const { app } = require('../../bootstrap'); | ||
if (app) { | ||
await app.ready(); | ||
} | ||
}, | ||
async afterEach() { | ||
const { app } = require('../../bootstrap'); | ||
if (app) { | ||
await app.backgroundTasksFinished(); | ||
} | ||
await mock.restore(); | ||
}, | ||
}; | ||
module.exports = require('../../register'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
const mock = require('./index').default; | ||
const agent = require('./lib/agent'); | ||
|
||
exports.mochaGlobalSetup = async () => { | ||
await agent.setupAgent(); | ||
}; | ||
|
||
exports.mochaGlobalTeardown = async () => { | ||
await agent.closeAgent(); | ||
}; | ||
|
||
exports.mochaHooks = { | ||
async beforeAll() { | ||
const { app } = require('./bootstrap'); | ||
if (app) { | ||
await app.ready(); | ||
} | ||
}, | ||
async afterEach() { | ||
const { app } = require('./bootstrap'); | ||
if (app) { | ||
await app.backgroundTasksFinished(); | ||
} | ||
await mock.restore(); | ||
}, | ||
}; |