https://github.com/aarhus/twoworkersonequeue
GitHub
Contribute to aarhus/twoworkersonequeue development by creating an account on GitHub.
describe('bluegreen routing', () => { const mf = new Miniflare({ envPath: true, packagePath: true, wranglerConfigPath: true, scriptPath: 'dist/index.mjs', modules: true }) it('should route to the green worker', async () => { const response = await mf.dispatchFetch('http://127.0.0.1/parent', { method: 'GET' }) if (response) { const parsedResp = await response.text() expect(parsedResp).toEqual('Green Hello World!') } }) })
ReferenceError: clearImmediate is not definedput method of your bucket binding before passing it to your worker, and then mocking that implementation to throw?wrangler dev --local, or check out https://miniflare.dev/storage/durable-objects if you're using Miniflare directly. vitest environment? I have a worker that's both the producer & consumer of a queue, and in a test I'm calling worker.fetch directly via an import of main. worker.fetch sends a message to the queue. As far as I can tell, worker.queue is never called as a result of this send. Is that expected? Is there an idiomatic way to E2E test a queue like this in the vitest environment?vitest.config.ts's environmentOptions. See https://gist.github.com/mrbbot/a1d5ddc5d7fd2878d58cf5f8215e9a3a for an example.
scriptPath manually appears to have fixed it which is weird. I've then had to correctly setup --experimental-vm-modules now we're getting closer.Some functionality, such as asynchronous I/O (fetch, Cache API, KV)..... but its erroring during the request context.input instanceof Request check during the dispatchFetch handling. Which led me to - https://github.com/cloudflare/miniflare/issues/454npm i and it fixed a whole heap of things.packagePath: true option set?module set in package.json doing what was required for that above issue fixed it thodescribe('bluegreen routing', () => {
const mf = new Miniflare({
envPath: true,
packagePath: true,
wranglerConfigPath: true,
scriptPath: 'dist/index.mjs',
modules: true
})
it('should route to the green worker', async () => {
const response = await mf.dispatchFetch('http://127.0.0.1/parent', {
method: 'GET'
})
if (response) {
const parsedResp = await response.text()
expect(parsedResp).toEqual('Green Hello World!')
}
})
})
ReferenceError: clearImmediate is not definedbinding<R2>.failAllWrites({ prefix: '/test' })
binding<R2>.failAllReads({ prefix: '/test2' })putbucketwrangler dev --localvitestvitestworker.fetchworker.fetchworker.queuevitest.config.tsenvironmentOptionsexport async function increment(namespace, key) {
// method
}
export default {
async fetch(request, env, ctx) {
// handler which uses increment
},
}; let mf = new miniflare.Miniflare({
wranglerConfigPath: true,
upstream: testingDetails.url,
modules: true,
cache: false,
kvNamespaces: ["CONFIG"]
});scriptPathSome functionality, such as asynchronous I/O (fetch, Cache API, KV).....input instanceof RequestpackagePath: truemoduledescribe('Cart durable object', () => {
let context: GraphqlContext
let config: AppConfig
let cart: Durable.Object
beforeAll(async () => {
context = createTestContext()
config = context.config
const id = context.bindings.Cart.newUniqueId()
cart = context.bindings.Cart.get(id)
})
test('add item', async () => {
const url = createCartDurableObjectUrl({ path: 'add', config })
const resp = await cart.fetch(url, {
method: 'POST',
body: JSON.stringify({
itemId: 'World of Warcraft: The Burning Crusade',
}),
})
const items: CartItem[] = await resp.json()
expect(items).toEqual([
{
id: 'World of Warcraft: The Burning Crusade',
name: 'World of Warcraft: The Burning Crusade',
price: {
amount: 1,
currency: Currency.Gbp,
},
quantity: 1,
},
])
})
})describe('Cart durable object', () => {
let context: GraphqlContext
let cart: Cart
beforeAll(async () => {
context = createTestContext()
const id = context.bindings.Cart.newUniqueId()
const state = await getMiniflareDurableObjectState(id as any)
cart = new Cart(state, context.bindings)
})
test('add item', async () => {
const url = createCartDurableObjectUrl({ path: 'add' })
const req = new Request(url, {
method: 'POST',
body: JSON.stringify({
itemId: 'World of Warcraft: The Burning Crusade',
quantity: 1,
}),
})
const resp = await cart.fetch(req)
const items: CartItem[] = await resp.json()
expect(items).toEqual([
{
id: 'World of Warcraft: The Burning Crusade',
name: 'World of Warcraft: The Burning Crusade',
price: {
amount: 1,
currency: Currency.Gbp,
},
quantity: 1,
},
])
})
})const myBlob = await response.blob();
await env.BUCKET.put(blobId, myBlob); // must use myBlob.stream()