Skip to content

Commit e4fb99d

Browse files
committed
feature: Adding debug logging
1 parent d171af0 commit e4fb99d

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@eresearchqut/jest-testcontainers",
3-
"version": "3.6.0",
3+
"version": "3.6.1",
44
"description": "Jest preset for starting docker containers that stay up while your tests run.",
55
"main": "dist/index",
66
"types": "dist/index",

src/environment.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
import { readFileSync } from "fs";
22
import NodeEnvironment from "jest-environment-node";
3-
import { join } from "path";
43
import { Script } from "vm";
4+
import {log} from "./logger";
5+
import {GLOBAL_VARS_JSON_PATH} from "./setup";
56

6-
const GLOBAL_VARS_JSON_PATH = join(__dirname, "global.vars.json");
77

88
export function setGlobalsWithJsonString(globals: any, jsonString: string) {
99
const globalVars = JSON.parse(jsonString);
1010
const globalVarKeys = Object.keys(globalVars);
1111

1212
globalVarKeys.forEach(globalVarKey => {
13+
log.debug(`${globals[globalVarKey]}=${globalVars[globalVarKey]}`);
1314
// @ts-ignore
1415
globals[globalVarKey] = globalVars[globalVarKey];
16+
1517
});
1618
}
1719

@@ -22,8 +24,8 @@ export class TestcontainersEnvironment extends NodeEnvironment {
2224
}
2325

2426
public async setup() {
27+
log.debug(`Reading global vars from ${GLOBAL_VARS_JSON_PATH}`);
2528
const globalVarsJsonString = readFileSync(GLOBAL_VARS_JSON_PATH, "utf-8");
26-
2729
setGlobalsWithJsonString(this.global, globalVarsJsonString);
2830
await super.setup();
2931
}

src/setup.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ import {
66
startAllContainers
77
} from "./containers";
88

9-
import { log } from "./logger";
109

11-
const GLOBAL_VARS_JSON_PATH = join(__dirname, "global.vars.json");
10+
11+
export const GLOBAL_VARS_JSON_PATH = join(__dirname, "global.vars.json");
1212
const createEnv = (name: string, key: string) =>
1313
`__TESTCONTAINERS_${name.toUpperCase()}_${key.toUpperCase()}__`;
1414

@@ -48,7 +48,7 @@ async function setup(opts: any) {
4848
allStartedContainersMetaInfo
4949
);
5050

51-
log.debug(`Writing global env: ${JSON.stringify({location: GLOBAL_VARS_JSON_PATH, globalEnv})}`);
51+
5252
writeFileSync(GLOBAL_VARS_JSON_PATH, JSON.stringify(globalEnv), "utf-8");
5353
// @ts-ignore
5454
global.__TESTCONTAINERS__ = Object.values(allStartedContainersMetaInfo).map(

0 commit comments

Comments
 (0)