Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix Typo setImmediate -> setImmediatePromise #127

Closed
wants to merge 1 commit into from

Conversation

worenga
Copy link
Contributor

@worenga worenga commented Dec 16, 2021

No description provided.

@mrbbot
Copy link
Contributor

mrbbot commented Dec 16, 2021

Hey! 👋 This is intentional. setImmediate takes a callback argument whereas setImmediatePromise doesn't. Since we don't want to await this, it makes sense to use the regular callback version. 👍

@mrbbot mrbbot closed this Dec 16, 2021
@worenga
Copy link
Contributor Author

worenga commented Dec 16, 2021

@mrbbot

in that file we encounter
import { setImmediate as setImmediatePromise } from "timers/promises";

i have jest test that tests a durable object and looks like this:

import { MyDurableObject } from './MyDurableObject';
import { MemoryStorage } from '@miniflare/storage-memory';
import { DurableObjectStorage, DurableObjectState, DurableObjectId } from '@miniflare/durable-objects';

let storage = new DurableObjectStorage(new MemoryStorage());
let obj: MyDurableObject;

const createObj = () => {
    return new DurableObject(new DurableObjectState(new DurableObjectId('test', 'test'), storage), {});
};

beforeEach(() => {
    storage = new DurableObjectStorage(new MemoryStorage());
    obj = createObj();
});

it(`works`, async () => {
    const consume1 = await obj.fetch(

....
        }),
...
    );

When i run this i get

 FAIL  src/durable_objects/MyDurableObject.test.ts
  ✕ works (7 ms)

  ● works

    ReferenceError: setImmediate is not defined

      36 |         switch (url.pathname) {
      37 |             case '/consume': {
    > 38 |                 return await this.state.blockConcurrencyWhile(async () => {
         |                        ^

      at InputGate.runWithClosed (node_modules/@miniflare/shared/src/sync/gate.ts:106:7)
      at MyDurableObject.fetch (src/durable_objects/MyDurableObject.ts:38:24)
      at Object.<anonymous> (src/durable_objects/MyTest.test.ts:18:22)

@mrbbot
Copy link
Contributor

mrbbot commented Dec 16, 2021

Hmmm 😕 What Jest environment are you using: node or miniflare?

@worenga
Copy link
Contributor Author

worenga commented Dec 16, 2021

@mrbbot does that matter? (miniflare)
setImmediate is not even defined in that file?

@mrbbot
Copy link
Contributor

mrbbot commented Dec 16, 2021

does that matter? (miniflare)

Yep, miniflare runs your tests in a Workers-like environment. Workers doesn't implement setImmediate so it's not included in the test sandbox.

setImmediate is not even defined in that file?

setImmediate is included in the Node.js global scope automatically.

@mrbbot
Copy link
Contributor

mrbbot commented Dec 16, 2021

I have been thinking about making the miniflare environment more like a hybrid Workers/Node.js though, so you could both run Workers code, and import Node packages for testing.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants