From 649404bd1df90b0471e17c46864a6f0f430ef495 Mon Sep 17 00:00:00 2001 From: Chris Manson Date: Mon, 17 Jul 2023 16:40:26 +0100 Subject: [PATCH] use debug() to properly log debug statements --- .github/workflows/ci.yml | 2 +- pnpm-lock.yaml | 33 +++++++++++++++++++++------------ tests/helpers/meta-helpers.ts | 13 ++++++------- tests/helpers/utils.ts | 16 ++++++++++------ tests/package.json | 2 ++ 5 files changed, 40 insertions(+), 26 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c70b2532..c83a3557 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -69,5 +69,5 @@ jobs: - uses: actions/checkout@v3 - uses: ./.github/actions/pnpm - run: pnpm add --global ember-cli yarn - - run: DEBUG=true pnpm vitest --testNamePattern "${{ matrix.slow-test }}" + - run: DEBUG=addon-blueprint:utils pnpm vitest --testNamePattern "${{ matrix.slow-test }}" working-directory: tests diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 3026800e..dce5443a 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -63,6 +63,9 @@ importers: tests: devDependencies: + '@types/debug': + specifier: ^4.1.8 + version: 4.1.8 '@types/fs-extra': specifier: ^9.0.13 version: 9.0.13 @@ -72,9 +75,12 @@ importers: c8: specifier: ^7.11.3 version: 7.11.3 + debug: + specifier: ^4.3.4 + version: 4.3.4 ember-cli: specifier: ember-cli/ember-cli#master - version: github.com/ember-cli/ember-cli/695e0f3524be9f6431d924627d64ecf625c0e868 + version: github.com/ember-cli/ember-cli/695e0f3524be9f6431d924627d64ecf625c0e868(debug@4.3.4) execa: specifier: ^6.1.0 version: 6.1.0 @@ -984,8 +990,8 @@ packages: '@types/node': 18.0.4 dev: true - /@types/debug@4.1.7: - resolution: {integrity: sha512-9AonUzyTjXXhEOa0DnqpzZi6VHlqKMswga9EXjpXnnqxwLtdvPPtlO8evrI5D9S6asFRCQ6v+wpiUKbw+vKqyg==} + /@types/debug@4.1.8: + resolution: {integrity: sha512-/vPO1EPOs306Cvhwv7KfVfYvOJqA/S/AXjaHQiJboCZzcNDb+TIJFN9/2C9DZ//ijSKWioNyUxD792QmDJ+HKQ==} dependencies: '@types/ms': 0.7.31 dev: true @@ -4467,7 +4473,7 @@ packages: resolution: {integrity: sha512-0sQoMh9s0BYsm+12Huy/rkKxVu4R1+r96YX5cG44rHV0pQ6iC3Q+mkoMFaGWObMFYQxCVT+ssG1ksneA2MI9KQ==} dev: true - /follow-redirects@1.15.2: + /follow-redirects@1.15.2(debug@4.3.4): resolution: {integrity: sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==} engines: {node: '>=4.0'} peerDependencies: @@ -4475,6 +4481,8 @@ packages: peerDependenciesMeta: debug: optional: true + dependencies: + debug: 4.3.4 dev: true /for-in@1.0.2: @@ -5236,12 +5244,12 @@ packages: - supports-color dev: true - /http-proxy@1.18.1: + /http-proxy@1.18.1(debug@4.3.4): resolution: {integrity: sha512-7mz/721AbnJwIVbnaSv1Cz3Am0ZLT/UBwkC92VlxhXv/k/BBQfM2fXElQNC27BVGr0uwUpplYPQM9LnaBMR5NQ==} engines: {node: '>=8.0.0'} dependencies: eventemitter3: 4.0.7 - follow-redirects: 1.15.2 + follow-redirects: 1.15.2(debug@4.3.4) requires-port: 1.0.0 transitivePeerDependencies: - debug @@ -6717,7 +6725,7 @@ packages: /micromark@3.1.0: resolution: {integrity: sha512-6Mj0yHLdUZjHnOPgr5xfWIMqMWS12zDN6iws9SLuSz76W8jTtAv24MN4/CL7gJrl5vtxGInkkqDv/JIoRsQOvA==} dependencies: - '@types/debug': 4.1.7 + '@types/debug': 4.1.8 debug: 4.3.4 decode-named-character-reference: 1.0.2 micromark-core-commonmark: 1.0.6 @@ -8927,7 +8935,7 @@ packages: minimatch: 3.1.2 dev: true - /testem@3.10.1: + /testem@3.10.1(debug@4.3.4): resolution: {integrity: sha512-42c4e7qlAelwMd8O3ogtVGRbgbr6fJnX6H51ACOIG1V1IjsKPlcQtxPyOwaL4iikH22Dfh+EyIuJnMG4yxieBQ==} engines: {node: '>= 7.*'} hasBin: true @@ -8943,7 +8951,7 @@ packages: express: 4.18.2 fireworm: 0.7.2 glob: 7.2.3 - http-proxy: 1.18.1 + http-proxy: 1.18.1(debug@4.3.4) js-yaml: 3.14.1 lodash.assignin: 4.2.0 lodash.castarray: 4.4.0 @@ -9932,8 +9940,9 @@ packages: engines: {node: '>=10'} dev: true - github.com/ember-cli/ember-cli/695e0f3524be9f6431d924627d64ecf625c0e868: + github.com/ember-cli/ember-cli/695e0f3524be9f6431d924627d64ecf625c0e868(debug@4.3.4): resolution: {tarball: https://codeload.github.com/ember-cli/ember-cli/tar.gz/695e0f3524be9f6431d924627d64ecf625c0e868} + id: github.com/ember-cli/ember-cli/695e0f3524be9f6431d924627d64ecf625c0e868 name: ember-cli version: 5.2.0-beta.0 engines: {node: '>= 16'} @@ -9987,7 +9996,7 @@ packages: heimdalljs-fs-monitor: 1.1.1 heimdalljs-graph: 1.0.0 heimdalljs-logger: 0.1.10 - http-proxy: 1.18.1 + http-proxy: 1.18.1(debug@4.3.4) inflection: 2.0.1 inquirer: 9.2.7 is-git-url: 1.0.0 @@ -10018,7 +10027,7 @@ packages: sort-package-json: 1.57.0 symlink-or-copy: 1.3.1 temp: 0.9.4 - testem: 3.10.1 + testem: 3.10.1(debug@4.3.4) tiny-lr: 2.0.0 tree-sync: 2.1.0 uuid: 9.0.0 diff --git a/tests/helpers/meta-helpers.ts b/tests/helpers/meta-helpers.ts index 47880026..ff9575c6 100644 --- a/tests/helpers/meta-helpers.ts +++ b/tests/helpers/meta-helpers.ts @@ -1,3 +1,4 @@ +import debug from 'debug'; import assert from 'node:assert'; import fs from 'node:fs/promises'; import path from 'node:path'; @@ -6,7 +7,7 @@ import { matchesFixture } from './assertions.js'; import { copyFixture } from './fixtures.js'; import { createAddon, createTmp, install, runScript } from './utils.js'; -const DEBUG = process.env.DEBUG === 'true'; +const debugLog = debug('addon-blueprint:temp'); /** * Helps with common addon testing concerns. @@ -14,8 +15,8 @@ const DEBUG = process.env.DEBUG === 'true'; * it's a wrapper around ember addon -b (so we can pass our flags with less duplication) * it lets us set compare against a fixture set / scenario * - * To DEBUG the intermediate output (in tmp), - * re-start your tests with `DEBUG=true`, and the tmpdir will be printed + * To debug the intermediate output (in tmp), + * re-start your tests with `DEBUG=addon-blueprint:temp`, and the tmpdir will be printed * as well as the `clean` function will not run so that if a test finishes, * you can still inspect the folder contents * @@ -42,9 +43,7 @@ export class AddonHelper { async setup() { this.#tmpDir = await createTmp(); - if (DEBUG) { - console.debug(`Debug test repo at ${this.#tmpDir}`); - } + debugLog(`Debug test repo at ${this.#tmpDir}`); let args = [...this.#args]; let needsPackageManagerSet = @@ -83,7 +82,7 @@ export class AddonHelper { } async clean() { - if (DEBUG) return; + if (process.env.SKIP_CLEANUP) return; assert( this.#tmpDir, diff --git a/tests/helpers/utils.ts b/tests/helpers/utils.ts index e5af01d2..fe04dcd0 100644 --- a/tests/helpers/utils.ts +++ b/tests/helpers/utils.ts @@ -1,3 +1,4 @@ +import debug from 'debug'; import { type Options, execa } from 'execa'; import fse from 'fs-extra'; import fs from 'node:fs/promises'; @@ -5,7 +6,8 @@ import os from 'node:os'; import path from 'node:path'; import { fileURLToPath } from 'node:url'; -const DEBUG = process.env.DEBUG === 'true'; +const debugLog = debug('addon-blueprint:utils'); + const __dirname = path.dirname(fileURLToPath(import.meta.url)); // repo-root @@ -91,7 +93,11 @@ export async function runScript({ let promise = execa(packageManager, ['run', script], { cwd }); try { - await promise; + const result = await promise; + + debugLog(`Finished running script ${script}`); + debugLog(result.stdout); + debugLog(result.stderr); return promise; } catch (e) { @@ -131,10 +137,8 @@ export async function createAddon({ }) { let emberCliArgs = ['addon', name, '-b', blueprintPath, '--skip-npm', '--skip-git', ...args]; - if (DEBUG) { - console.debug(`Running ember-cli in ${options.cwd}`); - console.debug(`\tember ${emberCliArgs.join(' ')}`); - } + debugLog(`Running ember-cli in ${options.cwd}`); + debugLog(`\tember ${emberCliArgs.join(' ')}`); let result = await execa('ember', emberCliArgs, { ...options, diff --git a/tests/package.json b/tests/package.json index 1c3edb16..0f9d7520 100644 --- a/tests/package.json +++ b/tests/package.json @@ -6,9 +6,11 @@ "test": "pnpm vitest" }, "devDependencies": { + "@types/debug": "^4.1.8", "@types/fs-extra": "^9.0.13", "@vitest/ui": "^0.18.0", "c8": "^7.11.3", + "debug": "^4.3.4", "ember-cli": "ember-cli/ember-cli#master", "execa": "^6.1.0", "fixturify": "^3.0.0",