@testspectra/react 1.1.8-rc.12 → 1.1.8-rc.15
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.
- package/dist/cli.js +34 -7
- package/dist/index.js +45 -8
- package/package.json +4 -2
package/dist/cli.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
// src/cli.ts
|
|
2
|
-
import
|
|
2
|
+
import spawn from "cross-spawn";
|
|
3
|
+
import path from "node:path";
|
|
3
4
|
import { fileURLToPath } from "node:url";
|
|
4
5
|
async function runComponentTests(options = {}) {
|
|
5
|
-
const
|
|
6
|
+
const rawCwd = options.cwd ?? process.cwd();
|
|
7
|
+
const cwd = path.resolve(rawCwd);
|
|
6
8
|
const configPath = fileURLToPath(new URL("../vitest.config.ts", import.meta.url));
|
|
7
9
|
const ext = process.platform === "win32" ? ".cmd" : "";
|
|
8
10
|
const vitestBin = fileURLToPath(new URL(`../node_modules/.bin/vitest${ext}`, import.meta.url));
|
|
@@ -11,7 +13,11 @@ async function runComponentTests(options = {}) {
|
|
|
11
13
|
args.push("--reporter=default", "--reporter=json", `--outputFile.json=${options.outputFile}`);
|
|
12
14
|
}
|
|
13
15
|
if (options.spec) {
|
|
14
|
-
|
|
16
|
+
let specPattern = options.spec.replace(/\\/g, "/");
|
|
17
|
+
if (path.isAbsolute(options.spec)) {
|
|
18
|
+
specPattern = path.relative(cwd, options.spec).replace(/\\/g, "/");
|
|
19
|
+
}
|
|
20
|
+
args.push(specPattern);
|
|
15
21
|
}
|
|
16
22
|
const semanticReporter = Boolean(options.onLine);
|
|
17
23
|
return new Promise((resolve) => {
|
|
@@ -20,14 +26,13 @@ async function runComponentTests(options = {}) {
|
|
|
20
26
|
cwd,
|
|
21
27
|
env: {
|
|
22
28
|
...process.env,
|
|
23
|
-
TESTSPECTRA_TEST_ROOT: cwd,
|
|
29
|
+
TESTSPECTRA_TEST_ROOT: cwd.replace(/\\/g, "/"),
|
|
24
30
|
TESTSPECTRA_HEADLESS: options.headless === false ? "false" : "true",
|
|
25
31
|
TESTSPECTRA_STEP_DELAY: String(options.stepDelayMs ?? 0),
|
|
26
32
|
TESTSPECTRA_FILE_PARALLELISM: options.concurrency === 1 ? "false" : "true",
|
|
27
33
|
...options.browserExecutablePath ? { TESTSPECTRA_BROWSER_EXECUTABLE: options.browserExecutablePath } : {},
|
|
28
34
|
TESTSPECTRA_SEMANTIC_REPORTER: semanticReporter ? "1" : "0"
|
|
29
|
-
}
|
|
30
|
-
shell: process.platform === "win32"
|
|
35
|
+
}
|
|
31
36
|
});
|
|
32
37
|
if (semanticReporter) {
|
|
33
38
|
const handleData = (buf) => {
|
|
@@ -64,7 +69,29 @@ async function runCli(argv = process.argv.slice(2)) {
|
|
|
64
69
|
const parsed = parseInt(String(rawDelay), 10);
|
|
65
70
|
if (!isNaN(parsed) && parsed >= 0) stepDelayMs = parsed;
|
|
66
71
|
}
|
|
67
|
-
|
|
72
|
+
let spec = getFlagValue(argv, "--spec", "-s");
|
|
73
|
+
if (!spec) {
|
|
74
|
+
const flagsWithValues = /* @__PURE__ */ new Set([
|
|
75
|
+
"--step-delay",
|
|
76
|
+
"--delay",
|
|
77
|
+
"--spec",
|
|
78
|
+
"-s",
|
|
79
|
+
"--output",
|
|
80
|
+
"-o",
|
|
81
|
+
"--concurrency",
|
|
82
|
+
"-c",
|
|
83
|
+
"--browser-executable"
|
|
84
|
+
]);
|
|
85
|
+
for (let i = 1; i < argv.length; i++) {
|
|
86
|
+
const arg = argv[i];
|
|
87
|
+
if (arg.startsWith("-")) {
|
|
88
|
+
if (flagsWithValues.has(arg)) i++;
|
|
89
|
+
} else {
|
|
90
|
+
spec = arg;
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
68
95
|
const outputFile = getFlagValue(argv, "--output", "-o");
|
|
69
96
|
const rawConcurrency = getFlagValue(argv, "--concurrency", "-c");
|
|
70
97
|
let concurrency;
|
package/dist/index.js
CHANGED
|
@@ -51,6 +51,14 @@ var DomDriverBridge = class {
|
|
|
51
51
|
"Spectra.navigate() is not supported in component testing mode. Use Spectra.mount(<Component />) to render a component tree instead of navigating a URL."
|
|
52
52
|
);
|
|
53
53
|
}
|
|
54
|
+
async setCookies(setCookieHeaders, _url) {
|
|
55
|
+
const headers = Array.isArray(setCookieHeaders) ? setCookieHeaders : [setCookieHeaders];
|
|
56
|
+
for (const header of headers) {
|
|
57
|
+
if (typeof document !== "undefined") {
|
|
58
|
+
document.cookie = header;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
54
62
|
async back() {
|
|
55
63
|
throw new Error("Spectra.back() is not supported in component testing mode.");
|
|
56
64
|
}
|
|
@@ -284,7 +292,9 @@ var DomDriverBridge = class {
|
|
|
284
292
|
}
|
|
285
293
|
async shouldHaveNoConsoleErrors() {
|
|
286
294
|
if (this.consoleErrors.length > 0) {
|
|
287
|
-
throw new Error(
|
|
295
|
+
throw new Error(
|
|
296
|
+
`Expected no console errors, but found ${this.consoleErrors.length}: ${this.consoleErrors.join("; ")}`
|
|
297
|
+
);
|
|
288
298
|
}
|
|
289
299
|
}
|
|
290
300
|
async clearCookies() {
|
|
@@ -337,10 +347,12 @@ async function mount(element) {
|
|
|
337
347
|
}
|
|
338
348
|
|
|
339
349
|
// src/cli.ts
|
|
340
|
-
import
|
|
350
|
+
import spawn from "cross-spawn";
|
|
351
|
+
import path from "node:path";
|
|
341
352
|
import { fileURLToPath } from "node:url";
|
|
342
353
|
async function runComponentTests(options = {}) {
|
|
343
|
-
const
|
|
354
|
+
const rawCwd = options.cwd ?? process.cwd();
|
|
355
|
+
const cwd = path.resolve(rawCwd);
|
|
344
356
|
const configPath = fileURLToPath(new URL("../vitest.config.ts", import.meta.url));
|
|
345
357
|
const ext = process.platform === "win32" ? ".cmd" : "";
|
|
346
358
|
const vitestBin = fileURLToPath(new URL(`../node_modules/.bin/vitest${ext}`, import.meta.url));
|
|
@@ -349,7 +361,11 @@ async function runComponentTests(options = {}) {
|
|
|
349
361
|
args.push("--reporter=default", "--reporter=json", `--outputFile.json=${options.outputFile}`);
|
|
350
362
|
}
|
|
351
363
|
if (options.spec) {
|
|
352
|
-
|
|
364
|
+
let specPattern = options.spec.replace(/\\/g, "/");
|
|
365
|
+
if (path.isAbsolute(options.spec)) {
|
|
366
|
+
specPattern = path.relative(cwd, options.spec).replace(/\\/g, "/");
|
|
367
|
+
}
|
|
368
|
+
args.push(specPattern);
|
|
353
369
|
}
|
|
354
370
|
const semanticReporter = Boolean(options.onLine);
|
|
355
371
|
return new Promise((resolve) => {
|
|
@@ -358,14 +374,13 @@ async function runComponentTests(options = {}) {
|
|
|
358
374
|
cwd,
|
|
359
375
|
env: {
|
|
360
376
|
...process.env,
|
|
361
|
-
TESTSPECTRA_TEST_ROOT: cwd,
|
|
377
|
+
TESTSPECTRA_TEST_ROOT: cwd.replace(/\\/g, "/"),
|
|
362
378
|
TESTSPECTRA_HEADLESS: options.headless === false ? "false" : "true",
|
|
363
379
|
TESTSPECTRA_STEP_DELAY: String(options.stepDelayMs ?? 0),
|
|
364
380
|
TESTSPECTRA_FILE_PARALLELISM: options.concurrency === 1 ? "false" : "true",
|
|
365
381
|
...options.browserExecutablePath ? { TESTSPECTRA_BROWSER_EXECUTABLE: options.browserExecutablePath } : {},
|
|
366
382
|
TESTSPECTRA_SEMANTIC_REPORTER: semanticReporter ? "1" : "0"
|
|
367
|
-
}
|
|
368
|
-
shell: process.platform === "win32"
|
|
383
|
+
}
|
|
369
384
|
});
|
|
370
385
|
if (semanticReporter) {
|
|
371
386
|
const handleData = (buf) => {
|
|
@@ -402,7 +417,29 @@ async function runCli(argv = process.argv.slice(2)) {
|
|
|
402
417
|
const parsed = parseInt(String(rawDelay), 10);
|
|
403
418
|
if (!isNaN(parsed) && parsed >= 0) stepDelayMs = parsed;
|
|
404
419
|
}
|
|
405
|
-
|
|
420
|
+
let spec = getFlagValue(argv, "--spec", "-s");
|
|
421
|
+
if (!spec) {
|
|
422
|
+
const flagsWithValues = /* @__PURE__ */ new Set([
|
|
423
|
+
"--step-delay",
|
|
424
|
+
"--delay",
|
|
425
|
+
"--spec",
|
|
426
|
+
"-s",
|
|
427
|
+
"--output",
|
|
428
|
+
"-o",
|
|
429
|
+
"--concurrency",
|
|
430
|
+
"-c",
|
|
431
|
+
"--browser-executable"
|
|
432
|
+
]);
|
|
433
|
+
for (let i = 1; i < argv.length; i++) {
|
|
434
|
+
const arg = argv[i];
|
|
435
|
+
if (arg.startsWith("-")) {
|
|
436
|
+
if (flagsWithValues.has(arg)) i++;
|
|
437
|
+
} else {
|
|
438
|
+
spec = arg;
|
|
439
|
+
break;
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
}
|
|
406
443
|
const outputFile = getFlagValue(argv, "--output", "-o");
|
|
407
444
|
const rawConcurrency = getFlagValue(argv, "--concurrency", "-c");
|
|
408
445
|
let concurrency;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@testspectra/react",
|
|
3
|
-
"version": "1.1.8-rc.
|
|
3
|
+
"version": "1.1.8-rc.15",
|
|
4
4
|
"description": "Bundled Vitest browser-mode runner for React component testing with the TestSpectra Spectra.* DSL",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"testspectra",
|
|
@@ -38,15 +38,17 @@
|
|
|
38
38
|
"@testing-library/user-event": "^14.5.2",
|
|
39
39
|
"@vitejs/plugin-react": "^4.3.1",
|
|
40
40
|
"@vitest/browser": "^2.1.8",
|
|
41
|
+
"cross-spawn": "^7.0.6",
|
|
41
42
|
"playwright": "^1.48.0",
|
|
42
43
|
"vitest": "^2.1.8",
|
|
43
|
-
"@testspectra/matchers": "1.1.8-rc.
|
|
44
|
+
"@testspectra/matchers": "1.1.8-rc.15"
|
|
44
45
|
},
|
|
45
46
|
"peerDependencies": {
|
|
46
47
|
"react": ">=18.0.0",
|
|
47
48
|
"react-dom": ">=18.0.0"
|
|
48
49
|
},
|
|
49
50
|
"devDependencies": {
|
|
51
|
+
"@types/cross-spawn": "^6.0.6",
|
|
50
52
|
"@types/node": "^20.14.0",
|
|
51
53
|
"@types/react": "^18.3.3",
|
|
52
54
|
"@types/react-dom": "^18.3.0",
|