Skip to content

Commit b813577

Browse files
committed
refactor: safer test folder teardown and clean test folder init
1 parent 9589010 commit b813577

File tree

4 files changed

+28
-17
lines changed

4 files changed

+28
-17
lines changed

e2e/cli-e2e/tests/__snapshots__/help.e2e.test.ts.snap

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ Global Options:
2121
--progress Show progress bar in stdout.
2222
[boolean] [default: true]
2323
--verbose When true creates more verbose output. This is helpful w
24-
hen debugging. [boolean] [default: false]
24+
hen debugging. You may also set CP_VERBOSE env variable
25+
instead. [boolean] [default: false]
2526
--config Path to config file. By default it loads code-pushup.con
2627
fig.(ts|mjs|js). [string]
2728
--tsconfig Path to a TypeScript config, to be used when loading con
@@ -65,9 +66,9 @@ Examples:
6566
code-pushup collect --onlyPlugins=covera Run collect with only coverage plugi
6667
ge n, other plugins from config file wi
6768
ll be skipped.
68-
code-pushup collect --skipPlugins=covera Run collect skiping the coverage plu
69-
ge gin, other plugins from config file
70-
will be included.
69+
code-pushup collect --skipPlugins=covera Run collect skipping the coverage pl
70+
ge ugin, other plugins from config file
71+
will be included.
7172
code-pushup upload --persist.outputDir=d Upload dist/report.json to portal us
7273
ist --upload.apiKey=$CP_API_KEY ing API key from environment variabl
7374
e

packages/cli/README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -195,12 +195,12 @@ Each example is fully tested to demonstrate best practices for plugin testing as
195195

196196
### Global Options
197197

198-
| Option | Type | Default | Description |
199-
| ---------------- | --------- | -------------------------------------------- | ---------------------------------------------------------------------- |
200-
| **`--progress`** | `boolean` | `true` | Show progress bar in stdout. |
201-
| **`--verbose`** | `boolean` | `false` | When true creates more verbose output. This is helpful when debugging. |
202-
| **`--config`** | `string` | looks for `code-pushup.config.{ts\|mjs\|js}` | Path to config file. |
203-
| **`--tsconfig`** | `string` | n/a | Path to a TypeScript config, used to load config file. |
198+
| Option | Type | Default | Description |
199+
| ---------------- | --------- | -------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------- |
200+
| **`--progress`** | `boolean` | `true` | Show progress bar in stdout. |
201+
| **`--verbose`** | `boolean` | `false` | When true creates more verbose output. This is helpful when debugging. You may also set `CP_VERBOSE` env variable instead. |
202+
| **`--config`** | `string` | looks for `code-pushup.config.{ts\|mjs\|js}` | Path to config file. |
203+
| **`--tsconfig`** | `string` | n/a | Path to a TypeScript config, used to load config file. |
204204

205205
> [!NOTE]
206206
> By default, the CLI loads `code-pushup.config.(ts|mjs|js)` if no config path is provided with `--config`.

packages/cli/src/lib/cli.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export const cli = (args: string[]) =>
2525
],
2626
[
2727
'code-pushup collect --skipPlugins=coverage',
28-
'Run collect skiping the coverage plugin, other plugins from config file will be included.',
28+
'Run collect skipping the coverage plugin, other plugins from config file will be included.',
2929
],
3030
[
3131
'code-pushup upload --persist.outputDir=dist --upload.apiKey=$CP_API_KEY',

testing/test-setup/src/lib/test-folder.setup.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,27 @@
11
import { logger } from '@nx/devkit';
22
import { bold } from 'ansis';
3-
import { mkdir, rm } from 'node:fs/promises';
4-
5-
export async function setupTestFolder(dirName: string) {
6-
await mkdir(dirName, { recursive: true });
7-
}
3+
import { mkdir, rm, stat } from 'node:fs/promises';
84

95
export async function cleanTestFolder(dirName: string) {
10-
await rm(dirName, { recursive: true, force: true });
6+
await teardownTestFolder(dirName);
117
await mkdir(dirName, { recursive: true });
128
}
139

1410
export async function teardownTestFolder(dirName: string) {
11+
try {
12+
const stats = await stat(dirName);
13+
if (!stats.isDirectory()) {
14+
logger.warn(
15+
`⚠️ You are trying to delete single file instead of directory ${bold(
16+
dirName,
17+
)}.`,
18+
);
19+
}
20+
} catch {
21+
// continue safely without deleting as folder does not exist in the filesystem
22+
return;
23+
}
24+
1525
try {
1626
await rm(dirName, {
1727
recursive: true,

0 commit comments

Comments
 (0)