Skip to content

Commit 16341c6

Browse files
committed
test: fixed --watch for global hooks
refs mochajs/mocha#5149
1 parent e80ee65 commit 16341c6

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

Diff for: packages/collector/test/apps/agentStubControls.js

+3
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,9 @@ class AgentStubControls {
162162
}
163163

164164
async reset() {
165+
// eslint-disable-next-line no-console
166+
console.log(`[AgentStubControls] reset ${this.agentPort}`);
167+
165168
return retry(async () => {
166169
await fetch(`http://127.0.0.1:${this.agentPort}/`, {
167170
method: 'DELETE',

Diff for: packages/collector/test/hooks.js

+17-2
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,20 @@
1010
// scripts for running tests take care of that.
1111
//
1212
// The globalAgent module manages an agent stub instance that can be used globally for all tests.
13-
14-
const { startGlobalAgent, stopGlobalAgent } = require('./globalAgent');
13+
const path = require('path');
1514
const isCI = require('@instana/core/test/test_util/is_ci');
1615
const config = require('@instana/core/test/config');
1716
const fs = require('fs');
1817

1918
exports.mochaHooks = {
2019
async beforeAll() {
20+
// NOTE: mocha --watch has a bug (https://github.com/mochajs/mocha/issues/5149)
21+
// We manually clear the file from the cache here.
22+
const globalAgentModulePath = path.resolve(__dirname, './globalAgent');
23+
delete require.cache[globalAgentModulePath];
24+
25+
const { startGlobalAgent } = require('./globalAgent');
26+
2127
// eslint-disable-next-line no-console
2228
console.log(`@instana/collector test suite starting at ${timestamp()}.`);
2329
this.timeout(config.getTestTimeout());
@@ -54,6 +60,15 @@ exports.mochaHooks = {
5460
},
5561

5662
async afterAll() {
63+
// NOTE: mocha --watch has a bug (https://github.com/mochajs/mocha/issues/5149)
64+
// We manually clear the file from the cache here.
65+
const globalAgentModulePath = path.resolve(__dirname, './globalAgent');
66+
delete require.cache[globalAgentModulePath];
67+
68+
const { stopGlobalAgent } = require('./globalAgent');
69+
70+
// eslint-disable-next-line no-console
71+
console.log(`@instana/collector test suite stopping at ${timestamp()}.`);
5772
this.timeout(config.getTestTimeout());
5873
await stopGlobalAgent();
5974
}

0 commit comments

Comments
 (0)