From 586cd0a33fd9d7823edc0ba12fe2be73d8772651 Mon Sep 17 00:00:00 2001 From: kirrg001 Date: Mon, 11 Nov 2024 13:12:33 +0100 Subject: [PATCH] test: fixed --watch for global hooks refs https://github.com/mochajs/mocha/issues/5149 --- .../collector/test/apps/agentStubControls.js | 3 +++ packages/collector/test/hooks.js | 19 +++++++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/packages/collector/test/apps/agentStubControls.js b/packages/collector/test/apps/agentStubControls.js index 2d59175437..eee7a6c027 100644 --- a/packages/collector/test/apps/agentStubControls.js +++ b/packages/collector/test/apps/agentStubControls.js @@ -162,6 +162,9 @@ class AgentStubControls { } async reset() { + // eslint-disable-next-line no-console + console.log(`[AgentStubControls] reset ${this.agentPort}`); + return retry(async () => { await fetch(`http://127.0.0.1:${this.agentPort}/`, { method: 'DELETE', diff --git a/packages/collector/test/hooks.js b/packages/collector/test/hooks.js index da53944bee..71b4909bb6 100644 --- a/packages/collector/test/hooks.js +++ b/packages/collector/test/hooks.js @@ -10,14 +10,20 @@ // scripts for running tests take care of that. // // The globalAgent module manages an agent stub instance that can be used globally for all tests. - -const { startGlobalAgent, stopGlobalAgent } = require('./globalAgent'); +const path = require('path'); const isCI = require('@instana/core/test/test_util/is_ci'); const config = require('@instana/core/test/config'); const fs = require('fs'); exports.mochaHooks = { async beforeAll() { + // NOTE: mocha --watch has a bug (https://github.com/mochajs/mocha/issues/5149) + // We manually clear the file from the cache here. + const globalAgentModulePath = path.resolve(__dirname, './globalAgent'); + delete require.cache[globalAgentModulePath]; + + const { startGlobalAgent } = require('./globalAgent'); + // eslint-disable-next-line no-console console.log(`@instana/collector test suite starting at ${timestamp()}.`); this.timeout(config.getTestTimeout()); @@ -54,6 +60,15 @@ exports.mochaHooks = { }, async afterAll() { + // NOTE: mocha --watch has a bug (https://github.com/mochajs/mocha/issues/5149) + // We manually clear the file from the cache here. + const globalAgentModulePath = path.resolve(__dirname, './globalAgent'); + delete require.cache[globalAgentModulePath]; + + const { stopGlobalAgent } = require('./globalAgent'); + + // eslint-disable-next-line no-console + console.log(`@instana/collector test suite stopping at ${timestamp()}.`); this.timeout(config.getTestTimeout()); await stopGlobalAgent(); }