Skip to content

Commit

Permalink
use debug() to properly log debug statements
Browse files Browse the repository at this point in the history
  • Loading branch information
mansona committed Jul 17, 2023
1 parent b639caa commit 649404b
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
33 changes: 21 additions & 12 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 6 additions & 7 deletions tests/helpers/meta-helpers.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import debug from 'debug';
import assert from 'node:assert';
import fs from 'node:fs/promises';
import path from 'node:path';
Expand All @@ -6,16 +7,16 @@ 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.
* tl;dr:
* 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
*
Expand All @@ -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 =
Expand Down Expand Up @@ -83,7 +82,7 @@ export class AddonHelper {
}

async clean() {
if (DEBUG) return;
if (process.env.SKIP_CLEANUP) return;

assert(
this.#tmpDir,
Expand Down
16 changes: 10 additions & 6 deletions tests/helpers/utils.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import debug from 'debug';
import { type Options, execa } from 'execa';
import fse from 'fs-extra';
import fs from 'node:fs/promises';
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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 649404b

Please sign in to comment.