rescript-zora icon indicating copy to clipboard operation
rescript-zora copied to clipboard

Shouldn't test return a promise?

Open tsnobip opened this issue 3 years ago • 1 comments

Right now test is modeled like this:

@send external test: (t, testTitle, zoraTest) => unit = "test"

Shouldn't it be modeled like this instead:

@send external test: (t, testTitle, zoraTest) => Js.Promise.t<unit> = "test"

Otherwise you can write multiple tests in a Zora block, finish with a done() and get an error:

tried to collect an assertion after it has run to its completion.
You might have forgotten to wait for an asynchronous task to complete

What do you think?

tsnobip avatar Apr 25 '22 13:04 tsnobip

Technically yes, in the sense that Zora test() returns a promise so it should be modelled the same way. I left it off because I didn't want to have to add a bunch of ->Promise.ignore calls cluttering up the Rescript syntax and all the Zora documentation silently ignores the return of test().

That said, I haven't seen your problem before. Are you doing the same thing as parallel.test.res? Does that file work for you?

I'd add it if it seems necessary, but the only reason I can see would be that you collect the promises inside your file and call Promise.all to wait for them all. But I think (I haven't actually spent much time in the Zora codebase) that the Zora test harness is doing this on your behalf so you shouldn't have to. šŸ¤”

dusty-phillips avatar Apr 27 '22 18:04 dusty-phillips

@tsnobip Did Dusty's suggestion work for you?

Are you doing the same thing as parallel.test.res? Does that file work for you?

brettcannon avatar May 09 '24 20:05 brettcannon

@tsnobip Did Dusty's suggestion work for you?

Are you doing the same thing as parallel.test.res? Does that file work for you?

to be honest I don't remember anymore, I left the company where I encountered this issue since then and switched to vitest for my new projects 😬

tsnobip avatar May 10 '24 08:05 tsnobip

The best solution here is to migrate everything to async/await syntax. I think that would clarify the docs.

dusty-phillips avatar May 10 '24 12:05 dusty-phillips

The best solution here is to migrate everything to async/await syntax.

@dusty-phillips The only explicit promise I can see is:

https://github.com/dusty-phillips/rescript-zora/blob/main/src%2FZora.res#L2

So are you saying to move that line and the tests?

brettcannon avatar May 15 '24 02:05 brettcannon

Ah, it appears I already migrated it to async/await. šŸ˜… I’m pretty sure this is a legacy issue from when I was depending on an external promise library. I went to a lot of trouble to make tests parallel by default, but I think most of that trouble was abstracted away with async/await syntax. Will close for now unless it comes up again.

dusty-phillips avatar May 15 '24 10:05 dusty-phillips

I'm also pretty sure it now works out of the box.

tsnobip avatar May 15 '24 13:05 tsnobip