Skip to content

Commit b5822c9

Browse files
committed
Enhance test logging
1 parent c6dc8ad commit b5822c9

26 files changed

+60
-181
lines changed

packages/create-next-stack/package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,12 @@
5151
"build": "rimraf lib && tsc --build",
5252
"clean": "rimraf lib && pnpm run clean-tests-dir",
5353
"clean-tests-dir": "ts-node src/tests/e2e/clean-tests-dir.ts",
54-
"test": "pnpm build && node lib/tests/e2e/test.js",
55-
"test:manual": "pnpm build && node lib/tests/e2e/test-manual.js --debug",
56-
"test:small": "pnpm build && node lib/tests/e2e/test-manual.js --debug --package-manager=pnpm --styling=css-modules",
57-
"test:large": "pnpm build && node lib/tests/e2e/test-manual.js --debug --package-manager=pnpm --styling=emotion --react-hook-form --formik --prettier --formatting-pre-commit-hook --chakra --framer-motion --github-actions",
58-
"test:cna": "pnpm build && node lib/tests/e2e/test-live-cna.js",
59-
"test:cns": "pnpm build && node lib/tests/e2e/test-live-cns.js",
54+
"test": "pnpm build && ts-node src/tests/e2e/test.ts",
55+
"test:manual": "pnpm build && ts-node src/tests/e2e/test-manual.ts --debug",
56+
"test:small": "pnpm build && ts-node src/tests/e2e/test-manual.ts --debug --package-manager=pnpm --styling=css-modules",
57+
"test:large": "pnpm build && ts-node src/tests/e2e/test-manual.ts --debug --package-manager=pnpm --styling=emotion --react-hook-form --formik --prettier --formatting-pre-commit-hook --chakra --framer-motion --github-actions",
58+
"test:cna": "pnpm build && ts-node src/tests/e2e/test-live-cna.ts",
59+
"test:cns": "pnpm build && ts-node src/tests/e2e/test-live-cns.ts",
6060
"print:help": "pnpm build && ./bin/dev --help",
6161
"print:version": "pnpm build && ./bin/dev --help",
6262
"version": "oclif-dev readme && git add README.md",
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export const inDebugMode = (): boolean => process.env["DEBUG"] === "true"
2+
export const inTestMode = (): boolean => process.env["TEST"] === "true"

packages/create-next-stack/src/main/helpers/run-command.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ export const runCommand = (
88
options?: Options
99
): ExecaChildProcess<string> => {
1010
logDebug("Running command:", prettyCommand(file, args))
11+
logDebug("Running command in:", options?.cwd ?? process.cwd())
1112
return execa(file, args, options)
1213
}

packages/create-next-stack/src/main/logging.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import chalk from "chalk"
2-
import { inDebugMode } from "./helpers/in-debug-mode"
2+
import { inDebugMode, inTestMode } from "./helpers/in-debug-mode"
33
import { prefixLines } from "./helpers/prefix-lines"
44

55
const infoPrefix = chalk.cyan("info ")
@@ -12,7 +12,7 @@ export const logInfo = (...strings: string[]): void => {
1212
}
1313

1414
export const logDebug = (...strings: string[]): void => {
15-
if (inDebugMode()) {
15+
if (inDebugMode() || inTestMode()) {
1616
console.debug(prefixLines(debugPrefix, chalk.white(strings.join(" "))))
1717
}
1818
}

packages/create-next-stack/src/tests/e2e/clean-tests-dir.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import fs from "fs/promises"
22
import path from "path"
33
;(async () => {
4+
process.env["TEST"] = "true"
5+
46
const testsDirectory = path.resolve(
57
__dirname,
68
"../../../../../../create-next-stack-tests"
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import chalk from "chalk"
2+
import { logTestInfo } from "../test-logging"
3+
4+
export const logTestMeta = (testName: string, testFilePath: string): void => {
5+
logTestInfo(chalk.yellow`Running test: ${testName}`)
6+
logTestInfo(`Test file path: ${testFilePath}`)
7+
}

packages/create-next-stack/src/tests/e2e/test-live-cna.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import chalk from "chalk"
22
import endent from "endent"
33
import { v4 as uuidv4 } from "uuid"
4-
import { prettyCommand } from "../../main/helpers/pretty-command"
54
import { runCommand } from "../../main/helpers/run-command"
65
import { exitWithError } from "./helpers/exit-with-error"
76
import { logTestInfo } from "./test-logging"
87
;(async () => {
8+
process.env["TEST"] = "true"
9+
910
try {
1011
const projectName = uuidv4()
1112
const runDirectory = `../../../create-next-stack-tests/${projectName}`
@@ -17,7 +18,6 @@ import { logTestInfo } from "./test-logging"
1718
...process.argv.slice(2),
1819
]
1920

20-
logTestInfo("Running command:", prettyCommand(command, args))
2121
await runCommand(command, args, { stdio: "inherit" })
2222

2323
logTestInfo("")

packages/create-next-stack/src/tests/e2e/test-live-cns.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import chalk from "chalk"
22
import endent from "endent"
33
import { v4 as uuidv4 } from "uuid"
4-
import { prettyCommand } from "../../main/helpers/pretty-command"
54
import { runCommand } from "../../main/helpers/run-command"
65
import { checkFormattingLintingBuild } from "./helpers/check-formatting-linting-build"
76
import { exitWithError } from "./helpers/exit-with-error"
87
import { logTestInfo } from "./test-logging"
98
;(async () => {
9+
process.env["TEST"] = "true"
10+
1011
try {
1112
const projectName = uuidv4()
1213
const runDirectory = `../../../create-next-stack-tests/${projectName}`
@@ -18,8 +19,6 @@ import { logTestInfo } from "./test-logging"
1819
runDirectory,
1920
]
2021

21-
logTestInfo("Running command:", prettyCommand(command, args))
22-
2322
await runCommand(command, args, { stdio: "inherit" })
2423

2524
await checkFormattingLintingBuild(runDirectory)

packages/create-next-stack/src/tests/e2e/test-manual.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,19 @@
11
import chalk from "chalk"
22
import endent from "endent"
33
import { v4 as uuidv4 } from "uuid"
4-
import { prettyCommand } from "../../main/helpers/pretty-command"
54
import { runCommand } from "../../main/helpers/run-command"
65
import { checkFormattingLintingBuild } from "./helpers/check-formatting-linting-build"
76
import { exitWithError } from "./helpers/exit-with-error"
87
import { logTestInfo } from "./test-logging"
98
;(async () => {
9+
process.env["TEST"] = "true"
10+
1011
try {
1112
const projectName = uuidv4()
1213
const runDirectory = `../../../create-next-stack-tests/${projectName}`
1314

1415
const pathToCLI = "./bin/dev"
1516
const args = [...process.argv.slice(2), runDirectory]
16-
logTestInfo(
17-
"Running command:",
18-
prettyCommand(pathToCLI, args),
19-
"in directory:",
20-
runDirectory
21-
)
2217
await runCommand(pathToCLI, args, { stdio: "inherit" })
2318

2419
await checkFormattingLintingBuild(runDirectory)

packages/create-next-stack/src/tests/e2e/test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import { testYarn } from "./tests/test-yarn"
2121
;(async () => {
2222
// TODO: Find a way to run tests in parallel. Currently failing because simultaneous calls to `npm i -g yarn` or `npm install -g mrm@^3.0.0 mrm-task-lint-staged@^6.0.0` cause crashes.
2323

24+
process.env["TEST"] = "true"
25+
2426
try {
2527
// If not done already, Set Git name and email so `git commit` doesn't fail during create-next-app
2628
await setGitNameAndEmail()

0 commit comments

Comments
 (0)