@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.
Files changed (72) hide show
  1. package/dist/.tsbuildinfo.json +1 -1
  2. package/dist/node/DockerComposeService/DockerComposeService.d.ts +48 -0
  3. package/dist/node/DockerComposeService/DockerComposeService.d.ts.map +1 -0
  4. package/dist/node/DockerComposeService/DockerComposeService.js +107 -0
  5. package/dist/node/DockerComposeService/DockerComposeService.js.map +1 -0
  6. package/dist/node/DockerComposeService/DockerComposeService.test.d.ts +2 -0
  7. package/dist/node/DockerComposeService/DockerComposeService.test.d.ts.map +1 -0
  8. package/dist/node/DockerComposeService/DockerComposeService.test.js +64 -0
  9. package/dist/node/DockerComposeService/DockerComposeService.test.js.map +1 -0
  10. package/dist/node/FileLogger.d.ts +14 -0
  11. package/dist/node/FileLogger.d.ts.map +1 -0
  12. package/dist/node/FileLogger.js +151 -0
  13. package/dist/node/FileLogger.js.map +1 -0
  14. package/dist/node/WranglerDevServer/WranglerDevServer.d.ts +51 -0
  15. package/dist/node/WranglerDevServer/WranglerDevServer.d.ts.map +1 -0
  16. package/dist/node/WranglerDevServer/WranglerDevServer.js +102 -0
  17. package/dist/node/WranglerDevServer/WranglerDevServer.js.map +1 -0
  18. package/dist/node/WranglerDevServer/WranglerDevServer.test.d.ts +2 -0
  19. package/dist/node/WranglerDevServer/WranglerDevServer.test.d.ts.map +1 -0
  20. package/dist/node/WranglerDevServer/WranglerDevServer.test.js +186 -0
  21. package/dist/node/WranglerDevServer/WranglerDevServer.test.js.map +1 -0
  22. package/dist/node/WranglerDevServer/fixtures/cf-worker.d.ts +8 -0
  23. package/dist/node/WranglerDevServer/fixtures/cf-worker.d.ts.map +1 -0
  24. package/dist/node/WranglerDevServer/fixtures/cf-worker.js +11 -0
  25. package/dist/node/WranglerDevServer/fixtures/cf-worker.js.map +1 -0
  26. package/dist/node/WranglerDevServer/process-tree-manager.d.ts +55 -0
  27. package/dist/node/WranglerDevServer/process-tree-manager.d.ts.map +1 -0
  28. package/dist/node/WranglerDevServer/process-tree-manager.js +178 -0
  29. package/dist/node/WranglerDevServer/process-tree-manager.js.map +1 -0
  30. package/dist/node/cmd.d.ts +27 -0
  31. package/dist/node/cmd.d.ts.map +1 -0
  32. package/dist/node/cmd.js +55 -0
  33. package/dist/node/cmd.js.map +1 -0
  34. package/dist/node/mod.d.ts +7 -13
  35. package/dist/node/mod.d.ts.map +1 -1
  36. package/dist/node/mod.js +22 -37
  37. package/dist/node/mod.js.map +1 -1
  38. package/dist/node-vitest/Vitest.d.ts +52 -0
  39. package/dist/node-vitest/Vitest.d.ts.map +1 -0
  40. package/dist/node-vitest/Vitest.js +98 -0
  41. package/dist/node-vitest/Vitest.js.map +1 -0
  42. package/dist/node-vitest/Vitest.test.d.ts +2 -0
  43. package/dist/node-vitest/Vitest.test.d.ts.map +1 -0
  44. package/dist/node-vitest/Vitest.test.js +59 -0
  45. package/dist/node-vitest/Vitest.test.js.map +1 -0
  46. package/dist/node-vitest/global.d.ts +2 -0
  47. package/dist/node-vitest/global.d.ts.map +1 -0
  48. package/dist/node-vitest/{polyfill.js → global.js} +1 -1
  49. package/dist/node-vitest/global.js.map +1 -0
  50. package/dist/node-vitest/mod.d.ts +2 -1
  51. package/dist/node-vitest/mod.d.ts.map +1 -1
  52. package/dist/node-vitest/mod.js +2 -1
  53. package/dist/node-vitest/mod.js.map +1 -1
  54. package/package.json +16 -23
  55. package/src/node/DockerComposeService/DockerComposeService.test.ts +91 -0
  56. package/src/node/DockerComposeService/DockerComposeService.ts +252 -0
  57. package/src/node/DockerComposeService/test-fixtures/docker-compose.yml +4 -0
  58. package/src/node/FileLogger.ts +206 -0
  59. package/src/node/WranglerDevServer/WranglerDevServer.test.ts +268 -0
  60. package/src/node/WranglerDevServer/WranglerDevServer.ts +206 -0
  61. package/src/node/WranglerDevServer/fixtures/cf-worker.ts +11 -0
  62. package/src/node/WranglerDevServer/fixtures/wrangler.toml +11 -0
  63. package/src/node/WranglerDevServer/process-tree-manager.ts +263 -0
  64. package/src/node/cmd.ts +99 -0
  65. package/src/node/mod.ts +39 -77
  66. package/src/node-vitest/Vitest.test.ts +101 -0
  67. package/src/node-vitest/Vitest.ts +221 -0
  68. package/src/node-vitest/mod.ts +3 -1
  69. package/dist/node-vitest/polyfill.d.ts +0 -2
  70. package/dist/node-vitest/polyfill.d.ts.map +0 -1
  71. package/dist/node-vitest/polyfill.js.map +0 -1
  72. /package/src/node-vitest/{polyfill.ts → global.ts} +0 -0
@@ -0,0 +1,221 @@
1
+ import * as inspector from 'node:inspector'
2
+ import type * as Vitest from '@effect/vitest'
3
+ import { IS_CI } from '@livestore/utils'
4
+ import {
5
+ type Cause,
6
+ Duration,
7
+ Effect,
8
+ type FastCheck as FC,
9
+ identity,
10
+ Layer,
11
+ type OtelTracer,
12
+ Predicate,
13
+ type Schema,
14
+ type Scope,
15
+ } from '@livestore/utils/effect'
16
+ import { OtelLiveDummy } from '@livestore/utils/node'
17
+ import { OtelLiveHttp } from '../node/mod.ts'
18
+
19
+ export * from '@effect/vitest'
20
+
21
+ export const DEBUGGER_ACTIVE = Boolean(process.env.DEBUGGER_ACTIVE ?? inspector.url() !== undefined)
22
+
23
+ export const makeWithTestCtx =
24
+ <R1 = never, E1 = never>(ctxParams: WithTestCtxParams<R1, E1>) =>
25
+ (testContext: Vitest.TestContext) =>
26
+ withTestCtx(testContext, ctxParams)
27
+
28
+ export type WithTestCtxParams<R1 = never, E1 = never> = {
29
+ suffix?: string
30
+ makeLayer?: (testContext: Vitest.TestContext) => Layer.Layer<R1, E1, Scope.Scope>
31
+ timeout?: Duration.DurationInput
32
+ forceOtel?: boolean
33
+ }
34
+
35
+ export const withTestCtx =
36
+ <R1 = never, E1 = never>(
37
+ testContext: Vitest.TestContext,
38
+ {
39
+ suffix,
40
+ makeLayer,
41
+ timeout = IS_CI ? 60_000 : 10_000,
42
+ forceOtel = false,
43
+ }: {
44
+ suffix?: string
45
+ makeLayer?: (testContext: Vitest.TestContext) => Layer.Layer<R1, E1, Scope.Scope>
46
+ timeout?: Duration.DurationInput
47
+ forceOtel?: boolean
48
+ } = {},
49
+ ) =>
50
+ <A, E>(
51
+ self: Effect.Effect<A, E, Scope.Scope | OtelTracer.OtelTracer | R1>,
52
+ ): Effect.Effect<A, E | Cause.TimeoutException | E1, Scope.Scope> => {
53
+ const spanName = `${testContext.task.suite?.name}:${testContext.task.name}${suffix ? `:${suffix}` : ''}`
54
+ const layer = makeLayer?.(testContext)
55
+
56
+ const otelLayer =
57
+ DEBUGGER_ACTIVE || forceOtel
58
+ ? OtelLiveHttp({ rootSpanName: spanName, serviceName: 'vitest-runner', skipLogUrl: false })
59
+ : OtelLiveDummy
60
+
61
+ const combinedLayer = (layer ?? Layer.empty).pipe(Layer.provideMerge(otelLayer))
62
+
63
+ return self.pipe(
64
+ DEBUGGER_ACTIVE
65
+ ? identity
66
+ : Effect.logWarnIfTakesLongerThan({
67
+ duration: Duration.toMillis(timeout) * 0.8,
68
+ label: `${spanName} approaching timeout (timeout: ${Duration.format(timeout)})`,
69
+ }),
70
+ DEBUGGER_ACTIVE ? identity : Effect.timeout(timeout),
71
+ Effect.provide(combinedLayer),
72
+ Effect.scoped, // We need to scope the effect manually here because otherwise the span is not closed
73
+ Effect.annotateLogs({ suffix }),
74
+ ) as any
75
+ }
76
+
77
+ /**
78
+ * Shared properties for all enhanced test context phases
79
+ */
80
+ export interface EnhancedTestContextBase {
81
+ numRuns: number
82
+ /** 0-based index */
83
+ runIndex: number
84
+ /** Total number of executions including initial runs and shrinking attempts */
85
+ totalExecutions: number
86
+ }
87
+
88
+ /**
89
+ * Enhanced context for property-based tests that includes shrinking phase information
90
+ */
91
+ export type EnhancedTestContext =
92
+ | (EnhancedTestContextBase & {
93
+ _tag: 'initial'
94
+ })
95
+ | (EnhancedTestContextBase & {
96
+ _tag: 'shrinking'
97
+ /** Number of shrinking attempts */
98
+ shrinkAttempt: number
99
+ })
100
+
101
+ /**
102
+ * Normalizes propOptions to ensure @effect/vitest receives correct fastCheck structure
103
+ */
104
+ const normalizePropOptions = <Arbs extends Vitest.Vitest.Arbitraries>(
105
+ propOptions:
106
+ | number
107
+ | (Vitest.TestOptions & {
108
+ fastCheck?: FC.Parameters<{
109
+ [K in keyof Arbs]: Arbs[K] extends FC.Arbitrary<infer T> ? T : Schema.Schema.Type<Arbs[K]>
110
+ }>
111
+ }),
112
+ ): Vitest.TestOptions & {
113
+ fastCheck?: FC.Parameters<{
114
+ [K in keyof Arbs]: Arbs[K] extends FC.Arbitrary<infer T> ? T : Schema.Schema.Type<Arbs[K]>
115
+ }>
116
+ } => {
117
+ // If it's a number, treat as timeout and add our default fastCheck
118
+ if (!Predicate.isObject(propOptions)) {
119
+ return {
120
+ timeout: propOptions,
121
+ fastCheck: { numRuns: 100 },
122
+ }
123
+ }
124
+
125
+ // If no fastCheck property, add it with our default numRuns
126
+ if (!propOptions.fastCheck) {
127
+ return {
128
+ ...propOptions,
129
+ fastCheck: { numRuns: 100 },
130
+ }
131
+ }
132
+
133
+ // If fastCheck exists but no numRuns, add our default
134
+ if (propOptions.fastCheck && !propOptions.fastCheck.numRuns) {
135
+ return {
136
+ ...propOptions,
137
+ fastCheck: {
138
+ ...propOptions.fastCheck,
139
+ numRuns: 100,
140
+ },
141
+ }
142
+ }
143
+
144
+ // If everything is properly structured, pass through
145
+ return propOptions
146
+ }
147
+
148
+ /**
149
+ * Equivalent to Vitest.prop but provides enhanced context including shrinking progress visibility
150
+ *
151
+ * This function enhances the standard property-based testing by providing clear information about
152
+ * whether FastCheck is in the initial testing phase or the shrinking phase, solving the confusion
153
+ * where tests show "Run 26/6" when FastCheck's shrinking algorithm is active.
154
+ *
155
+ * TODO: allow for upper timelimit instead of / additional to `numRuns`
156
+ *
157
+ * TODO: Upstream to Effect
158
+ */
159
+ export const asProp = <Arbs extends Vitest.Vitest.Arbitraries, A, E, R>(
160
+ api: Vitest.Vitest.Tester<R>,
161
+ name: string,
162
+ arbitraries: Arbs,
163
+ test: Vitest.Vitest.TestFunction<
164
+ A,
165
+ E,
166
+ R,
167
+ [
168
+ { [K in keyof Arbs]: Arbs[K] extends FC.Arbitrary<infer T> ? T : Schema.Schema.Type<Arbs[K]> },
169
+ Vitest.TestContext,
170
+ EnhancedTestContext,
171
+ ]
172
+ >,
173
+ propOptions:
174
+ | number
175
+ | (Vitest.TestOptions & {
176
+ fastCheck?: FC.Parameters<{
177
+ [K in keyof Arbs]: Arbs[K] extends FC.Arbitrary<infer T> ? T : Schema.Schema.Type<Arbs[K]>
178
+ }>
179
+ }),
180
+ ) => {
181
+ const normalizedPropOptions = normalizePropOptions(propOptions)
182
+ const numRuns = normalizedPropOptions.fastCheck?.numRuns ?? 100
183
+ let runIndex = 0
184
+ let shrinkAttempts = 0
185
+ let totalExecutions = 0
186
+
187
+ return api.prop(
188
+ name,
189
+ arbitraries,
190
+ (properties, ctx) => {
191
+ if (ctx.signal.aborted) {
192
+ return ctx.skip('Test aborted')
193
+ }
194
+
195
+ totalExecutions++
196
+ const isInShrinkingPhase = runIndex >= numRuns
197
+
198
+ if (isInShrinkingPhase) {
199
+ shrinkAttempts++
200
+ }
201
+
202
+ const enhancedContext: EnhancedTestContext = isInShrinkingPhase
203
+ ? {
204
+ _tag: 'shrinking',
205
+ numRuns,
206
+ runIndex: runIndex++,
207
+ shrinkAttempt: shrinkAttempts,
208
+ totalExecutions,
209
+ }
210
+ : {
211
+ _tag: 'initial',
212
+ numRuns,
213
+ runIndex: runIndex++,
214
+ totalExecutions,
215
+ }
216
+
217
+ return test(properties, ctx, enhancedContext)
218
+ },
219
+ normalizedPropOptions,
220
+ )
221
+ }
@@ -1 +1,3 @@
1
- export * as Vitest from '@effect/vitest'
1
+ import './global.ts'
2
+
3
+ export * as Vitest from './Vitest.ts'
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=polyfill.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"polyfill.d.ts","sourceRoot":"","sources":["../../src/node-vitest/polyfill.ts"],"names":[],"mappings":""}
@@ -1 +0,0 @@
1
- {"version":3,"file":"polyfill.js","sourceRoot":"","sources":["../../src/node-vitest/polyfill.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,CAAC,KAAK,GAAG,IAAI,CAAA"}
File without changes