@testpulse.run/reporter 0.1.1 → 0.1.2
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/fixtures/options.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { resolveTestPulseEndpoint } from "../shared/endpoint.js";
|
|
2
2
|
export function resolveTestPulseFixturesOptions(options = {}, environment = process.env) {
|
|
3
|
-
const enabled = options.enabled ?? environment.TESTPULSE_ENABLE_LIVE_STREAMING
|
|
3
|
+
const enabled = options.enabled ?? parseOptionalBoolean(environment.TESTPULSE_ENABLE_LIVE_STREAMING) ?? true;
|
|
4
4
|
const swallowErrors = options.swallowErrors ?? true;
|
|
5
5
|
return {
|
|
6
6
|
enabled,
|
|
@@ -16,6 +16,19 @@ export function resolveTestPulseFixturesOptions(options = {}, environment = proc
|
|
|
16
16
|
}
|
|
17
17
|
};
|
|
18
18
|
}
|
|
19
|
+
function parseOptionalBoolean(value) {
|
|
20
|
+
const normalized = value?.trim().toLowerCase();
|
|
21
|
+
if (!normalized) {
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
if (normalized === "1" || normalized === "true") {
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
if (normalized === "0" || normalized === "false") {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
19
32
|
function trim(value) {
|
|
20
33
|
const trimmed = value?.trim();
|
|
21
34
|
return trimmed ? trimmed : undefined;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { readdir, readFile } from "node:fs/promises";
|
|
1
|
+
import { access, readdir, readFile } from "node:fs/promises";
|
|
2
2
|
import { getLiveCaptureStateDirectory, getLiveCaptureStatePath } from "./LiveSessionState.js";
|
|
3
3
|
export async function resolveLiveCaptureSession(options, now = () => Date.now(), wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms))) {
|
|
4
4
|
if (options.endpoint && options.projectId && options.apiKey && options.runId && options.streamPublisherToken) {
|
|
@@ -11,6 +11,12 @@ export async function resolveLiveCaptureSession(options, now = () => Date.now(),
|
|
|
11
11
|
createdAt: new Date(now()).toISOString()
|
|
12
12
|
};
|
|
13
13
|
}
|
|
14
|
+
if (!await shouldWaitForState(options)) {
|
|
15
|
+
const path = options.sessionKey
|
|
16
|
+
? getLiveCaptureStatePath(options.sessionKey, options.stateDirectory)
|
|
17
|
+
: getLiveCaptureStateDirectory(options.stateDirectory);
|
|
18
|
+
throw new Error(`TestPulse live streaming session state was not found at ${path}.`);
|
|
19
|
+
}
|
|
14
20
|
const deadline = now() + 30_000;
|
|
15
21
|
while (now() < deadline) {
|
|
16
22
|
const session = options.sessionKey
|
|
@@ -26,6 +32,20 @@ export async function resolveLiveCaptureSession(options, now = () => Date.now(),
|
|
|
26
32
|
: getLiveCaptureStateDirectory(options.stateDirectory);
|
|
27
33
|
throw new Error(`TestPulse live streaming session state was not found at ${path}.`);
|
|
28
34
|
}
|
|
35
|
+
async function shouldWaitForState(options) {
|
|
36
|
+
if (options.sessionKey) {
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
try {
|
|
40
|
+
const directory = getLiveCaptureStateDirectory(options.stateDirectory);
|
|
41
|
+
await access(directory);
|
|
42
|
+
const entries = await readdir(directory);
|
|
43
|
+
return entries.some((entry) => entry.endsWith(".json"));
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
29
49
|
async function tryReadLatestStateFile(stateDirectory, now) {
|
|
30
50
|
try {
|
|
31
51
|
const directory = getLiveCaptureStateDirectory(stateDirectory);
|