Skip to content

Commit

Permalink
test: fixed --watch for global hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
kirrg001 committed Nov 12, 2024
1 parent e80ee65 commit 16341c6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
3 changes: 3 additions & 0 deletions packages/collector/test/apps/agentStubControls.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
19 changes: 17 additions & 2 deletions packages/collector/test/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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();
}
Expand Down

0 comments on commit 16341c6

Please sign in to comment.