diff --git a/package-lock.json b/package-lock.json index c59a9f514ee..f32a5c705a0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -46330,6 +46330,7 @@ "@mongodb-js/prettier-config-compass": "^1.2.0", "@mongodb-js/tsconfig-compass": "^1.2.0", "@types/node": "^20", + "debug": "^4.3.4", "depcheck": "^1.4.1", "eslint": "^7.25.0", "hadron-build": "^25.7.0", @@ -57574,6 +57575,7 @@ "@mongodb-js/prettier-config-compass": "^1.2.0", "@mongodb-js/tsconfig-compass": "^1.2.0", "@types/node": "^20", + "debug": "^4.3.4", "depcheck": "^1.4.1", "eslint": "^7.25.0", "hadron-build": "^25.7.0", diff --git a/packages/compass-smoke-tests/package.json b/packages/compass-smoke-tests/package.json index 4a575b4d78b..37ceae97342 100644 --- a/packages/compass-smoke-tests/package.json +++ b/packages/compass-smoke-tests/package.json @@ -35,6 +35,7 @@ "@mongodb-js/prettier-config-compass": "^1.2.0", "@mongodb-js/tsconfig-compass": "^1.2.0", "depcheck": "^1.4.1", + "debug": "^4.3.4", "eslint": "^7.25.0", "hadron-build": "^25.7.0", "lodash": "^4.17.21", diff --git a/packages/compass-smoke-tests/src/build-info.ts b/packages/compass-smoke-tests/src/build-info.ts index 860bf0a8f41..6b61ffae797 100644 --- a/packages/compass-smoke-tests/src/build-info.ts +++ b/packages/compass-smoke-tests/src/build-info.ts @@ -1,6 +1,7 @@ import assert from 'node:assert/strict'; import fs from 'node:fs'; import path from 'node:path'; +import createDebug from 'debug'; import { handler as writeBuildInfo } from 'hadron-build/commands/info'; @@ -8,6 +9,8 @@ import { type PackageKind } from './packages'; import { type SmokeTestsContextWithSandbox } from './context'; import { pick } from 'lodash'; +const debug = createDebug('compass:smoketests:build-info'); + const SUPPORTED_CHANNELS = ['dev', 'beta', 'stable'] as const; export type Channel = typeof SUPPORTED_CHANNELS[number]; @@ -242,11 +245,11 @@ export function writeAndReadPackageDetails( arch: context.arch, out: path.resolve(context.sandboxPath, 'target.json'), }; - console.log({ infoArgs }); + debug({ infoArgs }); // These are known environment variables that will affect the way // writeBuildInfo works. Log them as a reminder and for our own sanity - console.log( + debug( 'info env vars', pick(process.env, [ 'HADRON_DISTRIBUTION', diff --git a/packages/compass-smoke-tests/src/cli.ts b/packages/compass-smoke-tests/src/cli.ts index 05d9b83e1c2..da495021da4 100755 --- a/packages/compass-smoke-tests/src/cli.ts +++ b/packages/compass-smoke-tests/src/cli.ts @@ -2,6 +2,7 @@ import yargs from 'yargs'; import { hideBin } from 'yargs/helpers'; import { pick } from 'lodash'; +import createDebug from 'debug'; import { SUPPORTED_TESTS } from './tests/types'; import { type SmokeTestsContext } from './context'; import { SUPPORTED_PACKAGES } from './packages'; @@ -9,6 +10,8 @@ import { testTimeToFirstQuery } from './tests/time-to-first-query'; import { testAutoUpdateFrom } from './tests/auto-update-from'; import { testAutoUpdateTo } from './tests/auto-update-to'; +const debug = createDebug('compass:smoketests'); + const SUPPORTED_PLATFORMS = ['win32', 'darwin', 'linux'] as const; const SUPPORTED_ARCHS = ['x64', 'arm64'] as const; @@ -103,9 +106,9 @@ const argv = yargs(hideBin(process.argv)) async function run() { const context: SmokeTestsContext = argv.parseSync(); - console.log(`Running tests`); + debug(`Running tests`); - console.log( + debug( 'context', pick(context, [ 'forceDownload', @@ -119,7 +122,7 @@ async function run() { ); for (const testName of context.tests) { - console.log(testName); + debug(`Running ${testName}`); if (testName === 'time-to-first-query') { await testTimeToFirstQuery(context); @@ -133,7 +136,7 @@ async function run() { run() .then(function () { - console.log('done'); + debug('done'); }) .catch(function (err) { console.error(err.stack); diff --git a/packages/compass-smoke-tests/src/downloads.ts b/packages/compass-smoke-tests/src/downloads.ts index 49ed7815cf8..3bd01a90f58 100644 --- a/packages/compass-smoke-tests/src/downloads.ts +++ b/packages/compass-smoke-tests/src/downloads.ts @@ -2,6 +2,9 @@ import assert from 'node:assert'; import fs from 'node:fs'; import path from 'node:path'; import stream from 'node:stream'; +import createDebug from 'debug'; + +const debug = createDebug('compass:smoketests:downloads'); import { ensureDownloadsDirectory } from './directories'; @@ -33,7 +36,7 @@ export async function downloadFile({ if (clearCache) { fs.rmSync(cacheDirectoryPath, { recursive: true, force: true }); } else { - console.log('Skipped downloading', url, '(cache existed)'); + debug('Skipped downloading', url, '(cache existed)'); return outputPath; } } @@ -44,7 +47,7 @@ export async function downloadFile({ // Write the response to file assert(response.body, 'Expected a response body'); - console.log('Downloading', url); + debug('Downloading', url); await stream.promises.pipeline( response.body, fs.createWriteStream(outputPath) diff --git a/packages/compass-smoke-tests/src/execute.ts b/packages/compass-smoke-tests/src/execute.ts index a6ce9349639..56cdb060cba 100644 --- a/packages/compass-smoke-tests/src/execute.ts +++ b/packages/compass-smoke-tests/src/execute.ts @@ -1,4 +1,7 @@ import { spawn, spawnSync, type SpawnOptions } from 'node:child_process'; +import createDebug from 'debug'; + +const debug = createDebug('compass:smoketests:execute'); export class ExecuteFailure extends Error { constructor( @@ -34,7 +37,7 @@ export function executeAsync( options?: SpawnOptions ): Promise { return new Promise((resolve, reject) => { - console.log(command, ...args); + debug(command, ...args); const child = spawn(command, args, { stdio: 'inherit', ...options, diff --git a/packages/compass-smoke-tests/src/installers/mac-utils.ts b/packages/compass-smoke-tests/src/installers/mac-utils.ts index 335405ab0ab..c6a9a68ff2a 100644 --- a/packages/compass-smoke-tests/src/installers/mac-utils.ts +++ b/packages/compass-smoke-tests/src/installers/mac-utils.ts @@ -2,6 +2,9 @@ import assert from 'node:assert/strict'; import { execSync } from 'node:child_process'; import fs from 'node:fs'; import path from 'node:path'; +import createDebug from 'debug'; + +const debug = createDebug('compass:smoketests:mac-utils'); // TODO: Consider instrumenting the app to use a settings directory in the sandbox export function removeApplicationSupportForApp(appName: string) { @@ -15,7 +18,7 @@ export function removeApplicationSupportForApp(appName: string) { ); if (fs.existsSync(settingsDir)) { - console.log(`${settingsDir} already exists. Removing.`); + debug(`${settingsDir} already exists. Removing.`); fs.rmSync(settingsDir, { recursive: true }); } } diff --git a/packages/compass-smoke-tests/src/installers/windows-msi.ts b/packages/compass-smoke-tests/src/installers/windows-msi.ts index c5a93d15ab5..ebde8d00e37 100644 --- a/packages/compass-smoke-tests/src/installers/windows-msi.ts +++ b/packages/compass-smoke-tests/src/installers/windows-msi.ts @@ -1,8 +1,11 @@ import path from 'node:path'; +import createDebug from 'debug'; import type { InstalledAppInfo, InstallablePackage } from './types'; import { execute, ExecuteFailure } from '../execute'; +const debug = createDebug('compass:smoketests:windows-msi'); + // See https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/msiexec export function installWindowsMSI({ @@ -24,7 +27,7 @@ export function installWindowsMSI({ uninstall(); } catch (err) { if (err instanceof ExecuteFailure && err.status === 1605) { - console.log( + debug( "Uninstalling before installing failed, which is expected if the app wasn't already installed" ); } else { diff --git a/packages/compass-smoke-tests/src/installers/windows-setup.ts b/packages/compass-smoke-tests/src/installers/windows-setup.ts index fd6e4ec4fa3..c9128a107aa 100644 --- a/packages/compass-smoke-tests/src/installers/windows-setup.ts +++ b/packages/compass-smoke-tests/src/installers/windows-setup.ts @@ -2,11 +2,14 @@ import path from 'node:path'; import assert from 'node:assert/strict'; import fs from 'node:fs'; import cp from 'node:child_process'; +import createDebug from 'debug'; import type { InstalledAppInfo, InstallablePackage } from './types'; import { execute } from '../execute'; import * as windowsRegistry from './windows-registry'; +const debug = createDebug('compass:smoketests:windows-setup'); + type UninstallOptions = { /** * Expect the app to already be uninstalled, warn if that's not the case. @@ -51,7 +54,7 @@ export function installWindowsSetup({ typeof uninstallCommand === 'string', 'Expected an UninstallString in the registry entry' ); - console.log(`Running command to uninstall: ${uninstallCommand}`); + debug(`Running command to uninstall: ${uninstallCommand}`); cp.execSync(uninstallCommand, { stdio: 'inherit' }); // Removing the any remaining files manually fs.rmSync(installLocation, { recursive: true, force: true }); diff --git a/packages/compass-smoke-tests/src/tests/auto-update-from.ts b/packages/compass-smoke-tests/src/tests/auto-update-from.ts index dd6f5df0c04..a04fa498691 100644 --- a/packages/compass-smoke-tests/src/tests/auto-update-from.ts +++ b/packages/compass-smoke-tests/src/tests/auto-update-from.ts @@ -1,5 +1,6 @@ import assert from 'node:assert/strict'; import fs from 'node:fs'; +import createDebug from 'debug'; import { type SmokeTestsContext } from '../context'; import { getInstaller } from '../installers'; import { createSandbox } from '../directories'; @@ -7,6 +8,8 @@ import { getTestSubject } from '../test-subject'; import { executeAsync } from '../execute'; import { startAutoUpdateServer } from './update-server'; +const debug = createDebug('compass:smoketests:auto-update-from'); + export async function testAutoUpdateFrom(context: SmokeTestsContext) { const sandboxPath = createSandbox(); const { kind, appName, filepath, autoUpdatable } = await getTestSubject({ @@ -61,7 +64,7 @@ export async function testAutoUpdateFrom(context: SmokeTestsContext) { } ); } finally { - console.log('Stopping auto-update server'); + debug('Stopping auto-update server'); server.close(); delete process.env.UPDATE_CHECKER_ALLOW_DOWNGRADES; } @@ -70,9 +73,9 @@ export async function testAutoUpdateFrom(context: SmokeTestsContext) { } } finally { if (context.skipCleanup) { - console.log(`Skipped cleaning up sandbox: ${sandboxPath}`); + debug(`Skipped cleaning up sandbox: ${sandboxPath}`); } else { - console.log(`Cleaning up sandbox: ${sandboxPath}`); + debug(`Cleaning up sandbox: ${sandboxPath}`); fs.rmSync(sandboxPath, { recursive: true }); } } diff --git a/packages/compass-smoke-tests/src/tests/auto-update-to.ts b/packages/compass-smoke-tests/src/tests/auto-update-to.ts index b3f8e3bba0a..aeecc2f0ad7 100644 --- a/packages/compass-smoke-tests/src/tests/auto-update-to.ts +++ b/packages/compass-smoke-tests/src/tests/auto-update-to.ts @@ -1,5 +1,6 @@ import assert from 'node:assert/strict'; import fs from 'node:fs'; +import createDebug from 'debug'; import { type SmokeTestsContext } from '../context'; import { getInstaller } from '../installers'; import { createSandbox } from '../directories'; @@ -8,6 +9,8 @@ import { executeAsync } from '../execute'; import { getLatestRelease, getLatestReleaseKindByKind } from '../releases'; import { startAutoUpdateServer } from './update-server'; +const debug = createDebug('compass:smoketests:auto-update-to'); + export async function testAutoUpdateTo(context: SmokeTestsContext) { assert( context.bucketKeyPrefix !== undefined, @@ -88,7 +91,7 @@ export async function testAutoUpdateTo(context: SmokeTestsContext) { } ); } finally { - console.log('Stopping auto-update server'); + debug('Stopping auto-update server'); server.close(); delete process.env.DEV_RELEASE; delete process.env.PUBLISHED_RELEASES; @@ -98,9 +101,9 @@ export async function testAutoUpdateTo(context: SmokeTestsContext) { } } finally { if (context.skipCleanup) { - console.log(`Skipped cleaning up sandbox: ${sandboxPath}`); + debug(`Skipped cleaning up sandbox: ${sandboxPath}`); } else { - console.log(`Cleaning up sandbox: ${sandboxPath}`); + debug(`Cleaning up sandbox: ${sandboxPath}`); fs.rmSync(sandboxPath, { recursive: true }); } } diff --git a/packages/compass-smoke-tests/src/tests/time-to-first-query.ts b/packages/compass-smoke-tests/src/tests/time-to-first-query.ts index 9566cb92ffc..376a83713e4 100644 --- a/packages/compass-smoke-tests/src/tests/time-to-first-query.ts +++ b/packages/compass-smoke-tests/src/tests/time-to-first-query.ts @@ -1,10 +1,13 @@ import fs from 'node:fs'; +import createDebug from 'debug'; import { type SmokeTestsContext } from '../context'; import { execute } from '../execute'; import { getInstaller } from '../installers'; import { createSandbox } from '../directories'; import { getTestSubject } from '../test-subject'; +const debug = createDebug('compass:smoketests:time-to-first-query'); + export async function testTimeToFirstQuery(context: SmokeTestsContext) { const sandboxPath = createSandbox(); const { kind, appName, filepath } = await getTestSubject({ @@ -48,9 +51,9 @@ export async function testTimeToFirstQuery(context: SmokeTestsContext) { } } finally { if (context.skipCleanup) { - console.log(`Skipped cleaning up sandbox: ${sandboxPath}`); + debug(`Skipped cleaning up sandbox: ${sandboxPath}`); } else { - console.log(`Cleaning up sandbox: ${sandboxPath}`); + debug(`Cleaning up sandbox: ${sandboxPath}`); fs.rmSync(sandboxPath, { recursive: true }); } } diff --git a/packages/compass-smoke-tests/src/tests/update-server.ts b/packages/compass-smoke-tests/src/tests/update-server.ts index fd0c149213e..3b1019c526a 100644 --- a/packages/compass-smoke-tests/src/tests/update-server.ts +++ b/packages/compass-smoke-tests/src/tests/update-server.ts @@ -1,16 +1,19 @@ import { once } from 'node:events'; +import createDebug from 'debug'; + +const debug = createDebug('compass:smoketests:update-server'); async function importUpdateServer() { try { return (await import('compass-mongodb-com')).default; } catch (err: unknown) { - console.log('Remember to npm link compass-mongodb-com'); + debug('Remember to npm link compass-mongodb-com'); throw err; } } export async function startAutoUpdateServer() { - console.log('Starting auto-update server'); + debug('Starting auto-update server'); const { httpServer, updateChecker, start } = (await importUpdateServer())(); start(); await once(updateChecker, 'refreshed');