ai-evaluate 0.1.0
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/.turbo/turbo-build.log +5 -0
- package/.turbo/turbo-test.log +51 -0
- package/README.md +420 -0
- package/coverage/base.css +224 -0
- package/coverage/block-navigation.js +87 -0
- package/coverage/coverage-final.json +4 -0
- package/coverage/evaluate.ts.html +574 -0
- package/coverage/favicon.png +0 -0
- package/coverage/index.html +146 -0
- package/coverage/index.ts.html +145 -0
- package/coverage/prettify.css +1 -0
- package/coverage/prettify.js +2 -0
- package/coverage/sort-arrow-sprite.png +0 -0
- package/coverage/sorter.js +210 -0
- package/coverage/worker-template.ts.html +1948 -0
- package/dist/evaluate.d.ts +62 -0
- package/dist/evaluate.d.ts.map +1 -0
- package/dist/evaluate.js +188 -0
- package/dist/evaluate.js.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -0
- package/dist/types.d.ts +165 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +5 -0
- package/dist/types.js.map +1 -0
- package/dist/worker-template.d.ts +40 -0
- package/dist/worker-template.d.ts.map +1 -0
- package/dist/worker-template.js +3628 -0
- package/dist/worker-template.js.map +1 -0
- package/package.json +46 -0
- package/src/evaluate.ts +217 -0
- package/src/index.ts +21 -0
- package/src/types.ts +174 -0
- package/src/worker-template.ts +3677 -0
- package/test/evaluate-extended.test.ts +469 -0
- package/test/evaluate.test.ts +253 -0
- package/test/index.test.ts +95 -0
- package/test/worker-template.test.ts +430 -0
- package/tsconfig.json +22 -0
- package/vitest.config.ts +16 -0
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest'
|
|
2
|
+
|
|
3
|
+
describe('index exports', () => {
|
|
4
|
+
it('exports evaluate function', async () => {
|
|
5
|
+
const { evaluate } = await import('../src/index.js')
|
|
6
|
+
expect(typeof evaluate).toBe('function')
|
|
7
|
+
})
|
|
8
|
+
|
|
9
|
+
it('exports createEvaluator function', async () => {
|
|
10
|
+
const { createEvaluator } = await import('../src/index.js')
|
|
11
|
+
expect(typeof createEvaluator).toBe('function')
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
it('exports types', async () => {
|
|
15
|
+
// Types are compile-time only, so we just check the module loads
|
|
16
|
+
await import('../src/index.js')
|
|
17
|
+
})
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
describe('types', () => {
|
|
21
|
+
it('EvaluateOptions interface is usable', async () => {
|
|
22
|
+
const { evaluate } = await import('../src/index.js')
|
|
23
|
+
|
|
24
|
+
// Test that options conform to EvaluateOptions
|
|
25
|
+
const options = {
|
|
26
|
+
module: 'exports.x = 1;',
|
|
27
|
+
tests: 'it("test", () => {});',
|
|
28
|
+
script: 'return 1;',
|
|
29
|
+
timeout: 5000,
|
|
30
|
+
env: { FOO: 'bar' },
|
|
31
|
+
fetch: null as null
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const result = await evaluate(options)
|
|
35
|
+
expect(result).toHaveProperty('success')
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
it('EvaluateResult has correct shape', async () => {
|
|
39
|
+
const { evaluate } = await import('../src/index.js')
|
|
40
|
+
|
|
41
|
+
const result = await evaluate({ script: 'return 42;' })
|
|
42
|
+
|
|
43
|
+
expect(result).toHaveProperty('success')
|
|
44
|
+
expect(result).toHaveProperty('logs')
|
|
45
|
+
expect(result).toHaveProperty('duration')
|
|
46
|
+
expect(typeof result.success).toBe('boolean')
|
|
47
|
+
expect(Array.isArray(result.logs)).toBe(true)
|
|
48
|
+
expect(typeof result.duration).toBe('number')
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
it('LogEntry has correct shape', async () => {
|
|
52
|
+
const { evaluate } = await import('../src/index.js')
|
|
53
|
+
|
|
54
|
+
const result = await evaluate({
|
|
55
|
+
script: 'console.log("test"); return true;'
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
const log = result.logs[0]
|
|
59
|
+
expect(log).toHaveProperty('level')
|
|
60
|
+
expect(log).toHaveProperty('message')
|
|
61
|
+
expect(log).toHaveProperty('timestamp')
|
|
62
|
+
expect(['log', 'warn', 'error', 'info', 'debug']).toContain(log.level)
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
it('TestResults has correct shape when tests provided', async () => {
|
|
66
|
+
const { evaluate } = await import('../src/index.js')
|
|
67
|
+
|
|
68
|
+
const result = await evaluate({
|
|
69
|
+
tests: 'it("test", () => { expect(1).toBe(1); });'
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
expect(result.testResults).toBeDefined()
|
|
73
|
+
expect(result.testResults).toHaveProperty('total')
|
|
74
|
+
expect(result.testResults).toHaveProperty('passed')
|
|
75
|
+
expect(result.testResults).toHaveProperty('failed')
|
|
76
|
+
expect(result.testResults).toHaveProperty('skipped')
|
|
77
|
+
expect(result.testResults).toHaveProperty('tests')
|
|
78
|
+
expect(result.testResults).toHaveProperty('duration')
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
it('TestResult has correct shape', async () => {
|
|
82
|
+
const { evaluate } = await import('../src/index.js')
|
|
83
|
+
|
|
84
|
+
const result = await evaluate({
|
|
85
|
+
tests: 'it("my test", () => {});'
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
const test = result.testResults?.tests[0]
|
|
89
|
+
expect(test).toHaveProperty('name')
|
|
90
|
+
expect(test).toHaveProperty('passed')
|
|
91
|
+
expect(test).toHaveProperty('duration')
|
|
92
|
+
expect(test?.name).toBe('my test')
|
|
93
|
+
expect(test?.passed).toBe(true)
|
|
94
|
+
})
|
|
95
|
+
})
|
|
@@ -0,0 +1,430 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest'
|
|
2
|
+
import { generateWorkerCode, generateDevWorkerCode } from '../src/worker-template.js'
|
|
3
|
+
|
|
4
|
+
describe('generateWorkerCode (production)', () => {
|
|
5
|
+
describe('basic structure', () => {
|
|
6
|
+
it('generates valid worker code', () => {
|
|
7
|
+
const code = generateWorkerCode({})
|
|
8
|
+
expect(code).toContain('export default')
|
|
9
|
+
expect(code).toContain('async fetch(request, env)')
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
it('includes console capture', () => {
|
|
13
|
+
const code = generateWorkerCode({})
|
|
14
|
+
expect(code).toContain('captureConsole')
|
|
15
|
+
expect(code).toContain('console.log = captureConsole')
|
|
16
|
+
expect(code).toContain('console.warn = captureConsole')
|
|
17
|
+
expect(code).toContain('console.error = captureConsole')
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
it('checks for TEST service binding', () => {
|
|
21
|
+
const code = generateWorkerCode({})
|
|
22
|
+
expect(code).toContain('env.TEST')
|
|
23
|
+
expect(code).toContain('TEST service binding not available')
|
|
24
|
+
})
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
describe('module embedding', () => {
|
|
28
|
+
it('embeds module code when provided', () => {
|
|
29
|
+
const code = generateWorkerCode({
|
|
30
|
+
module: 'exports.foo = 42;'
|
|
31
|
+
})
|
|
32
|
+
expect(code).toContain('exports.foo = 42;')
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
it('extracts export names from exports.name pattern', () => {
|
|
36
|
+
const code = generateWorkerCode({
|
|
37
|
+
module: 'exports.add = (a, b) => a + b; exports.sub = (a, b) => a - b;'
|
|
38
|
+
})
|
|
39
|
+
expect(code).toContain('const { add, sub } = exports')
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
it('extracts export names from exports["name"] pattern', () => {
|
|
43
|
+
const code = generateWorkerCode({
|
|
44
|
+
module: 'exports["myFunc"] = () => {};'
|
|
45
|
+
})
|
|
46
|
+
expect(code).toContain('myFunc')
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
it('handles no module code', () => {
|
|
50
|
+
const code = generateWorkerCode({})
|
|
51
|
+
expect(code).toContain('// No module code provided')
|
|
52
|
+
})
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
describe('test embedding', () => {
|
|
56
|
+
it('embeds test code when provided', () => {
|
|
57
|
+
const code = generateWorkerCode({
|
|
58
|
+
tests: 'describe("test", () => {});'
|
|
59
|
+
})
|
|
60
|
+
expect(code).toContain('describe("test", () => {});')
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
it('handles no test code', () => {
|
|
64
|
+
const code = generateWorkerCode({})
|
|
65
|
+
expect(code).toContain('// No test code provided')
|
|
66
|
+
})
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
describe('script embedding', () => {
|
|
70
|
+
it('embeds script code when provided', () => {
|
|
71
|
+
const code = generateWorkerCode({
|
|
72
|
+
script: 'return 42;'
|
|
73
|
+
})
|
|
74
|
+
expect(code).toContain('return 42;')
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
it('handles no script code', () => {
|
|
78
|
+
const code = generateWorkerCode({})
|
|
79
|
+
expect(code).toContain('// No script code provided')
|
|
80
|
+
})
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
describe('RPC setup', () => {
|
|
84
|
+
it('connects to test service via RPC', () => {
|
|
85
|
+
const code = generateWorkerCode({})
|
|
86
|
+
expect(code).toContain('env.TEST.connect()')
|
|
87
|
+
expect(code).toContain('const testService = await env.TEST.connect()')
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
it('sets up test functions from RPC service', () => {
|
|
91
|
+
const code = generateWorkerCode({})
|
|
92
|
+
expect(code).toContain('const describe = (name, fn) => testService.describe(name, fn)')
|
|
93
|
+
expect(code).toContain('const it = (name, fn) => testService.it(name, fn)')
|
|
94
|
+
expect(code).toContain('const expect = (value, message) => testService.expect(value, message)')
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
it('includes skip and only modifiers', () => {
|
|
98
|
+
const code = generateWorkerCode({})
|
|
99
|
+
expect(code).toContain('it.skip')
|
|
100
|
+
expect(code).toContain('it.only')
|
|
101
|
+
expect(code).toContain('test.skip')
|
|
102
|
+
expect(code).toContain('test.only')
|
|
103
|
+
})
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
describe('capnweb RPC', () => {
|
|
107
|
+
it('imports capnweb', () => {
|
|
108
|
+
const code = generateWorkerCode({})
|
|
109
|
+
expect(code).toContain("import { RpcTarget, newWorkersRpcResponse } from 'capnweb'")
|
|
110
|
+
})
|
|
111
|
+
|
|
112
|
+
it('creates ExportsRpcTarget class', () => {
|
|
113
|
+
const code = generateWorkerCode({})
|
|
114
|
+
expect(code).toContain('class ExportsRpcTarget extends RpcTarget')
|
|
115
|
+
})
|
|
116
|
+
|
|
117
|
+
it('handles /rpc route', () => {
|
|
118
|
+
const code = generateWorkerCode({})
|
|
119
|
+
expect(code).toContain("url.pathname === '/rpc'")
|
|
120
|
+
expect(code).toContain('newWorkersRpcResponse(request, new ExportsRpcTarget())')
|
|
121
|
+
})
|
|
122
|
+
|
|
123
|
+
it('handles GET / route for info', () => {
|
|
124
|
+
const code = generateWorkerCode({})
|
|
125
|
+
expect(code).toContain("url.pathname === '/'")
|
|
126
|
+
expect(code).toContain("exports: Object.keys(exports)")
|
|
127
|
+
})
|
|
128
|
+
})
|
|
129
|
+
|
|
130
|
+
describe('GET /:name endpoint', () => {
|
|
131
|
+
it('handles GET requests to export names', () => {
|
|
132
|
+
const code = generateWorkerCode({})
|
|
133
|
+
expect(code).toContain("request.method === 'GET'")
|
|
134
|
+
expect(code).toContain('url.pathname.slice(1)')
|
|
135
|
+
expect(code).toContain('exports[name]')
|
|
136
|
+
})
|
|
137
|
+
|
|
138
|
+
it('returns non-function exports directly', () => {
|
|
139
|
+
const code = generateWorkerCode({})
|
|
140
|
+
expect(code).toContain("typeof value !== 'function'")
|
|
141
|
+
expect(code).toContain('return Response.json({ result: value })')
|
|
142
|
+
})
|
|
143
|
+
|
|
144
|
+
it('supports args query parameter with JSON array', () => {
|
|
145
|
+
const code = generateWorkerCode({})
|
|
146
|
+
expect(code).toContain("url.searchParams.get('args')")
|
|
147
|
+
expect(code).toContain('JSON.parse(argsParam)')
|
|
148
|
+
})
|
|
149
|
+
|
|
150
|
+
it('supports named query parameters as object', () => {
|
|
151
|
+
const code = generateWorkerCode({})
|
|
152
|
+
expect(code).toContain('Object.fromEntries(url.searchParams.entries())')
|
|
153
|
+
})
|
|
154
|
+
|
|
155
|
+
it('returns 404 for missing exports', () => {
|
|
156
|
+
const code = generateWorkerCode({})
|
|
157
|
+
expect(code).toContain('not found')
|
|
158
|
+
expect(code).toContain('status: 404')
|
|
159
|
+
})
|
|
160
|
+
})
|
|
161
|
+
|
|
162
|
+
describe('ES module syntax support', () => {
|
|
163
|
+
it('transforms export const to CommonJS', () => {
|
|
164
|
+
const code = generateWorkerCode({
|
|
165
|
+
module: 'export const add = (a, b) => a + b'
|
|
166
|
+
})
|
|
167
|
+
expect(code).toContain('const add = exports.add =')
|
|
168
|
+
expect(code).toContain('const { add } = exports')
|
|
169
|
+
})
|
|
170
|
+
|
|
171
|
+
it('transforms export function to CommonJS', () => {
|
|
172
|
+
const code = generateWorkerCode({
|
|
173
|
+
module: 'export function multiply(a, b) { return a * b }'
|
|
174
|
+
})
|
|
175
|
+
expect(code).toContain('function multiply')
|
|
176
|
+
expect(code).toContain('exports.multiply = multiply')
|
|
177
|
+
expect(code).toContain('const { multiply } = exports')
|
|
178
|
+
})
|
|
179
|
+
|
|
180
|
+
it('handles mixed ES and CommonJS exports', () => {
|
|
181
|
+
const code = generateWorkerCode({
|
|
182
|
+
module: `
|
|
183
|
+
export const foo = 1
|
|
184
|
+
exports.bar = 2
|
|
185
|
+
`
|
|
186
|
+
})
|
|
187
|
+
expect(code).toContain('const foo = exports.foo =')
|
|
188
|
+
expect(code).toContain('exports.bar = 2')
|
|
189
|
+
expect(code).toContain('foo')
|
|
190
|
+
expect(code).toContain('bar')
|
|
191
|
+
})
|
|
192
|
+
})
|
|
193
|
+
|
|
194
|
+
describe('script auto-return', () => {
|
|
195
|
+
it('auto-returns single expressions', () => {
|
|
196
|
+
const code = generateWorkerCode({
|
|
197
|
+
script: 'add(1, 2)'
|
|
198
|
+
})
|
|
199
|
+
expect(code).toContain('return add(1, 2)')
|
|
200
|
+
})
|
|
201
|
+
|
|
202
|
+
it('does not modify scripts with return', () => {
|
|
203
|
+
const code = generateWorkerCode({
|
|
204
|
+
script: 'return add(1, 2)'
|
|
205
|
+
})
|
|
206
|
+
expect(code).toContain('return add(1, 2)')
|
|
207
|
+
expect(code).not.toContain('return return')
|
|
208
|
+
})
|
|
209
|
+
|
|
210
|
+
it('does not modify throw statements', () => {
|
|
211
|
+
const code = generateWorkerCode({
|
|
212
|
+
script: 'throw new Error("test")'
|
|
213
|
+
})
|
|
214
|
+
expect(code).toContain('throw new Error("test")')
|
|
215
|
+
expect(code).not.toContain('return throw')
|
|
216
|
+
})
|
|
217
|
+
|
|
218
|
+
it('auto-returns last expression in multi-line scripts', () => {
|
|
219
|
+
const code = generateWorkerCode({
|
|
220
|
+
script: `
|
|
221
|
+
const x = 1
|
|
222
|
+
x + 1
|
|
223
|
+
`
|
|
224
|
+
})
|
|
225
|
+
expect(code).toContain('return x + 1')
|
|
226
|
+
})
|
|
227
|
+
})
|
|
228
|
+
})
|
|
229
|
+
|
|
230
|
+
describe('generateDevWorkerCode (development)', () => {
|
|
231
|
+
describe('basic structure', () => {
|
|
232
|
+
it('generates valid worker code', () => {
|
|
233
|
+
const code = generateDevWorkerCode({})
|
|
234
|
+
expect(code).toContain('export default')
|
|
235
|
+
expect(code).toContain('async fetch(request, env)')
|
|
236
|
+
})
|
|
237
|
+
|
|
238
|
+
it('includes embedded test framework', () => {
|
|
239
|
+
const code = generateDevWorkerCode({})
|
|
240
|
+
expect(code).toContain('const describe = (name, fn)')
|
|
241
|
+
expect(code).toContain('const it = (name, fn)')
|
|
242
|
+
expect(code).toContain('const expect = (actual)')
|
|
243
|
+
})
|
|
244
|
+
|
|
245
|
+
it('does not require TEST service', () => {
|
|
246
|
+
const code = generateDevWorkerCode({})
|
|
247
|
+
expect(code).not.toContain('env.TEST')
|
|
248
|
+
})
|
|
249
|
+
})
|
|
250
|
+
|
|
251
|
+
describe('embedded test framework', () => {
|
|
252
|
+
it('includes describe function', () => {
|
|
253
|
+
const code = generateDevWorkerCode({})
|
|
254
|
+
expect(code).toContain('const describe = (name, fn)')
|
|
255
|
+
expect(code).toContain('currentDescribe')
|
|
256
|
+
})
|
|
257
|
+
|
|
258
|
+
it('includes it/test functions', () => {
|
|
259
|
+
const code = generateDevWorkerCode({})
|
|
260
|
+
expect(code).toContain('const it = (name, fn)')
|
|
261
|
+
expect(code).toContain('const test = it')
|
|
262
|
+
})
|
|
263
|
+
|
|
264
|
+
it('includes skip and only', () => {
|
|
265
|
+
const code = generateDevWorkerCode({})
|
|
266
|
+
expect(code).toContain('it.skip')
|
|
267
|
+
expect(code).toContain('it.only')
|
|
268
|
+
})
|
|
269
|
+
|
|
270
|
+
it('includes beforeEach/afterEach hooks', () => {
|
|
271
|
+
const code = generateDevWorkerCode({})
|
|
272
|
+
expect(code).toContain('const beforeEach = (fn)')
|
|
273
|
+
expect(code).toContain('const afterEach = (fn)')
|
|
274
|
+
})
|
|
275
|
+
|
|
276
|
+
it('includes deep equality check', () => {
|
|
277
|
+
const code = generateDevWorkerCode({})
|
|
278
|
+
expect(code).toContain('const deepEqual = (a, b)')
|
|
279
|
+
})
|
|
280
|
+
})
|
|
281
|
+
|
|
282
|
+
describe('embedded expect matchers', () => {
|
|
283
|
+
it('includes toBe', () => {
|
|
284
|
+
const code = generateDevWorkerCode({})
|
|
285
|
+
expect(code).toContain('toBe:')
|
|
286
|
+
})
|
|
287
|
+
|
|
288
|
+
it('includes toEqual', () => {
|
|
289
|
+
const code = generateDevWorkerCode({})
|
|
290
|
+
expect(code).toContain('toEqual:')
|
|
291
|
+
})
|
|
292
|
+
|
|
293
|
+
it('includes toStrictEqual', () => {
|
|
294
|
+
const code = generateDevWorkerCode({})
|
|
295
|
+
expect(code).toContain('toStrictEqual:')
|
|
296
|
+
})
|
|
297
|
+
|
|
298
|
+
it('includes toBeTruthy', () => {
|
|
299
|
+
const code = generateDevWorkerCode({})
|
|
300
|
+
expect(code).toContain('toBeTruthy:')
|
|
301
|
+
})
|
|
302
|
+
|
|
303
|
+
it('includes toBeFalsy', () => {
|
|
304
|
+
const code = generateDevWorkerCode({})
|
|
305
|
+
expect(code).toContain('toBeFalsy:')
|
|
306
|
+
})
|
|
307
|
+
|
|
308
|
+
it('includes toBeNull', () => {
|
|
309
|
+
const code = generateDevWorkerCode({})
|
|
310
|
+
expect(code).toContain('toBeNull:')
|
|
311
|
+
})
|
|
312
|
+
|
|
313
|
+
it('includes toBeUndefined', () => {
|
|
314
|
+
const code = generateDevWorkerCode({})
|
|
315
|
+
expect(code).toContain('toBeUndefined:')
|
|
316
|
+
})
|
|
317
|
+
|
|
318
|
+
it('includes toBeDefined', () => {
|
|
319
|
+
const code = generateDevWorkerCode({})
|
|
320
|
+
expect(code).toContain('toBeDefined:')
|
|
321
|
+
})
|
|
322
|
+
|
|
323
|
+
it('includes toBeNaN', () => {
|
|
324
|
+
const code = generateDevWorkerCode({})
|
|
325
|
+
expect(code).toContain('toBeNaN:')
|
|
326
|
+
})
|
|
327
|
+
|
|
328
|
+
it('includes toContain', () => {
|
|
329
|
+
const code = generateDevWorkerCode({})
|
|
330
|
+
expect(code).toContain('toContain:')
|
|
331
|
+
})
|
|
332
|
+
|
|
333
|
+
it('includes toContainEqual', () => {
|
|
334
|
+
const code = generateDevWorkerCode({})
|
|
335
|
+
expect(code).toContain('toContainEqual:')
|
|
336
|
+
})
|
|
337
|
+
|
|
338
|
+
it('includes toHaveLength', () => {
|
|
339
|
+
const code = generateDevWorkerCode({})
|
|
340
|
+
expect(code).toContain('toHaveLength:')
|
|
341
|
+
})
|
|
342
|
+
|
|
343
|
+
it('includes toHaveProperty', () => {
|
|
344
|
+
const code = generateDevWorkerCode({})
|
|
345
|
+
expect(code).toContain('toHaveProperty:')
|
|
346
|
+
})
|
|
347
|
+
|
|
348
|
+
it('includes toMatchObject', () => {
|
|
349
|
+
const code = generateDevWorkerCode({})
|
|
350
|
+
expect(code).toContain('toMatchObject:')
|
|
351
|
+
})
|
|
352
|
+
|
|
353
|
+
it('includes toThrow', () => {
|
|
354
|
+
const code = generateDevWorkerCode({})
|
|
355
|
+
expect(code).toContain('toThrow:')
|
|
356
|
+
})
|
|
357
|
+
|
|
358
|
+
it('includes toBeGreaterThan', () => {
|
|
359
|
+
const code = generateDevWorkerCode({})
|
|
360
|
+
expect(code).toContain('toBeGreaterThan:')
|
|
361
|
+
})
|
|
362
|
+
|
|
363
|
+
it('includes toBeLessThan', () => {
|
|
364
|
+
const code = generateDevWorkerCode({})
|
|
365
|
+
expect(code).toContain('toBeLessThan:')
|
|
366
|
+
})
|
|
367
|
+
|
|
368
|
+
it('includes toBeCloseTo', () => {
|
|
369
|
+
const code = generateDevWorkerCode({})
|
|
370
|
+
expect(code).toContain('toBeCloseTo:')
|
|
371
|
+
})
|
|
372
|
+
|
|
373
|
+
it('includes toMatch', () => {
|
|
374
|
+
const code = generateDevWorkerCode({})
|
|
375
|
+
expect(code).toContain('toMatch:')
|
|
376
|
+
})
|
|
377
|
+
|
|
378
|
+
it('includes toBeInstanceOf', () => {
|
|
379
|
+
const code = generateDevWorkerCode({})
|
|
380
|
+
expect(code).toContain('toBeInstanceOf:')
|
|
381
|
+
})
|
|
382
|
+
|
|
383
|
+
it('includes toBeTypeOf', () => {
|
|
384
|
+
const code = generateDevWorkerCode({})
|
|
385
|
+
expect(code).toContain('toBeTypeOf:')
|
|
386
|
+
})
|
|
387
|
+
|
|
388
|
+
it('includes not matchers', () => {
|
|
389
|
+
const code = generateDevWorkerCode({})
|
|
390
|
+
expect(code).toContain('matchers.not = {')
|
|
391
|
+
})
|
|
392
|
+
|
|
393
|
+
it('includes resolves proxy', () => {
|
|
394
|
+
const code = generateDevWorkerCode({})
|
|
395
|
+
expect(code).toContain('matchers.resolves')
|
|
396
|
+
})
|
|
397
|
+
|
|
398
|
+
it('includes rejects proxy', () => {
|
|
399
|
+
const code = generateDevWorkerCode({})
|
|
400
|
+
expect(code).toContain('matchers.rejects')
|
|
401
|
+
})
|
|
402
|
+
})
|
|
403
|
+
|
|
404
|
+
describe('module embedding', () => {
|
|
405
|
+
it('embeds module code when provided', () => {
|
|
406
|
+
const code = generateDevWorkerCode({
|
|
407
|
+
module: 'exports.foo = 42;'
|
|
408
|
+
})
|
|
409
|
+
expect(code).toContain('exports.foo = 42;')
|
|
410
|
+
})
|
|
411
|
+
})
|
|
412
|
+
|
|
413
|
+
describe('test embedding', () => {
|
|
414
|
+
it('embeds test code when provided', () => {
|
|
415
|
+
const code = generateDevWorkerCode({
|
|
416
|
+
tests: 'describe("test", () => {});'
|
|
417
|
+
})
|
|
418
|
+
expect(code).toContain('describe("test", () => {});')
|
|
419
|
+
})
|
|
420
|
+
})
|
|
421
|
+
|
|
422
|
+
describe('script embedding', () => {
|
|
423
|
+
it('embeds script code when provided', () => {
|
|
424
|
+
const code = generateDevWorkerCode({
|
|
425
|
+
script: 'return 42;'
|
|
426
|
+
})
|
|
427
|
+
expect(code).toContain('return 42;')
|
|
428
|
+
})
|
|
429
|
+
})
|
|
430
|
+
})
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"module": "ESNext",
|
|
5
|
+
"moduleResolution": "bundler",
|
|
6
|
+
"lib": ["ES2022"],
|
|
7
|
+
"strict": true,
|
|
8
|
+
"esModuleInterop": true,
|
|
9
|
+
"skipLibCheck": true,
|
|
10
|
+
"forceConsistentCasingInFileNames": true,
|
|
11
|
+
"resolveJsonModule": true,
|
|
12
|
+
"declaration": true,
|
|
13
|
+
"declarationMap": true,
|
|
14
|
+
"sourceMap": true,
|
|
15
|
+
"isolatedModules": true,
|
|
16
|
+
"verbatimModuleSyntax": true,
|
|
17
|
+
"rootDir": "src",
|
|
18
|
+
"outDir": "dist"
|
|
19
|
+
},
|
|
20
|
+
"include": ["src/**/*"],
|
|
21
|
+
"exclude": ["node_modules", "dist", "**/*.test.ts", "**/*.spec.ts"]
|
|
22
|
+
}
|
package/vitest.config.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { defineConfig } from 'vitest/config'
|
|
2
|
+
|
|
3
|
+
export default defineConfig({
|
|
4
|
+
test: {
|
|
5
|
+
globals: false,
|
|
6
|
+
environment: 'node',
|
|
7
|
+
include: ['test/**/*.test.ts'],
|
|
8
|
+
testTimeout: 30000, // Allow time for Miniflare startup
|
|
9
|
+
coverage: {
|
|
10
|
+
provider: 'v8',
|
|
11
|
+
reporter: ['text', 'json', 'html'],
|
|
12
|
+
include: ['src/**/*.ts'],
|
|
13
|
+
exclude: ['src/types.ts']
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
})
|