@livestore/utils-dev 0.0.0-snapshot-1c345a0e6695466bdc7c4483444e7b3513620261 → 0.0.0-snapshot-92c31f56117b4fd377b66f55163ed565795c5e4c
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/.tsbuildinfo.json +1 -1
- package/dist/node/DockerComposeService/DockerComposeService.d.ts +48 -0
- package/dist/node/DockerComposeService/DockerComposeService.d.ts.map +1 -0
- package/dist/node/DockerComposeService/DockerComposeService.js +107 -0
- package/dist/node/DockerComposeService/DockerComposeService.js.map +1 -0
- package/dist/node/DockerComposeService/DockerComposeService.test.d.ts +2 -0
- package/dist/node/DockerComposeService/DockerComposeService.test.d.ts.map +1 -0
- package/dist/node/DockerComposeService/DockerComposeService.test.js +64 -0
- package/dist/node/DockerComposeService/DockerComposeService.test.js.map +1 -0
- package/dist/node/FileLogger.d.ts +14 -0
- package/dist/node/FileLogger.d.ts.map +1 -0
- package/dist/node/FileLogger.js +151 -0
- package/dist/node/FileLogger.js.map +1 -0
- package/dist/node/WranglerDevServer/WranglerDevServer.d.ts +51 -0
- package/dist/node/WranglerDevServer/WranglerDevServer.d.ts.map +1 -0
- package/dist/node/WranglerDevServer/WranglerDevServer.js +102 -0
- package/dist/node/WranglerDevServer/WranglerDevServer.js.map +1 -0
- package/dist/node/WranglerDevServer/WranglerDevServer.test.d.ts +2 -0
- package/dist/node/WranglerDevServer/WranglerDevServer.test.d.ts.map +1 -0
- package/dist/node/WranglerDevServer/WranglerDevServer.test.js +186 -0
- package/dist/node/WranglerDevServer/WranglerDevServer.test.js.map +1 -0
- package/dist/node/WranglerDevServer/fixtures/cf-worker.d.ts +8 -0
- package/dist/node/WranglerDevServer/fixtures/cf-worker.d.ts.map +1 -0
- package/dist/node/WranglerDevServer/fixtures/cf-worker.js +11 -0
- package/dist/node/WranglerDevServer/fixtures/cf-worker.js.map +1 -0
- package/dist/node/WranglerDevServer/process-tree-manager.d.ts +55 -0
- package/dist/node/WranglerDevServer/process-tree-manager.d.ts.map +1 -0
- package/dist/node/WranglerDevServer/process-tree-manager.js +178 -0
- package/dist/node/WranglerDevServer/process-tree-manager.js.map +1 -0
- package/dist/node/cmd.d.ts +27 -0
- package/dist/node/cmd.d.ts.map +1 -0
- package/dist/node/cmd.js +55 -0
- package/dist/node/cmd.js.map +1 -0
- package/dist/node/mod.d.ts +7 -13
- package/dist/node/mod.d.ts.map +1 -1
- package/dist/node/mod.js +22 -37
- package/dist/node/mod.js.map +1 -1
- package/dist/node-vitest/Vitest.d.ts +52 -0
- package/dist/node-vitest/Vitest.d.ts.map +1 -0
- package/dist/node-vitest/Vitest.js +98 -0
- package/dist/node-vitest/Vitest.js.map +1 -0
- package/dist/node-vitest/Vitest.test.d.ts +2 -0
- package/dist/node-vitest/Vitest.test.d.ts.map +1 -0
- package/dist/node-vitest/Vitest.test.js +59 -0
- package/dist/node-vitest/Vitest.test.js.map +1 -0
- package/dist/node-vitest/global.d.ts +2 -0
- package/dist/node-vitest/global.d.ts.map +1 -0
- package/dist/node-vitest/{polyfill.js → global.js} +1 -1
- package/dist/node-vitest/global.js.map +1 -0
- package/dist/node-vitest/mod.d.ts +2 -1
- package/dist/node-vitest/mod.d.ts.map +1 -1
- package/dist/node-vitest/mod.js +2 -1
- package/dist/node-vitest/mod.js.map +1 -1
- package/package.json +16 -23
- package/src/node/DockerComposeService/DockerComposeService.test.ts +91 -0
- package/src/node/DockerComposeService/DockerComposeService.ts +252 -0
- package/src/node/DockerComposeService/test-fixtures/docker-compose.yml +4 -0
- package/src/node/FileLogger.ts +206 -0
- package/src/node/WranglerDevServer/WranglerDevServer.test.ts +268 -0
- package/src/node/WranglerDevServer/WranglerDevServer.ts +206 -0
- package/src/node/WranglerDevServer/fixtures/cf-worker.ts +11 -0
- package/src/node/WranglerDevServer/fixtures/wrangler.toml +11 -0
- package/src/node/WranglerDevServer/process-tree-manager.ts +263 -0
- package/src/node/cmd.ts +99 -0
- package/src/node/mod.ts +39 -77
- package/src/node-vitest/Vitest.test.ts +101 -0
- package/src/node-vitest/Vitest.ts +221 -0
- package/src/node-vitest/mod.ts +3 -1
- package/dist/node-vitest/polyfill.d.ts +0 -2
- package/dist/node-vitest/polyfill.d.ts.map +0 -1
- package/dist/node-vitest/polyfill.js.map +0 -1
- /package/src/node-vitest/{polyfill.ts → global.ts} +0 -0
package/dist/node/mod.js
CHANGED
|
@@ -1,18 +1,23 @@
|
|
|
1
1
|
import { performance } from 'node:perf_hooks';
|
|
2
2
|
import * as OtelNodeSdk from '@effect/opentelemetry/NodeSdk';
|
|
3
|
-
import { IS_BUN,
|
|
4
|
-
import {
|
|
3
|
+
import { IS_BUN, isNonEmptyString } from '@livestore/utils';
|
|
4
|
+
import { Config, Effect, FiberRef, Layer, LogLevel, OtelTracer } from '@livestore/utils/effect';
|
|
5
5
|
import { OtelLiveDummy } from '@livestore/utils/node';
|
|
6
6
|
import * as otel from '@opentelemetry/api';
|
|
7
7
|
import { OTLPMetricExporter } from '@opentelemetry/exporter-metrics-otlp-http';
|
|
8
8
|
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http';
|
|
9
9
|
import { PeriodicExportingMetricReader } from '@opentelemetry/sdk-metrics';
|
|
10
10
|
import { BatchSpanProcessor } from '@opentelemetry/sdk-trace-base';
|
|
11
|
-
export { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http';
|
|
12
11
|
export { OTLPMetricExporter } from '@opentelemetry/exporter-metrics-otlp-http';
|
|
12
|
+
export { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http';
|
|
13
|
+
export * from "./cmd.js";
|
|
14
|
+
export { DockerComposeError, DockerComposeService, startDockerComposeServicesScoped, } from "./DockerComposeService/DockerComposeService.js";
|
|
15
|
+
export * as FileLogger from "./FileLogger.js";
|
|
16
|
+
export * from "./WranglerDevServer/process-tree-manager.js";
|
|
17
|
+
export { WranglerDevServerError, WranglerDevServerService, } from "./WranglerDevServer/WranglerDevServer.js";
|
|
13
18
|
export const OtelLiveHttp = ({ serviceName, rootSpanName, rootSpanAttributes, parentSpan, skipLogUrl, traceNodeBootstrap, } = {}) => Effect.gen(function* () {
|
|
14
19
|
const configRes = yield* Config.all({
|
|
15
|
-
exporterUrl: Config.string('OTEL_EXPORTER_OTLP_ENDPOINT'),
|
|
20
|
+
exporterUrl: Config.string('OTEL_EXPORTER_OTLP_ENDPOINT').pipe(Config.validate({ message: 'OTEL_EXPORTER_OTLP_ENDPOINT must be set', validation: isNonEmptyString })),
|
|
16
21
|
serviceName: serviceName
|
|
17
22
|
? Config.succeed(serviceName)
|
|
18
23
|
: Config.string('OTEL_SERVICE_NAME').pipe(Config.withDefault('livestore-utils-dev')),
|
|
@@ -22,7 +27,7 @@ export const OtelLiveHttp = ({ serviceName, rootSpanName, rootSpanAttributes, pa
|
|
|
22
27
|
}).pipe(Effect.option);
|
|
23
28
|
if (configRes._tag === 'None') {
|
|
24
29
|
const RootSpanLive = Layer.span('DummyRoot', {});
|
|
25
|
-
return RootSpanLive.pipe(Layer.
|
|
30
|
+
return RootSpanLive.pipe(Layer.provideMerge(OtelLiveDummy));
|
|
26
31
|
}
|
|
27
32
|
const config = configRes.value;
|
|
28
33
|
const resource = { serviceName: config.serviceName };
|
|
@@ -34,7 +39,18 @@ export const OtelLiveHttp = ({ serviceName, rootSpanName, rootSpanAttributes, pa
|
|
|
34
39
|
resource,
|
|
35
40
|
metricReader,
|
|
36
41
|
spanProcessor: new BatchSpanProcessor(new OTLPTraceExporter({ url: `${config.exporterUrl}/v1/traces`, headers: {} }), { scheduledDelayMillis: 50 }),
|
|
37
|
-
}))
|
|
42
|
+
})).pipe(
|
|
43
|
+
// If an OpenTelemetry backend is not available, the `OtelNodeSdk` layer
|
|
44
|
+
// will ignore the error when attempting to connect and emit a debug log
|
|
45
|
+
// stating the reason for the error (in this case `ECONNREFUSED`). This
|
|
46
|
+
// can cause problems for programs which rely on clean `stdout` (e.g.
|
|
47
|
+
// command-line applications). To remedy this, the below code sets the
|
|
48
|
+
// minimum log level `FiberRef` to `"None"` for the duration of the
|
|
49
|
+
// `OtelNodeSdk`'s layer constructor.
|
|
50
|
+
//
|
|
51
|
+
// This can likely be removed when Livestore is migrated to the Effect
|
|
52
|
+
// native Otlp exporters.
|
|
53
|
+
Layer.locally(FiberRef.currentMinimumLogLevel, LogLevel.None));
|
|
38
54
|
const RootSpanLive = Layer.span(config.rootSpanName, {
|
|
39
55
|
attributes: { config, ...rootSpanAttributes },
|
|
40
56
|
onEnd: skipLogUrl ? undefined : (span) => logTraceUiUrlForSpan()(span.span),
|
|
@@ -97,35 +113,4 @@ export const getTracingBackendUrl = (span) => Effect.gen(function* () {
|
|
|
97
113
|
// TODO make dynamic via env var
|
|
98
114
|
return `${grafanaEndpoint}/explore?${searchParams.toString()}`;
|
|
99
115
|
});
|
|
100
|
-
export const cmd = Effect.fn('cmd')(function* (commandInput, options) {
|
|
101
|
-
const cwd = options?.cwd ?? process.env.WORKSPACE_ROOT ?? shouldNeverHappen('WORKSPACE_ROOT is not set');
|
|
102
|
-
const [command, ...args] = Array.isArray(commandInput) ? commandInput.filter(isNotUndefined) : commandInput.split(' ');
|
|
103
|
-
const debugEnvStr = Object.entries(options?.env ?? {})
|
|
104
|
-
.map(([key, value]) => `${key}=${value} `)
|
|
105
|
-
.join('');
|
|
106
|
-
const commandDebugStr = debugEnvStr + [command, ...args].join(' ');
|
|
107
|
-
yield* Effect.logDebug(`Running '${commandDebugStr}' in '${cwd}'`);
|
|
108
|
-
yield* Effect.annotateCurrentSpan({ 'span.label': commandDebugStr, cwd, command, args });
|
|
109
|
-
return yield* Command.make(command, ...args).pipe(
|
|
110
|
-
// TODO don't forward abort signal to the command
|
|
111
|
-
Command.stdin('inherit'), // Forward stdin to the command
|
|
112
|
-
Command.stdout('inherit'), // Stream stdout to process.stdout
|
|
113
|
-
Command.stderr('inherit'), // Stream stderr to process.stderr
|
|
114
|
-
Command.workingDirectory(cwd), options?.shell ? Command.runInShell(true) : identity, Command.env(options?.env ?? {}), Command.exitCode, Effect.tap((exitCode) => (exitCode === 0 ? Effect.void : Effect.die(`${commandDebugStr} failed`))));
|
|
115
|
-
});
|
|
116
|
-
export const cmdText = Effect.fn('cmdText')(function* (commandInput, options) {
|
|
117
|
-
const cwd = options?.cwd ?? process.env.WORKSPACE_ROOT ?? shouldNeverHappen('WORKSPACE_ROOT is not set');
|
|
118
|
-
const [command, ...args] = Array.isArray(commandInput)
|
|
119
|
-
? commandInput.filter(isNotUndefined)
|
|
120
|
-
: commandInput.split(' ');
|
|
121
|
-
const debugEnvStr = Object.entries(options?.env ?? {})
|
|
122
|
-
.map(([key, value]) => `${key}=${value} `)
|
|
123
|
-
.join('');
|
|
124
|
-
const commandDebugStr = debugEnvStr + [command, ...args].join(' ');
|
|
125
|
-
yield* Effect.logDebug(`Running '${commandDebugStr}' in '${cwd}'`);
|
|
126
|
-
yield* Effect.annotateCurrentSpan({ 'span.label': commandDebugStr, command, cwd });
|
|
127
|
-
return yield* Command.make(command, ...args).pipe(
|
|
128
|
-
// inherit = Stream stderr to process.stderr, pipe = Stream stderr to process.stdout
|
|
129
|
-
Command.stderr(options?.stderr ?? 'inherit'), Command.workingDirectory(cwd), options?.runInShell ? Command.runInShell(true) : identity, Command.env(options?.env ?? {}), Command.string);
|
|
130
|
-
});
|
|
131
116
|
//# sourceMappingURL=mod.js.map
|
package/dist/node/mod.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mod.js","sourceRoot":"","sources":["../../src/node/mod.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAE7C,OAAO,KAAK,WAAW,MAAM,+BAA+B,CAAA;AAC5D,OAAO,EAAE,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"mod.js","sourceRoot":"","sources":["../../src/node/mod.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAE7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CAAC,CAAA;QAClC,CAAC;aAAM,CAAC;YACN,OAAO,MAAM,CAAC,GAAG,CAAC,cAAc,GAAG,EAAE,CAAC,CAAA;QACxC,CAAC;IACH,CAAC;AACH,CAAC,CAAC,CACH,CAAA;AAEH,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,IAAe,EAAE,EAAE,CACtD,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;IAClB,MAAM,QAAQ,GAAG,KAAK,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,kBAAkB,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,KAAK,CAAC,CAAA;IAC3F,IAAI,QAAQ,CAAC,IAAI,KAAK,MAAM;QAAE,OAAM;IAEpC,MAAM,OAAO,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC,OAAO,CAAA;IAE1C,kBAAkB;IAElB,MAAM,eAAe,GAAG,QAAQ,CAAC,KAAK,CAAA;IACtC,MAAM,YAAY,GAAG,IAAI,eAAe,CAAC;QACvC,KAAK,EAAE,GAAG;QACV,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;YACnB,UAAU,EAAE,OAAO;YACnB,OAAO,EAAE,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC;YAC/D,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,EAAE,KAAK,EAAE;SACrC,CAAC;KACH,CAAC,CAAA;IAEF,gCAAgC;IAChC,OAAO,GAAG,eAAe,YAAY,YAAY,CAAC,QAAQ,EAAE,EAAE,CAAA;AAChE,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type * as Vitest from '@effect/vitest';
|
|
2
|
+
import { type Cause, Duration, Effect, type FastCheck as FC, Layer, type OtelTracer, type Schema, type Scope } from '@livestore/utils/effect';
|
|
3
|
+
export * from '@effect/vitest';
|
|
4
|
+
export declare const DEBUGGER_ACTIVE: boolean;
|
|
5
|
+
export declare const makeWithTestCtx: <R1 = never, E1 = never>(ctxParams: WithTestCtxParams<R1, E1>) => (testContext: Vitest.TestContext) => <A, E>(self: Effect.Effect<A, E, Scope.Scope | OtelTracer.OtelTracer | R1>) => Effect.Effect<A, Cause.TimeoutException | E1 | E, Scope.Scope>;
|
|
6
|
+
export type WithTestCtxParams<R1 = never, E1 = never> = {
|
|
7
|
+
suffix?: string;
|
|
8
|
+
makeLayer?: (testContext: Vitest.TestContext) => Layer.Layer<R1, E1, Scope.Scope>;
|
|
9
|
+
timeout?: Duration.DurationInput;
|
|
10
|
+
forceOtel?: boolean;
|
|
11
|
+
};
|
|
12
|
+
export declare const withTestCtx: <R1 = never, E1 = never>(testContext: Vitest.TestContext, { suffix, makeLayer, timeout, forceOtel, }?: {
|
|
13
|
+
suffix?: string;
|
|
14
|
+
makeLayer?: (testContext: Vitest.TestContext) => Layer.Layer<R1, E1, Scope.Scope>;
|
|
15
|
+
timeout?: Duration.DurationInput;
|
|
16
|
+
forceOtel?: boolean;
|
|
17
|
+
}) => <A, E>(self: Effect.Effect<A, E, Scope.Scope | OtelTracer.OtelTracer | R1>) => Effect.Effect<A, E | Cause.TimeoutException | E1, Scope.Scope>;
|
|
18
|
+
/**
|
|
19
|
+
* Shared properties for all enhanced test context phases
|
|
20
|
+
*/
|
|
21
|
+
export interface EnhancedTestContextBase {
|
|
22
|
+
numRuns: number;
|
|
23
|
+
/** 0-based index */
|
|
24
|
+
runIndex: number;
|
|
25
|
+
/** Total number of executions including initial runs and shrinking attempts */
|
|
26
|
+
totalExecutions: number;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Enhanced context for property-based tests that includes shrinking phase information
|
|
30
|
+
*/
|
|
31
|
+
export type EnhancedTestContext = (EnhancedTestContextBase & {
|
|
32
|
+
_tag: 'initial';
|
|
33
|
+
}) | (EnhancedTestContextBase & {
|
|
34
|
+
_tag: 'shrinking';
|
|
35
|
+
/** Number of shrinking attempts */
|
|
36
|
+
shrinkAttempt: number;
|
|
37
|
+
});
|
|
38
|
+
/**
|
|
39
|
+
* Equivalent to Vitest.prop but provides enhanced context including shrinking progress visibility
|
|
40
|
+
*
|
|
41
|
+
* This function enhances the standard property-based testing by providing clear information about
|
|
42
|
+
* whether FastCheck is in the initial testing phase or the shrinking phase, solving the confusion
|
|
43
|
+
* where tests show "Run 26/6" when FastCheck's shrinking algorithm is active.
|
|
44
|
+
*
|
|
45
|
+
* TODO: allow for upper timelimit instead of / additional to `numRuns`
|
|
46
|
+
*
|
|
47
|
+
* TODO: Upstream to Effect
|
|
48
|
+
*/
|
|
49
|
+
export declare const asProp: <Arbs extends Vitest.Vitest.Arbitraries, A, E, R>(api: Vitest.Vitest.Tester<R>, name: string, arbitraries: Arbs, test: Vitest.Vitest.TestFunction<A, E, R, [{ [K in keyof Arbs]: Arbs[K] extends FC.Arbitrary<infer T> ? T : Schema.Schema.Type<Arbs[K]>; }, Vitest.TestContext, EnhancedTestContext]>, propOptions: number | (Vitest.TestOptions & {
|
|
50
|
+
fastCheck?: FC.Parameters<{ [K in keyof Arbs]: Arbs[K] extends FC.Arbitrary<infer T> ? T : Schema.Schema.Type<Arbs[K]>; }>;
|
|
51
|
+
})) => void;
|
|
52
|
+
//# sourceMappingURL=Vitest.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Vitest.d.ts","sourceRoot":"","sources":["../../src/node-vitest/Vitest.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,MAAM,gBAAgB,CAAA;AAE7C,OAAO,EACL,KAAK,KAAK,EACV,QAAQ,EACR,MAAM,EACN,KAAK,SAAS,IAAI,EAAE,EAEpB,KAAK,EACL,KAAK,UAAU,EAEf,KAAK,MAAM,EACX,KAAK,KAAK,EACX,MAAM,yBAAyB,CAAA;AAIhC,cAAc,gBAAgB,CAAA;AAE9B,eAAO,MAAM,eAAe,SAAwE,CAA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AAC,CAAA;CACH,CAAC,SA0CP,CAAA"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import * as inspector from 'node:inspector';
|
|
2
|
+
import { IS_CI } from '@livestore/utils';
|
|
3
|
+
import { Duration, Effect, identity, Layer, Predicate, } from '@livestore/utils/effect';
|
|
4
|
+
import { OtelLiveDummy } from '@livestore/utils/node';
|
|
5
|
+
import { OtelLiveHttp } from "../node/mod.js";
|
|
6
|
+
export * from '@effect/vitest';
|
|
7
|
+
export const DEBUGGER_ACTIVE = Boolean(process.env.DEBUGGER_ACTIVE ?? inspector.url() !== undefined);
|
|
8
|
+
export const makeWithTestCtx = (ctxParams) => (testContext) => withTestCtx(testContext, ctxParams);
|
|
9
|
+
export const withTestCtx = (testContext, { suffix, makeLayer, timeout = IS_CI ? 60_000 : 10_000, forceOtel = false, } = {}) => (self) => {
|
|
10
|
+
const spanName = `${testContext.task.suite?.name}:${testContext.task.name}${suffix ? `:${suffix}` : ''}`;
|
|
11
|
+
const layer = makeLayer?.(testContext);
|
|
12
|
+
const otelLayer = DEBUGGER_ACTIVE || forceOtel
|
|
13
|
+
? OtelLiveHttp({ rootSpanName: spanName, serviceName: 'vitest-runner', skipLogUrl: false })
|
|
14
|
+
: OtelLiveDummy;
|
|
15
|
+
const combinedLayer = (layer ?? Layer.empty).pipe(Layer.provideMerge(otelLayer));
|
|
16
|
+
return self.pipe(DEBUGGER_ACTIVE
|
|
17
|
+
? identity
|
|
18
|
+
: Effect.logWarnIfTakesLongerThan({
|
|
19
|
+
duration: Duration.toMillis(timeout) * 0.8,
|
|
20
|
+
label: `${spanName} approaching timeout (timeout: ${Duration.format(timeout)})`,
|
|
21
|
+
}), DEBUGGER_ACTIVE ? identity : Effect.timeout(timeout), Effect.provide(combinedLayer), Effect.scoped, // We need to scope the effect manually here because otherwise the span is not closed
|
|
22
|
+
Effect.annotateLogs({ suffix }));
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Normalizes propOptions to ensure @effect/vitest receives correct fastCheck structure
|
|
26
|
+
*/
|
|
27
|
+
const normalizePropOptions = (propOptions) => {
|
|
28
|
+
// If it's a number, treat as timeout and add our default fastCheck
|
|
29
|
+
if (!Predicate.isObject(propOptions)) {
|
|
30
|
+
return {
|
|
31
|
+
timeout: propOptions,
|
|
32
|
+
fastCheck: { numRuns: 100 },
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
// If no fastCheck property, add it with our default numRuns
|
|
36
|
+
if (!propOptions.fastCheck) {
|
|
37
|
+
return {
|
|
38
|
+
...propOptions,
|
|
39
|
+
fastCheck: { numRuns: 100 },
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
// If fastCheck exists but no numRuns, add our default
|
|
43
|
+
if (propOptions.fastCheck && !propOptions.fastCheck.numRuns) {
|
|
44
|
+
return {
|
|
45
|
+
...propOptions,
|
|
46
|
+
fastCheck: {
|
|
47
|
+
...propOptions.fastCheck,
|
|
48
|
+
numRuns: 100,
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
// If everything is properly structured, pass through
|
|
53
|
+
return propOptions;
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Equivalent to Vitest.prop but provides enhanced context including shrinking progress visibility
|
|
57
|
+
*
|
|
58
|
+
* This function enhances the standard property-based testing by providing clear information about
|
|
59
|
+
* whether FastCheck is in the initial testing phase or the shrinking phase, solving the confusion
|
|
60
|
+
* where tests show "Run 26/6" when FastCheck's shrinking algorithm is active.
|
|
61
|
+
*
|
|
62
|
+
* TODO: allow for upper timelimit instead of / additional to `numRuns`
|
|
63
|
+
*
|
|
64
|
+
* TODO: Upstream to Effect
|
|
65
|
+
*/
|
|
66
|
+
export const asProp = (api, name, arbitraries, test, propOptions) => {
|
|
67
|
+
const normalizedPropOptions = normalizePropOptions(propOptions);
|
|
68
|
+
const numRuns = normalizedPropOptions.fastCheck?.numRuns ?? 100;
|
|
69
|
+
let runIndex = 0;
|
|
70
|
+
let shrinkAttempts = 0;
|
|
71
|
+
let totalExecutions = 0;
|
|
72
|
+
return api.prop(name, arbitraries, (properties, ctx) => {
|
|
73
|
+
if (ctx.signal.aborted) {
|
|
74
|
+
return ctx.skip('Test aborted');
|
|
75
|
+
}
|
|
76
|
+
totalExecutions++;
|
|
77
|
+
const isInShrinkingPhase = runIndex >= numRuns;
|
|
78
|
+
if (isInShrinkingPhase) {
|
|
79
|
+
shrinkAttempts++;
|
|
80
|
+
}
|
|
81
|
+
const enhancedContext = isInShrinkingPhase
|
|
82
|
+
? {
|
|
83
|
+
_tag: 'shrinking',
|
|
84
|
+
numRuns,
|
|
85
|
+
runIndex: runIndex++,
|
|
86
|
+
shrinkAttempt: shrinkAttempts,
|
|
87
|
+
totalExecutions,
|
|
88
|
+
}
|
|
89
|
+
: {
|
|
90
|
+
_tag: 'initial',
|
|
91
|
+
numRuns,
|
|
92
|
+
runIndex: runIndex++,
|
|
93
|
+
totalExecutions,
|
|
94
|
+
};
|
|
95
|
+
return test(properties, ctx, enhancedContext);
|
|
96
|
+
}, normalizedPropOptions);
|
|
97
|
+
};
|
|
98
|
+
//# sourceMappingURL=Vitest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Vitest.js","sourceRoot":"","sources":["../../src/node-vitest/Vitest.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,SAAS,MAAM,gBAAgB,CAAA;AAE3C,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAA;AACxC,OAAO,EAEL,QAAQ,EACR,MAAM,EAEN,QAAQ,EACR,KAAK,EAEL,SAAS,GAGV,MAAM,yBAAyB,CAAA;AAChC,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAA;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAE7C,cAAc,gBAAgB,CAAA;AAE9B,MAAM,CAAC,MAAM,eAAe,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,eAAe,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AE,OAAO,IAAI,GAAG,CAAA;IAC/D,IAAI,QAAQ,GAAG,CAAC,CAAA;IAChB,IAAI,cAAc,GAAG,CAAC,CAAA;IACtB,IAAI,eAAe,GAAG,CAAC,CAAA;IAEvB,OAAO,GAAG,CAAC,IAAI,CACb,IAAI,EACJ,WAAW,EACX,CAAC,UAAU,EAAE,GAAG,EAAE,EAAE;QAClB,IAAI,GAAG,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;YACvB,OAAO,GAAG,CAAC,IAAI,CAAC,cAAc,CAAC,CAAA;QACjC,CAAC;QAED,eAAe,EAAE,CAAA;QACjB,MAAM,kBAAkB,GAAG,QAAQ,IAAI,OAAO,CAAA;QAE9C,IAAI,kBAAkB,EAAE,CAAC;YACvB,cAAc,EAAE,CAAA;QAClB,CAAC;QAED,MAAM,eAAe,GAAwB,kBAAkB;YAC7D,CAAC,CAAC;gBACE,IAAI,EAAE,WAAW;gBACjB,OAAO;gBACP,QAAQ,EAAE,QAAQ,EAAE;gBACpB,aAAa,EAAE,cAAc;gBAC7B,eAAe;aAChB;YACH,CAAC,CAAC;gBACE,IAAI,EAAE,SAAS;gBACf,OAAO;gBACP,QAAQ,EAAE,QAAQ,EAAE;gBACpB,eAAe;aAChB,CAAA;QAEL,OAAO,IAAI,CAAC,UAAU,EAAE,GAAG,EAAE,eAAe,CAAC,CAAA;IAC/C,CAAC,EACD,qBAAqB,CACtB,CAAA;AACH,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Vitest.test.d.ts","sourceRoot":"","sources":["../../src/node-vitest/Vitest.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { Effect, FastCheck } from '@livestore/utils/effect';
|
|
2
|
+
import * as Vitest from "./Vitest.js";
|
|
3
|
+
// Demonstrate enhanced asProp functionality with clear shrinking progress
|
|
4
|
+
// This showcases the fix for the "Run 26/6" bug and accurate shrinking detection
|
|
5
|
+
Vitest.describe('Vitest.asProp', () => {
|
|
6
|
+
const IntArbitrary = FastCheck.integer({ min: 1, max: 100 });
|
|
7
|
+
// Always-passing test - should only show initial phase
|
|
8
|
+
Vitest.asProp(Vitest.scopedLive, 'always-pass test (shows only initial runs)', [IntArbitrary], (properties, _ctx, enhanced) => Effect.gen(function* () {
|
|
9
|
+
const [value] = properties;
|
|
10
|
+
if (value === undefined) {
|
|
11
|
+
return yield* Effect.fail(new Error('Value is undefined'));
|
|
12
|
+
}
|
|
13
|
+
console.log(`✅ ALWAYS-PASS [${enhanced._tag.toUpperCase()}]: ` +
|
|
14
|
+
(enhanced._tag === 'initial'
|
|
15
|
+
? `Run ${enhanced.runIndex + 1}/${enhanced.numRuns}`
|
|
16
|
+
: `Shrink #${enhanced.shrinkAttempt} (finding minimal counterexample)`) +
|
|
17
|
+
`, value=${value}, total=${enhanced.totalExecutions}`);
|
|
18
|
+
// This test always passes, so no shrinking will occur
|
|
19
|
+
return;
|
|
20
|
+
}), { fastCheck: { numRuns: 4 } });
|
|
21
|
+
// Failing test - should show initial + shrinking phases
|
|
22
|
+
let alreadyFailed = false;
|
|
23
|
+
Vitest.asProp(Vitest.scopedLive, 'failing test (shows initial runs + shrinking)', [IntArbitrary], (properties, ctx, enhanced) => Effect.gen(function* () {
|
|
24
|
+
const [value] = properties;
|
|
25
|
+
if (value === undefined) {
|
|
26
|
+
return yield* Effect.fail(new Error('Value is undefined'));
|
|
27
|
+
}
|
|
28
|
+
const displayInfo = enhanced._tag === 'initial'
|
|
29
|
+
? `Run ${enhanced.runIndex + 1}/${enhanced.numRuns}`
|
|
30
|
+
: `Shrink #${enhanced.shrinkAttempt} (finding minimal counterexample)`;
|
|
31
|
+
const status = value > 80 ? '💥' : '✅';
|
|
32
|
+
console.log(`${status} FAILING-TEST [${enhanced._tag.toUpperCase()}]: ${displayInfo}, value=${value}, total=${enhanced.totalExecutions}`);
|
|
33
|
+
// Fail when value is greater than 80 to trigger shrinking
|
|
34
|
+
if (value > 80) {
|
|
35
|
+
alreadyFailed = true;
|
|
36
|
+
return yield* Effect.fail(new Error(`Value ${value} is too large (> 80)`));
|
|
37
|
+
}
|
|
38
|
+
if (alreadyFailed && enhanced._tag === 'shrinking') {
|
|
39
|
+
ctx.skip("For the sake of this test, we don't want to fail but want to skip");
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
return;
|
|
43
|
+
}), { fastCheck: { numRuns: 3 } });
|
|
44
|
+
// Test with endOnFailure: true - should not show shrinking
|
|
45
|
+
Vitest.asProp(Vitest.scopedLive, 'failing test with endOnFailure (no shrinking)', [IntArbitrary], (properties, _ctx, enhanced) => Effect.gen(function* () {
|
|
46
|
+
const [value] = properties;
|
|
47
|
+
if (value === undefined) {
|
|
48
|
+
return yield* Effect.fail(new Error('Value is undefined'));
|
|
49
|
+
}
|
|
50
|
+
console.log(`🚫 END-ON-FAILURE [${enhanced._tag.toUpperCase()}]: ` +
|
|
51
|
+
`Run ${enhanced.runIndex + 1}/${enhanced.numRuns}, value=${value}, total=${enhanced.totalExecutions}`);
|
|
52
|
+
// This will fail but shrinking is disabled
|
|
53
|
+
if (value > 50) {
|
|
54
|
+
yield* Effect.fail(new Error(`Value ${value} is too large (> 50) - but no shrinking!`));
|
|
55
|
+
}
|
|
56
|
+
return;
|
|
57
|
+
}), { fastCheck: { numRuns: 5, endOnFailure: true }, fails: true });
|
|
58
|
+
});
|
|
59
|
+
//# sourceMappingURL=Vitest.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Vitest.test.js","sourceRoot":"","sources":["../../src/node-vitest/Vitest.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAC3D,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AAErC,0EAA0E;AAC1E,iFAAiF;AAEjF,MAAM,CAAC,QAAQ,CAAC,eAAe,EAAE,GAAG,EAAE;IACpC,MAAM,YAAY,GAAG,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CAAC,QAAQ,CAAC;QAClB,MAAM,CAAC,KAAK,CAAC,GAAG,UAAU,CAAA;QAC1B,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YACxB,OAAO,KAAK,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,KAAK,CAAC,oBAAoB,CAAC,CAAC,CAAA;QAC5D,CAAC;QAED,OAAO,CAAC,GAAG,CACT,sBAAsB,QAAQ,CAAC,IAAI,CAAC,WAAW,EAAE,KAAK;YACpD,OAAO,QAAQ,CAAC,QAAQ,GAAG,CAAC,IAAI,QAAQ,CAAC,OAAO,WAAW,KAAK,WAAW,QAAQ,CAAC,eAAe,EAAE,CACxG,CAAA;QAED,2CAA2C;QAC3C,IAAI,KAAK,GAAG,EAAE,EAAE,CAAC;YACf,KAAK,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,KAAK,CAAC,SAAS,KAAK,0CAA0C,CAAC,CAAC,CAAA;QACzF,CAAC;QAED,OAAM;IACR,CAAC,CAAC,EACJ,EAAE,SAAS,EAAE,EAAE,OAAO,EAAE,CAAC,EAAE,YAAY,EAAE,IAAI,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAC/D,CAAA;AACH,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"global.d.ts","sourceRoot":"","sources":["../../src/node-vitest/global.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"global.js","sourceRoot":"","sources":["../../src/node-vitest/global.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,CAAC,KAAK,GAAG,IAAI,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../src/node-vitest/mod.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../src/node-vitest/mod.ts"],"names":[],"mappings":"AAAA,OAAO,aAAa,CAAA;AAEpB,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA"}
|
package/dist/node-vitest/mod.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mod.js","sourceRoot":"","sources":["../../src/node-vitest/mod.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,
|
|
1
|
+
{"version":3,"file":"mod.js","sourceRoot":"","sources":["../../src/node-vitest/mod.ts"],"names":[],"mappings":"AAAA,OAAO,aAAa,CAAA;AAEpB,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,34 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@livestore/utils-dev",
|
|
3
|
-
"version": "0.0.0-snapshot-
|
|
3
|
+
"version": "0.0.0-snapshot-92c31f56117b4fd377b66f55163ed565795c5e4c",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": [
|
|
6
|
-
"./
|
|
6
|
+
"./src/node-vitest/global.ts"
|
|
7
7
|
],
|
|
8
8
|
"exports": {
|
|
9
|
-
"./node":
|
|
10
|
-
|
|
11
|
-
"default": "./dist/node/mod.js"
|
|
12
|
-
},
|
|
13
|
-
"./node-vitest": {
|
|
14
|
-
"types": "./dist/node-vitest/mod.d.ts",
|
|
15
|
-
"default": "./dist/node-vitest/mod.js"
|
|
16
|
-
},
|
|
17
|
-
"./node-vitest-polyfill": {
|
|
18
|
-
"types": "./dist/node-vitest/polyfill.d.ts",
|
|
19
|
-
"default": "./dist/node-vitest/polyfill.js"
|
|
20
|
-
}
|
|
9
|
+
"./node": "./dist/node/mod.js",
|
|
10
|
+
"./node-vitest": "./dist/node-vitest/mod.js"
|
|
21
11
|
},
|
|
22
12
|
"dependencies": {
|
|
23
|
-
"@effect/opentelemetry": "0.
|
|
24
|
-
"@effect/vitest": "0.
|
|
13
|
+
"@effect/opentelemetry": "0.56.4",
|
|
14
|
+
"@effect/vitest": "0.25.1",
|
|
25
15
|
"@opentelemetry/api": "1.9.0",
|
|
26
|
-
"@opentelemetry/exporter-metrics-otlp-http": "0.
|
|
27
|
-
"@opentelemetry/exporter-trace-otlp-http": "0.
|
|
28
|
-
"@opentelemetry/sdk-metrics": "2.0.
|
|
29
|
-
"@opentelemetry/sdk-trace-base": "2.0.
|
|
30
|
-
"@opentelemetry/sdk-trace-node": "2.0.
|
|
31
|
-
"@livestore/utils": "0.0.0-snapshot-
|
|
16
|
+
"@opentelemetry/exporter-metrics-otlp-http": "0.203.0",
|
|
17
|
+
"@opentelemetry/exporter-trace-otlp-http": "0.203.0",
|
|
18
|
+
"@opentelemetry/sdk-metrics": "2.0.1",
|
|
19
|
+
"@opentelemetry/sdk-trace-base": "2.0.1",
|
|
20
|
+
"@opentelemetry/sdk-trace-node": "2.0.1",
|
|
21
|
+
"@livestore/utils": "0.0.0-snapshot-92c31f56117b4fd377b66f55163ed565795c5e4c"
|
|
32
22
|
},
|
|
33
23
|
"devDependencies": {},
|
|
34
24
|
"files": [
|
|
@@ -39,7 +29,10 @@
|
|
|
39
29
|
"license": "Apache-2.0",
|
|
40
30
|
"peerDependencies": {},
|
|
41
31
|
"publishConfig": {
|
|
42
|
-
"access": "public"
|
|
32
|
+
"access": "public",
|
|
33
|
+
"sideEffects": [
|
|
34
|
+
"./dist/node-vitest/global.js"
|
|
35
|
+
]
|
|
43
36
|
},
|
|
44
37
|
"scripts": {
|
|
45
38
|
"test": "echo 'No tests for utils-dev'"
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import path from 'node:path'
|
|
2
|
+
import { Duration, Effect, Layer, Stream } from '@livestore/utils/effect'
|
|
3
|
+
import { PlatformNode } from '@livestore/utils/node'
|
|
4
|
+
import { Vitest } from '@livestore/utils-dev/node-vitest'
|
|
5
|
+
import { expect } from 'vitest'
|
|
6
|
+
import { type DockerComposeArgs, DockerComposeService } from './DockerComposeService.ts'
|
|
7
|
+
|
|
8
|
+
const testTimeout = 30_000
|
|
9
|
+
const testFixturePath = path.join(import.meta.dirname, 'test-fixtures')
|
|
10
|
+
|
|
11
|
+
const DockerComposeTest = (args: Partial<DockerComposeArgs> = {}) =>
|
|
12
|
+
DockerComposeService.Default({
|
|
13
|
+
cwd: testFixturePath,
|
|
14
|
+
...args,
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
Vitest.describe('DockerComposeService', { timeout: testTimeout }, () => {
|
|
18
|
+
Vitest.describe('Basic Operations', () => {
|
|
19
|
+
const withBasicTest = (args: Partial<DockerComposeArgs> = {}) =>
|
|
20
|
+
Vitest.makeWithTestCtx({
|
|
21
|
+
timeout: testTimeout,
|
|
22
|
+
makeLayer: () => DockerComposeTest(args).pipe(Layer.provide(PlatformNode.NodeContext.layer)),
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
Vitest.scopedLive('can pull docker images', (test) =>
|
|
26
|
+
Effect.gen(function* () {
|
|
27
|
+
const dockerCompose = yield* DockerComposeService
|
|
28
|
+
|
|
29
|
+
// Test that pull operation works (should succeed for hello-world image)
|
|
30
|
+
yield* dockerCompose.pull
|
|
31
|
+
}).pipe(withBasicTest()(test)),
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
Vitest.scopedLive('can start and stop docker compose services', (test) =>
|
|
35
|
+
Effect.gen(function* () {
|
|
36
|
+
const dockerCompose = yield* DockerComposeService
|
|
37
|
+
|
|
38
|
+
// Start the service
|
|
39
|
+
yield* dockerCompose.start({ detached: true })
|
|
40
|
+
|
|
41
|
+
// Stop the service
|
|
42
|
+
yield* dockerCompose.stop
|
|
43
|
+
}).pipe(withBasicTest({ serviceName: 'hello-world' })(test)),
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
Vitest.scopedLive('can get logs from docker compose services', (test) =>
|
|
47
|
+
Effect.gen(function* () {
|
|
48
|
+
const dockerCompose = yield* DockerComposeService
|
|
49
|
+
|
|
50
|
+
// Start the service first
|
|
51
|
+
yield* dockerCompose.start({ detached: true })
|
|
52
|
+
|
|
53
|
+
// Get logs (should contain at least the "Hello from Docker!" message)
|
|
54
|
+
const firstLogLine = yield* dockerCompose.logs().pipe(Stream.runHead)
|
|
55
|
+
|
|
56
|
+
expect(firstLogLine._tag).toBe('Some')
|
|
57
|
+
|
|
58
|
+
// Stop the service
|
|
59
|
+
yield* dockerCompose.stop
|
|
60
|
+
}).pipe(withBasicTest({ serviceName: 'hello-world' })(test)),
|
|
61
|
+
)
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
Vitest.describe('Health Check Operations', () => {
|
|
65
|
+
const withHealthCheckTest = (args: Partial<DockerComposeArgs> = {}) =>
|
|
66
|
+
Vitest.makeWithTestCtx({
|
|
67
|
+
timeout: testTimeout,
|
|
68
|
+
makeLayer: () => DockerComposeTest(args).pipe(Layer.provide(PlatformNode.NodeContext.layer)),
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
Vitest.scopedLive('handles health check timeout gracefully', (test) =>
|
|
72
|
+
Effect.gen(function* () {
|
|
73
|
+
const dockerCompose = yield* DockerComposeService
|
|
74
|
+
|
|
75
|
+
// Test starting with a health check that will timeout (invalid URL)
|
|
76
|
+
const result = yield* dockerCompose
|
|
77
|
+
.start({
|
|
78
|
+
detached: true,
|
|
79
|
+
healthCheck: {
|
|
80
|
+
url: 'http://localhost:99999/nonexistent',
|
|
81
|
+
timeout: Duration.seconds(2),
|
|
82
|
+
},
|
|
83
|
+
})
|
|
84
|
+
.pipe(Effect.either)
|
|
85
|
+
|
|
86
|
+
// Should fail due to health check timeout
|
|
87
|
+
expect(result._tag).toBe('Left')
|
|
88
|
+
}).pipe(withHealthCheckTest({ serviceName: 'hello-world' })(test)),
|
|
89
|
+
)
|
|
90
|
+
})
|
|
91
|
+
})
|