@tsparticles/cli 3.2.2 → 3.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,138 @@
1
- Testing
2
- - Vitest configuration present
3
- - Run with pnpm test
1
+ # Testing Patterns
2
+
3
+ **Analysis Date:** 2026-03-08
4
+
5
+ ## Test Framework
6
+
7
+ **Runner:**
8
+
9
+ - Vitest (`vitest`) - configured in `vitest.config.ts` with `environment: "node"` and `include: ["tests/**/*.test.ts"]`.
10
+
11
+ Config: `vitest.config.ts`
12
+
13
+ Run Commands:
14
+
15
+ ```bash
16
+ pnpm test # Run all tests (runs `vitest run` as defined in package.json)
17
+ pnpm test --watch # Run in watch mode (Vitest supports --watch)
18
+ pnpm test --coverage # Coverage if configured via vitest options (not explicitly configured here)
19
+ ```
20
+
21
+ ## Test File Organization
22
+
23
+ Location:
24
+
25
+ - Tests live under `tests/` at the repo root: `tests/*.test.ts` (e.g., `tests/create-shape.test.ts`, `tests/file-utils.test.ts`).
26
+
27
+ Naming:
28
+
29
+ - Test files use the pattern `<feature>.test.ts` (Vitest `include` config picks `tests/**/*.test.ts`).
30
+
31
+ Structure:
32
+
33
+ ```
34
+ tests/
35
+ ├── create-shape.test.ts
36
+ ├── create-preset.test.ts
37
+ ├── create-plugin.test.ts
38
+ ├── file-utils.test.ts
39
+ └── string-utils.test.ts
40
+ ```
41
+
42
+ ## Test Structure
43
+
44
+ Suite Organization (example from `tests/create-shape.test.ts`):
45
+
46
+ ```ts
47
+ import { describe, it, expect } from "vitest";
48
+ import { createShapeTemplate } from "../src/create/shape/create-shape.js";
49
+
50
+ describe("create-shape", () => {
51
+ it("should have created the shape project", async () => {
52
+ // arrange: compute destDir
53
+ // act: call createShapeTemplate
54
+ // assert: read package.json and assert properties using fs-extra
55
+ });
56
+ });
57
+ ```
58
+
59
+ Patterns:
60
+
61
+ - Tests create temporary directories under `tests/tmp-files` and remove them after assertions (`fs-extra` used to clean up).
62
+ - Tests use actual file system operations to verify template creation (integration-style unit tests).
63
+
64
+ Setup/Teardown:
65
+
66
+ - Tests manually create and remove directories within each test case (no global setup file detected).
67
+
68
+ ## Mocking
69
+
70
+ Framework: Vitest built-in mocking utilities are available but not heavily used in current tests.
71
+
72
+ Patterns:
73
+
74
+ - Tests primarily exercise filesystem operations without mocking `fs-extra` or child processes. When external commands are invoked, the code checks for the presence of `npm` using `lookpath` before running `exec` which avoids executing if not present.
75
+
76
+ What to Mock:
77
+
78
+ - When adding unit tests for functions that call `exec` or modify the environment, mock `child_process.exec` or `lookpath` to avoid running external processes.
79
+
80
+ What NOT to Mock:
81
+
82
+ - For integration-style tests that verify file scaffolding, prefer real `fs` operations in a temporary directory to validate end-to-end behavior.
83
+
84
+ ## Fixtures and Factories
85
+
86
+ Test Data:
87
+
88
+ - Tests programmatically generate temporary directories under `tests/tmp-files` and use template functions to create artifacts. No centralized fixtures directory is present.
89
+
90
+ Location:
91
+
92
+ - Temporary test artifacts are created in `tests/tmp-files` during tests and cleaned up by tests (see `tests/create-shape.test.ts`).
93
+
94
+ ## Coverage
95
+
96
+ Requirements: None enforced in repo. CI runs `pnpm test` but coverage thresholds are not configured.
97
+
98
+ View Coverage:
99
+
100
+ ```bash
101
+
102
+ ```
103
+
104
+ ## Test Types
105
+
106
+ Unit Tests:
107
+
108
+ - Small utilities tested (e.g., `tests/file-utils.test.ts`, `tests/string-utils.test.ts`).
109
+
110
+ Integration Tests:
111
+
112
+ - Template creation tests behave like integration tests, performing file operations and validating outputs (`tests/create-*.test.ts`).
113
+
114
+ E2E Tests:
115
+
116
+ - Not used.
117
+
118
+ ## Common Patterns
119
+
120
+ Async Testing:
121
+
122
+ ```ts
123
+ it("does async work", async () => {
124
+ await expect(someAsyncFn()).resolves.toBeTruthy();
125
+ });
126
+ ```
127
+
128
+ Error Testing:
129
+
130
+ ```ts
131
+ it("throws on bad input", async () => {
132
+ await expect(badAsync()).rejects.toThrow();
133
+ });
134
+ ```
135
+
136
+ ---
137
+
138
+ _Testing analysis: 2026-03-08_
@@ -9,7 +9,7 @@ export async function bundle(basePath, silent) {
9
9
  if (!silent) {
10
10
  console.log("Bundling started");
11
11
  }
12
- let res = false;
12
+ let res;
13
13
  try {
14
14
  const options = (await import(path.join(basePath, "webpack.config.js")));
15
15
  res = await new Promise((resolve, reject) => {
@@ -9,7 +9,7 @@ export async function clearDist(basePath, silent) {
9
9
  if (!silent) {
10
10
  console.log("Clearing dist folder");
11
11
  }
12
- let res = false;
12
+ let res;
13
13
  try {
14
14
  await rimraf(path.join(basePath, "dist"));
15
15
  res = true;
@@ -15,11 +15,11 @@ export declare function prettifySrc(basePath: string, srcPath: string, ci: boole
15
15
  export declare function prettifyPackageJson(basePath: string, ci: boolean, silent: boolean): Promise<boolean>;
16
16
  /**
17
17
  * @param basePath -
18
- * @param _ci -
18
+ * @param ci -
19
19
  * @param silent -
20
20
  * @returns true if the prettify package.dist.json process was successful
21
21
  */
22
- export declare function prettifyPackageDistJson(basePath: string, _ci: boolean, silent: boolean): Promise<boolean>;
22
+ export declare function prettifyPackageDistJson(basePath: string, ci: boolean, silent: boolean): Promise<boolean>;
23
23
  /**
24
24
  * @param basePath -
25
25
  * @param ci -
@@ -85,11 +85,11 @@ export async function prettifyPackageJson(basePath, ci, silent) {
85
85
  }
86
86
  /**
87
87
  * @param basePath -
88
- * @param _ci -
88
+ * @param ci -
89
89
  * @param silent -
90
90
  * @returns true if the prettify package.dist.json process was successful
91
91
  */
92
- export async function prettifyPackageDistJson(basePath, _ci, silent) {
92
+ export async function prettifyPackageDistJson(basePath, ci, silent) {
93
93
  if (!silent) {
94
94
  console.log("Prettier - started on package.dist.json");
95
95
  }
@@ -100,15 +100,15 @@ export async function prettifyPackageDistJson(basePath, _ci, silent) {
100
100
  options.printWidth = 120;
101
101
  options.endOfLine = "lf";
102
102
  options.parser = "json";
103
- // TODO: disabled this check until "prettier-plugin-multiline-arrays" package is compatible with Prettier 3.0.0
104
- /* if (ci) {
105
- if (!(await prettier.check(contents, options))) {
106
- throw new Error(`package.dist.json is not formatted correctly`);
107
- }
108
- } else { */
109
- const formatted = await prettier.format(contents, options);
110
- await fs.writeFile("package.dist.json", formatted, "utf8");
111
- // }
103
+ if (ci) {
104
+ if (!(await prettier.check(contents, options))) {
105
+ throw new Error(`package.dist.json is not formatted correctly`);
106
+ }
107
+ }
108
+ else {
109
+ const formatted = await prettier.format(contents, options);
110
+ await fs.writeFile("package.dist.json", formatted, "utf8");
111
+ }
112
112
  res = true;
113
113
  }
114
114
  catch (e) {