Skip to content

Commit 10e4f0d

Browse files
authored
chore(smoketests): use debug rather than console.log (#6701)
use debug rather than console.log
1 parent 5e68065 commit 10e4f0d

File tree

13 files changed

+58
-22
lines changed

13 files changed

+58
-22
lines changed

package-lock.json

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/compass-smoke-tests/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"@mongodb-js/prettier-config-compass": "^1.2.0",
3636
"@mongodb-js/tsconfig-compass": "^1.2.0",
3737
"depcheck": "^1.4.1",
38+
"debug": "^4.3.4",
3839
"eslint": "^7.25.0",
3940
"hadron-build": "^25.7.0",
4041
"lodash": "^4.17.21",

packages/compass-smoke-tests/src/build-info.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
import assert from 'node:assert/strict';
22
import fs from 'node:fs';
33
import path from 'node:path';
4+
import createDebug from 'debug';
45

56
import { handler as writeBuildInfo } from 'hadron-build/commands/info';
67

78
import { type PackageKind } from './packages';
89
import { type SmokeTestsContextWithSandbox } from './context';
910
import { pick } from 'lodash';
1011

12+
const debug = createDebug('compass:smoketests:build-info');
13+
1114
const SUPPORTED_CHANNELS = ['dev', 'beta', 'stable'] as const;
1215

1316
export type Channel = typeof SUPPORTED_CHANNELS[number];
@@ -242,11 +245,11 @@ export function writeAndReadPackageDetails(
242245
arch: context.arch,
243246
out: path.resolve(context.sandboxPath, 'target.json'),
244247
};
245-
console.log({ infoArgs });
248+
debug({ infoArgs });
246249

247250
// These are known environment variables that will affect the way
248251
// writeBuildInfo works. Log them as a reminder and for our own sanity
249-
console.log(
252+
debug(
250253
'info env vars',
251254
pick(process.env, [
252255
'HADRON_DISTRIBUTION',

packages/compass-smoke-tests/src/cli.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@
22
import yargs from 'yargs';
33
import { hideBin } from 'yargs/helpers';
44
import { pick } from 'lodash';
5+
import createDebug from 'debug';
56
import { SUPPORTED_TESTS } from './tests/types';
67
import { type SmokeTestsContext } from './context';
78
import { SUPPORTED_PACKAGES } from './packages';
89
import { testTimeToFirstQuery } from './tests/time-to-first-query';
910
import { testAutoUpdateFrom } from './tests/auto-update-from';
1011
import { testAutoUpdateTo } from './tests/auto-update-to';
1112

13+
const debug = createDebug('compass:smoketests');
14+
1215
const SUPPORTED_PLATFORMS = ['win32', 'darwin', 'linux'] as const;
1316
const SUPPORTED_ARCHS = ['x64', 'arm64'] as const;
1417

@@ -103,9 +106,9 @@ const argv = yargs(hideBin(process.argv))
103106
async function run() {
104107
const context: SmokeTestsContext = argv.parseSync();
105108

106-
console.log(`Running tests`);
109+
debug(`Running tests`);
107110

108-
console.log(
111+
debug(
109112
'context',
110113
pick(context, [
111114
'forceDownload',
@@ -119,7 +122,7 @@ async function run() {
119122
);
120123

121124
for (const testName of context.tests) {
122-
console.log(testName);
125+
debug(`Running ${testName}`);
123126

124127
if (testName === 'time-to-first-query') {
125128
await testTimeToFirstQuery(context);
@@ -133,7 +136,7 @@ async function run() {
133136

134137
run()
135138
.then(function () {
136-
console.log('done');
139+
debug('done');
137140
})
138141
.catch(function (err) {
139142
console.error(err.stack);

packages/compass-smoke-tests/src/downloads.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import assert from 'node:assert';
22
import fs from 'node:fs';
33
import path from 'node:path';
44
import stream from 'node:stream';
5+
import createDebug from 'debug';
6+
7+
const debug = createDebug('compass:smoketests:downloads');
58

69
import { ensureDownloadsDirectory } from './directories';
710

@@ -33,7 +36,7 @@ export async function downloadFile({
3336
if (clearCache) {
3437
fs.rmSync(cacheDirectoryPath, { recursive: true, force: true });
3538
} else {
36-
console.log('Skipped downloading', url, '(cache existed)');
39+
debug('Skipped downloading', url, '(cache existed)');
3740
return outputPath;
3841
}
3942
}
@@ -44,7 +47,7 @@ export async function downloadFile({
4447

4548
// Write the response to file
4649
assert(response.body, 'Expected a response body');
47-
console.log('Downloading', url);
50+
debug('Downloading', url);
4851
await stream.promises.pipeline(
4952
response.body,
5053
fs.createWriteStream(outputPath)

packages/compass-smoke-tests/src/execute.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
import { spawn, spawnSync, type SpawnOptions } from 'node:child_process';
2+
import createDebug from 'debug';
3+
4+
const debug = createDebug('compass:smoketests:execute');
25

36
export class ExecuteFailure extends Error {
47
constructor(
@@ -34,7 +37,7 @@ export function executeAsync(
3437
options?: SpawnOptions
3538
): Promise<void> {
3639
return new Promise((resolve, reject) => {
37-
console.log(command, ...args);
40+
debug(command, ...args);
3841
const child = spawn(command, args, {
3942
stdio: 'inherit',
4043
...options,

packages/compass-smoke-tests/src/installers/mac-utils.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import assert from 'node:assert/strict';
22
import { execSync } from 'node:child_process';
33
import fs from 'node:fs';
44
import path from 'node:path';
5+
import createDebug from 'debug';
6+
7+
const debug = createDebug('compass:smoketests:mac-utils');
58

69
// TODO: Consider instrumenting the app to use a settings directory in the sandbox
710
export function removeApplicationSupportForApp(appName: string) {
@@ -15,7 +18,7 @@ export function removeApplicationSupportForApp(appName: string) {
1518
);
1619

1720
if (fs.existsSync(settingsDir)) {
18-
console.log(`${settingsDir} already exists. Removing.`);
21+
debug(`${settingsDir} already exists. Removing.`);
1922
fs.rmSync(settingsDir, { recursive: true });
2023
}
2124
}

packages/compass-smoke-tests/src/installers/windows-msi.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import path from 'node:path';
2+
import createDebug from 'debug';
23

34
import type { InstalledAppInfo, InstallablePackage } from './types';
45
import { execute, ExecuteFailure } from '../execute';
56

7+
const debug = createDebug('compass:smoketests:windows-msi');
8+
69
// See https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/msiexec
710

811
export function installWindowsMSI({
@@ -24,7 +27,7 @@ export function installWindowsMSI({
2427
uninstall();
2528
} catch (err) {
2629
if (err instanceof ExecuteFailure && err.status === 1605) {
27-
console.log(
30+
debug(
2831
"Uninstalling before installing failed, which is expected if the app wasn't already installed"
2932
);
3033
} else {

packages/compass-smoke-tests/src/installers/windows-setup.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@ import path from 'node:path';
22
import assert from 'node:assert/strict';
33
import fs from 'node:fs';
44
import cp from 'node:child_process';
5+
import createDebug from 'debug';
56

67
import type { InstalledAppInfo, InstallablePackage } from './types';
78
import { execute } from '../execute';
89
import * as windowsRegistry from './windows-registry';
910

11+
const debug = createDebug('compass:smoketests:windows-setup');
12+
1013
type UninstallOptions = {
1114
/**
1215
* Expect the app to already be uninstalled, warn if that's not the case.
@@ -51,7 +54,7 @@ export function installWindowsSetup({
5154
typeof uninstallCommand === 'string',
5255
'Expected an UninstallString in the registry entry'
5356
);
54-
console.log(`Running command to uninstall: ${uninstallCommand}`);
57+
debug(`Running command to uninstall: ${uninstallCommand}`);
5558
cp.execSync(uninstallCommand, { stdio: 'inherit' });
5659
// Removing the any remaining files manually
5760
fs.rmSync(installLocation, { recursive: true, force: true });

packages/compass-smoke-tests/src/tests/auto-update-from.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
import assert from 'node:assert/strict';
22
import fs from 'node:fs';
3+
import createDebug from 'debug';
34
import { type SmokeTestsContext } from '../context';
45
import { getInstaller } from '../installers';
56
import { createSandbox } from '../directories';
67
import { getTestSubject } from '../test-subject';
78
import { executeAsync } from '../execute';
89
import { startAutoUpdateServer } from './update-server';
910

11+
const debug = createDebug('compass:smoketests:auto-update-from');
12+
1013
export async function testAutoUpdateFrom(context: SmokeTestsContext) {
1114
const sandboxPath = createSandbox();
1215
const { kind, appName, filepath, autoUpdatable } = await getTestSubject({
@@ -61,7 +64,7 @@ export async function testAutoUpdateFrom(context: SmokeTestsContext) {
6164
}
6265
);
6366
} finally {
64-
console.log('Stopping auto-update server');
67+
debug('Stopping auto-update server');
6568
server.close();
6669
delete process.env.UPDATE_CHECKER_ALLOW_DOWNGRADES;
6770
}
@@ -70,9 +73,9 @@ export async function testAutoUpdateFrom(context: SmokeTestsContext) {
7073
}
7174
} finally {
7275
if (context.skipCleanup) {
73-
console.log(`Skipped cleaning up sandbox: ${sandboxPath}`);
76+
debug(`Skipped cleaning up sandbox: ${sandboxPath}`);
7477
} else {
75-
console.log(`Cleaning up sandbox: ${sandboxPath}`);
78+
debug(`Cleaning up sandbox: ${sandboxPath}`);
7679
fs.rmSync(sandboxPath, { recursive: true });
7780
}
7881
}

0 commit comments

Comments
 (0)