Skip to content

Commit

Permalink
fix: use symbol to access suite app (#156)
Browse files Browse the repository at this point in the history
  • Loading branch information
killagu committed Jan 31, 2023
1 parent 6c87625 commit a130dd3
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/inject_context.js
@@ -1,4 +1,6 @@
const assert = require('assert');
const debug = require('util').debuglog('egg-mock:inject_context');
const MOCHA_SUITE_APP = Symbol.for('mocha#suite#app');
const appHandler = require('./app_handler');

/**
Expand Down Expand Up @@ -42,7 +44,7 @@ function injectContext(mocha) {
let errSuite;
try {
await app.ready();
suite.ctx.app = app;
suite.ctx[MOCHA_SUITE_APP] = app;
const mockContextFun = app.mockModuleContextScope || app.mockContextScope;
await mockContextFun.call(app, async function() {
await new Promise(resolve => {
Expand All @@ -67,7 +69,7 @@ function injectContext(mocha) {
return runTests.call(this, suite, fn);
}

const app = suite.ctx.app;
const app = suite.ctx[MOCHA_SUITE_APP];

const self = this;
if (!app) {
Expand All @@ -89,6 +91,7 @@ function injectContext(mocha) {
let app;
try {
app = await appHandler.getApp(suite, test);
assert(app, `not found app for test ${getTestTitle(suite, test)}`);
await app.ready();
} catch (err) {
err.message = `[egg-mock/runTests] get app for ${getTestTitle(suite, test)}: ${err.message}`;
Expand Down

0 comments on commit a130dd3

Please sign in to comment.