toFailEvaluation accepts globals

This commit is contained in:
Chris Wanstrath 2025-10-29 20:50:03 -07:00
parent fa0b377eca
commit f81a9669cf

View File

@ -35,7 +35,7 @@ declare module 'bun:test' {
toMatchExpression(expected: string): T
toFailParse(): T
toEvaluateTo(expected: unknown, globals?: Record<string, any>): Promise<T>
toFailEvaluation(): Promise<T>
toFailEvaluation(globals?: Record<string, any>): Promise<T>
}
}
@ -99,8 +99,7 @@ expect.extend({
assert(typeof received === 'string', 'toEvaluateTo can only be used with string values')
try {
if (globals) setGlobals(Object.keys(globals))
const compiler = new Compiler(received)
const compiler = new Compiler(received, globals ? Object.keys(globals) : [])
const result = await run(compiler.bytecode, globals)
let value = VMResultToValue(result)
@ -121,12 +120,12 @@ expect.extend({
}
},
async toFailEvaluation(received) {
async toFailEvaluation(received, globals?: Record<string, any>) {
assert(typeof received === 'string', 'toFailEvaluation can only be used with string values')
try {
const compiler = new Compiler(received)
const vm = new VM(compiler.bytecode)
const compiler = new Compiler(received, globals ? Object.keys(globals) : [])
const vm = new VM(compiler.bytecode, globals)
const value = await vm.run()
return {