@livestore/utils-dev 0.5.0-dev.0 → 0.5.0-dev.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.
- package/dist/.tsbuildinfo +1 -1
- package/dist/node/DockerCompose/DockerCompose.d.ts +2 -2
- package/dist/node/DockerCompose/DockerCompose.d.ts.map +1 -1
- package/dist/node/DockerCompose/DockerCompose.js.map +1 -1
- package/dist/node/DockerCompose/DockerCompose.test.js +1 -1
- package/dist/node/DockerCompose/DockerCompose.test.js.map +1 -1
- package/dist/node/DockerCompose/mod.js +1 -1
- package/dist/node/FileLogger.d.ts.map +1 -1
- package/dist/node/FileLogger.js.map +1 -1
- package/dist/node/cmd.js +4 -4
- package/dist/node/cmd.js.map +1 -1
- package/dist/node/cmd.test.js +2 -2
- package/dist/node/mod.d.ts.map +1 -1
- package/dist/node/mod.js +8 -8
- package/dist/node/mod.js.map +1 -1
- package/dist/node/workspace.d.ts.map +1 -1
- package/dist/node/workspace.js.map +1 -1
- package/dist/node-vitest/Vitest.d.ts +1 -42
- package/dist/node-vitest/Vitest.d.ts.map +1 -1
- package/dist/node-vitest/Vitest.js +2 -73
- package/dist/node-vitest/Vitest.js.map +1 -1
- package/dist/node-vitest/mod.js +2 -2
- package/dist/wrangler/WranglerDevServer.d.ts +1 -1
- package/dist/wrangler/WranglerDevServer.d.ts.map +1 -1
- package/dist/wrangler/WranglerDevServer.test.js +1 -1
- package/dist/wrangler/WranglerDevServer.test.js.map +1 -1
- package/dist/wrangler/fixtures/cf-worker.d.ts.map +1 -1
- package/dist/wrangler/mod.js +1 -1
- package/package.json +39 -39
- package/src/node/cmd.ts +1 -3
- package/src/node/mod.ts +4 -4
- package/src/node-vitest/Vitest.ts +1 -142
- package/dist/node-vitest/Vitest.test.d.ts +0 -8
- package/dist/node-vitest/Vitest.test.d.ts.map +0 -1
- package/dist/node-vitest/Vitest.test.js +0 -85
- package/dist/node-vitest/Vitest.test.js.map +0 -1
- package/src/node-vitest/Vitest.test.ts +0 -136
package/package.json
CHANGED
|
@@ -1,74 +1,74 @@
|
|
|
1
1
|
{
|
|
2
|
-
"
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
"$genie": {
|
|
3
|
+
"source": "package.json.genie.ts",
|
|
4
|
+
"warning": "DO NOT EDIT - changes will be overwritten",
|
|
5
|
+
"workspaceClosureDirs": [
|
|
6
|
+
"packages/@livestore/utils",
|
|
7
|
+
"packages/@livestore/utils-dev"
|
|
8
|
+
]
|
|
8
9
|
},
|
|
9
|
-
"
|
|
10
|
-
|
|
11
|
-
"package.json",
|
|
12
|
-
"src"
|
|
13
|
-
],
|
|
10
|
+
"name": "@livestore/utils-dev",
|
|
11
|
+
"version": "0.5.0-dev.1",
|
|
14
12
|
"type": "module",
|
|
15
13
|
"sideEffects": [
|
|
16
14
|
"./src/node-vitest/global.ts",
|
|
17
15
|
"./dist/node-vitest/global.js"
|
|
18
16
|
],
|
|
17
|
+
"license": "Apache-2.0",
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "git+https://github.com/livestorejs/livestore.git"
|
|
21
|
+
},
|
|
19
22
|
"exports": {
|
|
20
23
|
"./node": "./dist/node/mod.js",
|
|
21
24
|
"./node-vitest": "./dist/node-vitest/mod.js",
|
|
22
25
|
"./wrangler": "./dist/wrangler/mod.js"
|
|
23
26
|
},
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
|
|
27
|
+
"files": [
|
|
28
|
+
"dist",
|
|
29
|
+
"package.json",
|
|
30
|
+
"src"
|
|
31
|
+
],
|
|
27
32
|
"dependencies": {
|
|
28
|
-
"@effect/opentelemetry": "4.0.
|
|
29
|
-
"@effect/vitest": "4.0.
|
|
33
|
+
"@effect/opentelemetry": "4.0.3",
|
|
34
|
+
"@effect/vitest": "4.0.3",
|
|
30
35
|
"@iarna/toml": "3.0.0",
|
|
36
|
+
"@livestore/utils": "^0.5.0-dev.1",
|
|
31
37
|
"@opentelemetry/api": "1.9.0",
|
|
32
38
|
"@opentelemetry/exporter-metrics-otlp-http": "0.208.0",
|
|
33
39
|
"@opentelemetry/exporter-trace-otlp-http": "0.208.0",
|
|
34
40
|
"@opentelemetry/sdk-metrics": "2.2.0",
|
|
35
41
|
"@opentelemetry/sdk-trace-base": "2.2.0",
|
|
36
42
|
"@opentelemetry/sdk-trace-node": "2.2.0",
|
|
37
|
-
"wrangler": "4.42.2"
|
|
38
|
-
"@livestore/utils": "^0.5.0-dev.0"
|
|
43
|
+
"wrangler": "4.42.2"
|
|
39
44
|
},
|
|
40
45
|
"devDependencies": {
|
|
41
|
-
"@effect/opentelemetry": "4.0.
|
|
42
|
-
"@effect/platform-browser": "4.0.
|
|
43
|
-
"@effect/platform-bun": "4.0.
|
|
44
|
-
"@effect/platform-node": "4.0.
|
|
45
|
-
"@effect/platform-node-shared": "4.0.
|
|
46
|
-
"@effect/vitest": "4.0.
|
|
46
|
+
"@effect/opentelemetry": "4.0.3",
|
|
47
|
+
"@effect/platform-browser": "4.0.3",
|
|
48
|
+
"@effect/platform-bun": "4.0.3",
|
|
49
|
+
"@effect/platform-node": "4.0.3",
|
|
50
|
+
"@effect/platform-node-shared": "4.0.3",
|
|
51
|
+
"@effect/vitest": "4.0.3",
|
|
47
52
|
"@opentelemetry/api": "1.9.0",
|
|
48
53
|
"@opentelemetry/resources": "2.2.0",
|
|
49
54
|
"@standard-schema/spec": "1.1.0",
|
|
50
|
-
"effect": "4.0.
|
|
55
|
+
"effect": "4.0.3",
|
|
51
56
|
"vitest": "4.1.9"
|
|
52
57
|
},
|
|
53
58
|
"peerDependencies": {
|
|
54
|
-
"@effect/opentelemetry": "^4.0.
|
|
55
|
-
"@effect/platform-browser": "^4.0.
|
|
56
|
-
"@effect/platform-bun": "^4.0.
|
|
57
|
-
"@effect/platform-node": "^4.0.
|
|
58
|
-
"@effect/platform-node-shared": "^4.0.
|
|
59
|
-
"@effect/vitest": "^4.0.
|
|
59
|
+
"@effect/opentelemetry": "^4.0.3",
|
|
60
|
+
"@effect/platform-browser": "^4.0.3",
|
|
61
|
+
"@effect/platform-bun": "^4.0.3",
|
|
62
|
+
"@effect/platform-node": "^4.0.3",
|
|
63
|
+
"@effect/platform-node-shared": "^4.0.3",
|
|
64
|
+
"@effect/vitest": "^4.0.3",
|
|
60
65
|
"@opentelemetry/api": "^1.9.0",
|
|
61
66
|
"@opentelemetry/resources": "^2.2.0",
|
|
62
67
|
"@standard-schema/spec": "^1.1.0",
|
|
63
|
-
"effect": "^4.0.
|
|
68
|
+
"effect": "^4.0.3"
|
|
64
69
|
},
|
|
65
|
-
"
|
|
66
|
-
"
|
|
67
|
-
"warning": "DO NOT EDIT - changes will be overwritten",
|
|
68
|
-
"workspaceClosureDirs": [
|
|
69
|
-
"packages/@livestore/utils",
|
|
70
|
-
"packages/@livestore/utils-dev"
|
|
71
|
-
]
|
|
70
|
+
"publishConfig": {
|
|
71
|
+
"access": "public"
|
|
72
72
|
},
|
|
73
73
|
"scripts": {
|
|
74
74
|
"test": "echo 'No tests for utils-dev'"
|
package/src/node/cmd.ts
CHANGED
|
@@ -242,9 +242,7 @@ const runWithLogging = ({
|
|
|
242
242
|
const spawner = yield* ChildProcessSpawner.ChildProcessSpawner
|
|
243
243
|
const runningProcess = yield* Effect.acquireRelease(spawner.spawn(command), (proc) =>
|
|
244
244
|
proc.isRunning.pipe(
|
|
245
|
-
Effect.flatMap((running) =>
|
|
246
|
-
running === true ? proc.kill().pipe(Effect.catch(() => Effect.void)) : Effect.void,
|
|
247
|
-
),
|
|
245
|
+
Effect.flatMap((running) => (running === true ? proc.kill().pipe(Effect.ignore) : Effect.void)),
|
|
248
246
|
Effect.ignore,
|
|
249
247
|
),
|
|
250
248
|
)
|
package/src/node/mod.ts
CHANGED
|
@@ -42,15 +42,15 @@ export const OtelLiveHttp = ({
|
|
|
42
42
|
} = {}): Layer.Layer<OtelTracer.OtelTracer | Tracer.Tracer | Tracer.ParentSpan> =>
|
|
43
43
|
Effect.gen(function* () {
|
|
44
44
|
const configRes = yield* Config.all({
|
|
45
|
-
exporterUrl: Config.
|
|
45
|
+
exporterUrl: Config.NonEmptyString('OTEL_EXPORTER_OTLP_ENDPOINT'),
|
|
46
46
|
serviceName:
|
|
47
47
|
serviceName !== undefined
|
|
48
48
|
? Config.succeed(serviceName)
|
|
49
|
-
: Config.
|
|
49
|
+
: Config.String('OTEL_SERVICE_NAME').pipe(Config.withDefault('livestore-utils-dev')),
|
|
50
50
|
rootSpanName:
|
|
51
51
|
rootSpanName !== undefined
|
|
52
52
|
? Config.succeed(rootSpanName)
|
|
53
|
-
: Config.
|
|
53
|
+
: Config.String('OTEL_ROOT_SPAN_NAME').pipe(Config.withDefault('RootSpan')),
|
|
54
54
|
}).pipe(Effect.option)
|
|
55
55
|
|
|
56
56
|
if (configRes._tag === 'None') {
|
|
@@ -142,7 +142,7 @@ const logTraceUiUrlForTraceId = (printMsg?: (url: string) => string) => (traceId
|
|
|
142
142
|
|
|
143
143
|
export const getTracingBackendUrl = (traceIdOrSpan: string | otel.Span) =>
|
|
144
144
|
Effect.gen(function* () {
|
|
145
|
-
const endpoint = yield* Config.
|
|
145
|
+
const endpoint = yield* Config.String('GRAFANA_ENDPOINT').pipe(Config.option)
|
|
146
146
|
if (endpoint._tag === 'None') return
|
|
147
147
|
|
|
148
148
|
const traceId = typeof traceIdOrSpan === 'string' ? traceIdOrSpan : traceIdOrSpan.spanContext().traceId
|
|
@@ -3,18 +3,7 @@ import * as inspector from 'node:inspector'
|
|
|
3
3
|
import type * as Vitest from '@effect/vitest'
|
|
4
4
|
|
|
5
5
|
import { IS_CI } from '@livestore/utils'
|
|
6
|
-
import {
|
|
7
|
-
type Cause,
|
|
8
|
-
Duration,
|
|
9
|
-
Effect,
|
|
10
|
-
type FastCheck as FC,
|
|
11
|
-
identity,
|
|
12
|
-
Layer,
|
|
13
|
-
type OtelTracer,
|
|
14
|
-
Predicate,
|
|
15
|
-
type Schema,
|
|
16
|
-
type Scope,
|
|
17
|
-
} from '@livestore/utils/effect'
|
|
6
|
+
import { type Cause, Duration, Effect, identity, Layer, type OtelTracer, type Scope } from '@livestore/utils/effect'
|
|
18
7
|
import { OtelLiveDummy } from '@livestore/utils/node'
|
|
19
8
|
|
|
20
9
|
import { OtelLiveHttp } from '../node/mod.ts'
|
|
@@ -100,133 +89,3 @@ export const withTestCtx =
|
|
|
100
89
|
Effect.annotateLogs({ suffix }),
|
|
101
90
|
)
|
|
102
91
|
}
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Shared properties for all enhanced test context phases
|
|
106
|
-
*/
|
|
107
|
-
export interface EnhancedTestContextBase {
|
|
108
|
-
numRuns: number
|
|
109
|
-
/** 0-based index */
|
|
110
|
-
runIndex: number
|
|
111
|
-
/** Total number of executions including initial runs and shrinking attempts */
|
|
112
|
-
totalExecutions: number
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* Enhanced context for property-based tests that includes shrinking phase information
|
|
117
|
-
*/
|
|
118
|
-
export type EnhancedTestContext =
|
|
119
|
-
| (EnhancedTestContextBase & {
|
|
120
|
-
_tag: 'initial'
|
|
121
|
-
})
|
|
122
|
-
| (EnhancedTestContextBase & {
|
|
123
|
-
_tag: 'shrinking'
|
|
124
|
-
/** Number of shrinking attempts */
|
|
125
|
-
shrinkAttempt: number
|
|
126
|
-
})
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* Normalizes propOptions to ensure @effect/vitest receives correct fastCheck structure
|
|
130
|
-
*/
|
|
131
|
-
type ArbitraryValues<Arbs extends Vitest.Vitest.Arbitraries> = {
|
|
132
|
-
[K in keyof Arbs]: Arbs[K] extends FC.Arbitrary<infer T> ? T : Arbs[K] extends Schema.Schema<infer T> ? T : never
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
type PropOptions<Arbs extends Vitest.Vitest.Arbitraries> = Omit<Vitest.TestOptions, 'fastCheck'> & {
|
|
136
|
-
fastCheck?: FC.Parameters<ArbitraryValues<Arbs>>
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
const normalizePropOptions = <Arbs extends Vitest.Vitest.Arbitraries>(
|
|
140
|
-
propOptions: number | PropOptions<Arbs>,
|
|
141
|
-
): PropOptions<Arbs> => {
|
|
142
|
-
// If it's a number, treat as timeout and add our default fastCheck
|
|
143
|
-
if (Predicate.isObject(propOptions) === false) {
|
|
144
|
-
return {
|
|
145
|
-
timeout: propOptions,
|
|
146
|
-
fastCheck: { numRuns: 100 },
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
// If no fastCheck property, add it with our default numRuns
|
|
151
|
-
if (propOptions.fastCheck == null) {
|
|
152
|
-
return {
|
|
153
|
-
...propOptions,
|
|
154
|
-
fastCheck: { numRuns: 100 },
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
// If fastCheck exists but no numRuns, add our default
|
|
159
|
-
if (propOptions.fastCheck !== undefined && propOptions.fastCheck.numRuns == null) {
|
|
160
|
-
return {
|
|
161
|
-
...propOptions,
|
|
162
|
-
fastCheck: {
|
|
163
|
-
...propOptions.fastCheck,
|
|
164
|
-
numRuns: 100,
|
|
165
|
-
},
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
// If everything is properly structured, pass through
|
|
170
|
-
return propOptions
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
/**
|
|
174
|
-
* Equivalent to Vitest.prop but provides enhanced context including shrinking progress visibility
|
|
175
|
-
*
|
|
176
|
-
* This function enhances the standard property-based testing by providing clear information about
|
|
177
|
-
* whether FastCheck is in the initial testing phase or the shrinking phase, solving the confusion
|
|
178
|
-
* where tests show "Run 26/6" when FastCheck's shrinking algorithm is active.
|
|
179
|
-
*
|
|
180
|
-
* TODO: allow for upper timelimit instead of / additional to `numRuns`
|
|
181
|
-
*
|
|
182
|
-
* TODO: Upstream to Effect
|
|
183
|
-
*/
|
|
184
|
-
export const asProp = <Arbs extends Vitest.Vitest.Arbitraries, A, E, R>(
|
|
185
|
-
api: Vitest.Vitest.Tester<R>,
|
|
186
|
-
name: string,
|
|
187
|
-
arbitraries: Arbs,
|
|
188
|
-
test: Vitest.Vitest.TestFunction<A, E, R, [ArbitraryValues<Arbs>, Vitest.TestContext, EnhancedTestContext]>,
|
|
189
|
-
propOptions: number | PropOptions<Arbs>,
|
|
190
|
-
) => {
|
|
191
|
-
const normalizedPropOptions = normalizePropOptions(propOptions)
|
|
192
|
-
const numRuns = normalizedPropOptions.fastCheck?.numRuns ?? 100
|
|
193
|
-
let runIndex = 0
|
|
194
|
-
let shrinkAttempts = 0
|
|
195
|
-
let totalExecutions = 0
|
|
196
|
-
|
|
197
|
-
return api.prop(
|
|
198
|
-
name,
|
|
199
|
-
arbitraries,
|
|
200
|
-
(properties, ctx) => {
|
|
201
|
-
if (ctx.signal.aborted === true) {
|
|
202
|
-
return ctx.skip('Test aborted')
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
totalExecutions++
|
|
206
|
-
const isInShrinkingPhase = runIndex >= numRuns
|
|
207
|
-
|
|
208
|
-
if (isInShrinkingPhase === true) {
|
|
209
|
-
shrinkAttempts++
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
const enhancedContext: EnhancedTestContext =
|
|
213
|
-
isInShrinkingPhase === true
|
|
214
|
-
? {
|
|
215
|
-
_tag: 'shrinking',
|
|
216
|
-
numRuns,
|
|
217
|
-
runIndex: runIndex++,
|
|
218
|
-
shrinkAttempt: shrinkAttempts,
|
|
219
|
-
totalExecutions,
|
|
220
|
-
}
|
|
221
|
-
: {
|
|
222
|
-
_tag: 'initial',
|
|
223
|
-
numRuns,
|
|
224
|
-
runIndex: runIndex++,
|
|
225
|
-
totalExecutions,
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
return test(properties, ctx, enhancedContext)
|
|
229
|
-
},
|
|
230
|
-
normalizedPropOptions,
|
|
231
|
-
)
|
|
232
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { Schema } from '@livestore/utils/effect';
|
|
2
|
-
declare const TestError_base: Schema.Class<TestError, Schema.TaggedStruct<"TestError", {
|
|
3
|
-
readonly message: Schema.String;
|
|
4
|
-
}>, import("effect/Cause").YieldableError>;
|
|
5
|
-
export declare class TestError extends TestError_base {
|
|
6
|
-
}
|
|
7
|
-
export {};
|
|
8
|
-
//# sourceMappingURL=Vitest.test.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Vitest.test.d.ts","sourceRoot":"","sources":["../../src/node-vitest/Vitest.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,MAAM,EAAE,MAAM,yBAAyB,CAAA;;;;AAInE,qBAAa,SAAU,SAAQ,cAE7B;CAAG"}
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import { Effect, FastCheck, Schema } from '@livestore/utils/effect';
|
|
2
|
-
import * as Vitest from "./Vitest.js";
|
|
3
|
-
export class TestError extends Schema.TaggedError()('TestError', {
|
|
4
|
-
message: Schema.String,
|
|
5
|
-
}) {
|
|
6
|
-
}
|
|
7
|
-
// Demonstrate enhanced asProp functionality with clear shrinking progress
|
|
8
|
-
// This showcases the fix for the "Run 26/6" bug and accurate shrinking detection
|
|
9
|
-
Vitest.describe('Vitest.asProp', () => {
|
|
10
|
-
const IntArbitrary = FastCheck.integer({ min: 1, max: 100 });
|
|
11
|
-
// Always-passing test - should only show initial phase
|
|
12
|
-
Vitest.asProp(Vitest.live, 'always-pass test (shows only initial runs)', [IntArbitrary], (properties, _ctx, enhanced) => Effect.gen(function* () {
|
|
13
|
-
const [value] = properties;
|
|
14
|
-
if (value === undefined) {
|
|
15
|
-
return yield* new TestError({ message: 'Value is undefined' });
|
|
16
|
-
}
|
|
17
|
-
console.log(`✅ ALWAYS-PASS [${enhanced._tag.toUpperCase()}]: ` +
|
|
18
|
-
(enhanced._tag === 'initial'
|
|
19
|
-
? `Run ${enhanced.runIndex + 1}/${enhanced.numRuns}`
|
|
20
|
-
: `Shrink #${enhanced.shrinkAttempt} (finding minimal counterexample)`) +
|
|
21
|
-
`, value=${value}, total=${enhanced.totalExecutions}`);
|
|
22
|
-
// This test always passes, so no shrinking will occur
|
|
23
|
-
return;
|
|
24
|
-
}), { fastCheck: { numRuns: 4 } });
|
|
25
|
-
Vitest.asProp(Vitest.live, 'converts record-form schemas to arbitraries', {
|
|
26
|
-
count: Schema.Int,
|
|
27
|
-
payload: Schema.Struct({
|
|
28
|
-
label: Schema.String,
|
|
29
|
-
note: Schema.optional(Schema.String),
|
|
30
|
-
}),
|
|
31
|
-
}, ({ count, payload }) => Effect.sync(() => {
|
|
32
|
-
Vitest.expect(Number.isInteger(count)).toBe(true);
|
|
33
|
-
Vitest.expect(typeof payload.label).toBe('string');
|
|
34
|
-
Vitest.expect(payload.note === undefined || typeof payload.note === 'string').toBe(true);
|
|
35
|
-
}), { fastCheck: { numRuns: 10 } });
|
|
36
|
-
// Failing test - should show initial + shrinking phases
|
|
37
|
-
let alreadyFailed = false;
|
|
38
|
-
Vitest.asProp(Vitest.live, 'failing test (shows initial runs + shrinking)', [IntArbitrary], (properties, ctx, enhanced) => Effect.gen(function* () {
|
|
39
|
-
const [value] = properties;
|
|
40
|
-
if (value === undefined) {
|
|
41
|
-
return yield* new TestError({ message: 'Value is undefined' });
|
|
42
|
-
}
|
|
43
|
-
const displayInfo = enhanced._tag === 'initial'
|
|
44
|
-
? `Run ${enhanced.runIndex + 1}/${enhanced.numRuns}`
|
|
45
|
-
: `Shrink #${enhanced.shrinkAttempt} (finding minimal counterexample)`;
|
|
46
|
-
const status = value > 80 ? '💥' : '✅';
|
|
47
|
-
console.log(`${status} FAILING-TEST [${enhanced._tag.toUpperCase()}]: ${displayInfo}, value=${value}, total=${enhanced.totalExecutions}`);
|
|
48
|
-
// Fail when value is greater than 80 to trigger shrinking
|
|
49
|
-
if (value > 80) {
|
|
50
|
-
alreadyFailed = true;
|
|
51
|
-
return yield* new TestError({ message: `Value ${value} is too large (> 80)` });
|
|
52
|
-
}
|
|
53
|
-
if (alreadyFailed === true && enhanced._tag === 'shrinking') {
|
|
54
|
-
ctx.skip("For the sake of this test, we don't want to fail but want to skip");
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
return;
|
|
58
|
-
}), { fastCheck: { numRuns: 3 } });
|
|
59
|
-
// Test with endOnFailure: true - should not show shrinking
|
|
60
|
-
Vitest.asProp(Vitest.live, 'failing test with endOnFailure (no shrinking)', [IntArbitrary], (properties, _ctx, enhanced) => Effect.gen(function* () {
|
|
61
|
-
const [value] = properties;
|
|
62
|
-
if (value === undefined) {
|
|
63
|
-
return yield* new TestError({ message: 'Value is undefined' });
|
|
64
|
-
}
|
|
65
|
-
console.log(`🚫 END-ON-FAILURE [${enhanced._tag.toUpperCase()}]: ` +
|
|
66
|
-
`Run ${enhanced.runIndex + 1}/${enhanced.numRuns}, value=${value}, total=${enhanced.totalExecutions}`);
|
|
67
|
-
// This will fail but shrinking is disabled
|
|
68
|
-
if (value > 50) {
|
|
69
|
-
return yield* new TestError({ message: `Value ${value} is too large (> 50) - but no shrinking!` });
|
|
70
|
-
}
|
|
71
|
-
return;
|
|
72
|
-
}), {
|
|
73
|
-
fastCheck: {
|
|
74
|
-
numRuns: 5,
|
|
75
|
-
endOnFailure: true,
|
|
76
|
-
// Provide explicit samples so the second run crosses >50. Randomly drawing five
|
|
77
|
-
// integers has ~3% chance to stay ≤ 50, which would break the `fails: true`
|
|
78
|
-
// expectation even though shrinking remains disabled. The examples keep the
|
|
79
|
-
// demo readable while leaving the remaining runs to FastCheck.
|
|
80
|
-
examples: [[5], [66]],
|
|
81
|
-
},
|
|
82
|
-
fails: true,
|
|
83
|
-
});
|
|
84
|
-
});
|
|
85
|
-
//# sourceMappingURL=Vitest.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Vitest.test.js","sourceRoot":"","sources":["../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,GAAG,UAAU,CAAA;QAC1B,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YACxB,OAAO,KAAK,CAAC,CAAC,IAAI,SAAS,CAAC,EAAE,OAAO,EAAE,oBAAoB,EAAE,CAAC,CAAA;QAChE,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,OAAO,KAAK,CAAC,CAAC,IAAI,SAAS,CAAC,EAAE,OAAO,EAAE,SAAS,KAAK,0CAA0C,EAAE,CAAC,CAAA;QACpG,CAAC;QAED,OAAM;IACR,CAAC,CAAC,EACJ;QACE,SAAS,EAAE;YACT,OAAO,EAAE,CAAC;YACV,YAAY,EAAE,IAAI;YAClB,gFAAgF;YAChF,4EAA4E;YAC5E,4EAA4E;YAC5E,+DAA+D;YAC/D,QAAQ,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;SACtB;QACD,KAAK,EAAE,IAAI;KACZ,CACF,CAAA;AACH,CAAC,CAAC,CAAA"}
|
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
import { Effect, FastCheck, Schema } from '@livestore/utils/effect'
|
|
2
|
-
|
|
3
|
-
import * as Vitest from './Vitest.ts'
|
|
4
|
-
|
|
5
|
-
export class TestError extends Schema.TaggedError<TestError>()('TestError', {
|
|
6
|
-
message: Schema.String,
|
|
7
|
-
}) {}
|
|
8
|
-
|
|
9
|
-
// Demonstrate enhanced asProp functionality with clear shrinking progress
|
|
10
|
-
// This showcases the fix for the "Run 26/6" bug and accurate shrinking detection
|
|
11
|
-
|
|
12
|
-
Vitest.describe('Vitest.asProp', () => {
|
|
13
|
-
const IntArbitrary = FastCheck.integer({ min: 1, max: 100 })
|
|
14
|
-
|
|
15
|
-
// Always-passing test - should only show initial phase
|
|
16
|
-
Vitest.asProp(
|
|
17
|
-
Vitest.live,
|
|
18
|
-
'always-pass test (shows only initial runs)',
|
|
19
|
-
[IntArbitrary],
|
|
20
|
-
(properties, _ctx, enhanced) =>
|
|
21
|
-
Effect.gen(function* () {
|
|
22
|
-
const [value] = properties
|
|
23
|
-
if (value === undefined) {
|
|
24
|
-
return yield* new TestError({ message: 'Value is undefined' })
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
console.log(
|
|
28
|
-
`✅ ALWAYS-PASS [${enhanced._tag.toUpperCase()}]: ` +
|
|
29
|
-
(enhanced._tag === 'initial'
|
|
30
|
-
? `Run ${enhanced.runIndex + 1}/${enhanced.numRuns}`
|
|
31
|
-
: `Shrink #${enhanced.shrinkAttempt} (finding minimal counterexample)`) +
|
|
32
|
-
`, value=${value}, total=${enhanced.totalExecutions}`,
|
|
33
|
-
)
|
|
34
|
-
|
|
35
|
-
// This test always passes, so no shrinking will occur
|
|
36
|
-
return
|
|
37
|
-
}),
|
|
38
|
-
{ fastCheck: { numRuns: 4 } },
|
|
39
|
-
)
|
|
40
|
-
|
|
41
|
-
Vitest.asProp(
|
|
42
|
-
Vitest.live,
|
|
43
|
-
'converts record-form schemas to arbitraries',
|
|
44
|
-
{
|
|
45
|
-
count: Schema.Int,
|
|
46
|
-
payload: Schema.Struct({
|
|
47
|
-
label: Schema.String,
|
|
48
|
-
note: Schema.optional(Schema.String),
|
|
49
|
-
}),
|
|
50
|
-
},
|
|
51
|
-
({ count, payload }) =>
|
|
52
|
-
Effect.sync(() => {
|
|
53
|
-
Vitest.expect(Number.isInteger(count)).toBe(true)
|
|
54
|
-
Vitest.expect(typeof payload.label).toBe('string')
|
|
55
|
-
Vitest.expect(payload.note === undefined || typeof payload.note === 'string').toBe(true)
|
|
56
|
-
}),
|
|
57
|
-
{ fastCheck: { numRuns: 10 } },
|
|
58
|
-
)
|
|
59
|
-
|
|
60
|
-
// Failing test - should show initial + shrinking phases
|
|
61
|
-
let alreadyFailed = false
|
|
62
|
-
Vitest.asProp(
|
|
63
|
-
Vitest.live,
|
|
64
|
-
'failing test (shows initial runs + shrinking)',
|
|
65
|
-
[IntArbitrary],
|
|
66
|
-
(properties, ctx, enhanced) =>
|
|
67
|
-
Effect.gen(function* () {
|
|
68
|
-
const [value] = properties
|
|
69
|
-
if (value === undefined) {
|
|
70
|
-
return yield* new TestError({ message: 'Value is undefined' })
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
const displayInfo =
|
|
74
|
-
enhanced._tag === 'initial'
|
|
75
|
-
? `Run ${enhanced.runIndex + 1}/${enhanced.numRuns}`
|
|
76
|
-
: `Shrink #${enhanced.shrinkAttempt} (finding minimal counterexample)`
|
|
77
|
-
|
|
78
|
-
const status = value > 80 ? '💥' : '✅'
|
|
79
|
-
console.log(
|
|
80
|
-
`${status} FAILING-TEST [${enhanced._tag.toUpperCase()}]: ${displayInfo}, value=${value}, total=${enhanced.totalExecutions}`,
|
|
81
|
-
)
|
|
82
|
-
|
|
83
|
-
// Fail when value is greater than 80 to trigger shrinking
|
|
84
|
-
if (value > 80) {
|
|
85
|
-
alreadyFailed = true
|
|
86
|
-
return yield* new TestError({ message: `Value ${value} is too large (> 80)` })
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
if (alreadyFailed === true && enhanced._tag === 'shrinking') {
|
|
90
|
-
ctx.skip("For the sake of this test, we don't want to fail but want to skip")
|
|
91
|
-
return
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
return
|
|
95
|
-
}),
|
|
96
|
-
{ fastCheck: { numRuns: 3 } },
|
|
97
|
-
)
|
|
98
|
-
|
|
99
|
-
// Test with endOnFailure: true - should not show shrinking
|
|
100
|
-
Vitest.asProp(
|
|
101
|
-
Vitest.live,
|
|
102
|
-
'failing test with endOnFailure (no shrinking)',
|
|
103
|
-
[IntArbitrary],
|
|
104
|
-
(properties, _ctx, enhanced) =>
|
|
105
|
-
Effect.gen(function* () {
|
|
106
|
-
const [value] = properties
|
|
107
|
-
if (value === undefined) {
|
|
108
|
-
return yield* new TestError({ message: 'Value is undefined' })
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
console.log(
|
|
112
|
-
`🚫 END-ON-FAILURE [${enhanced._tag.toUpperCase()}]: ` +
|
|
113
|
-
`Run ${enhanced.runIndex + 1}/${enhanced.numRuns}, value=${value}, total=${enhanced.totalExecutions}`,
|
|
114
|
-
)
|
|
115
|
-
|
|
116
|
-
// This will fail but shrinking is disabled
|
|
117
|
-
if (value > 50) {
|
|
118
|
-
return yield* new TestError({ message: `Value ${value} is too large (> 50) - but no shrinking!` })
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
return
|
|
122
|
-
}),
|
|
123
|
-
{
|
|
124
|
-
fastCheck: {
|
|
125
|
-
numRuns: 5,
|
|
126
|
-
endOnFailure: true,
|
|
127
|
-
// Provide explicit samples so the second run crosses >50. Randomly drawing five
|
|
128
|
-
// integers has ~3% chance to stay ≤ 50, which would break the `fails: true`
|
|
129
|
-
// expectation even though shrinking remains disabled. The examples keep the
|
|
130
|
-
// demo readable while leaving the remaining runs to FastCheck.
|
|
131
|
-
examples: [[5], [66]],
|
|
132
|
-
},
|
|
133
|
-
fails: true,
|
|
134
|
-
},
|
|
135
|
-
)
|
|
136
|
-
})
|