Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ceifa committed Jan 18, 2025
1 parent 312179c commit 651eab9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion test/engine.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { LuaLibraries, LuaReturn, LuaThread, LuaType, decorate, decorateProxy, d
import { expect } from 'chai'
import { getEngine, getFactory } from './utils.js'
import { setTimeout } from 'node:timers/promises'
import { mock } from 'node:test';
import { mock } from 'node:test'

class TestClass {
static hello() {
Expand Down
26 changes: 13 additions & 13 deletions test/promises.test.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { expect } from 'chai'
import { getEngine, tick } from './utils.js'
import jestMock from 'jest-mock'
import { mock } from 'node:test'

describe('Promises', () => {
it('use promise next should succeed', async () => {
const engine = await getEngine()
const check = jestMock.fn()
const check = mock.fn()
engine.global.set('check', check)
const promise = new Promise((resolve) => setTimeout(() => resolve(60), 5))
engine.global.set('promise', promise)
Expand All @@ -17,12 +17,12 @@ describe('Promises', () => {
expect(check.mock.calls.length).to.be.equal(0)
await promise
await res
expect(check.mock.calls[0]).to.be.eql([60])
expect(check.mock.calls[0].arguments).to.be.eql([60])
})

it('chain promises with next should succeed', async () => {
const engine = await getEngine()
const check = jestMock.fn()
const check = mock.fn()
engine.global.set('check', check)
const promise = new Promise((resolve) => resolve(60))
engine.global.set('promise', promise)
Expand All @@ -37,14 +37,14 @@ describe('Promises', () => {
await tick()
await res

expect(check.mock.calls[0]).to.be.eql([120])
expect(check.mock.calls[0].arguments).to.be.eql([120])
expect(check.mock.calls.length).to.be.equal(2)
})

it('call an async function should succeed', async () => {
const engine = await getEngine()
engine.global.set('asyncFunction', async () => Promise.resolve(60))
const check = jestMock.fn()
const check = mock.fn()
engine.global.set('check', check)

const res = engine.doString(`
Expand All @@ -53,7 +53,7 @@ describe('Promises', () => {

await tick()
await res
expect(check.mock.calls[0]).to.be.eql([60])
expect(check.mock.calls[0].arguments).to.be.eql([60])
})

it('return an async function should succeed', async () => {
Expand Down Expand Up @@ -82,7 +82,7 @@ describe('Promises', () => {

it('await an promise inside coroutine should succeed', async () => {
const engine = await getEngine()
const check = jestMock.fn()
const check = mock.fn()
engine.global.set('check', check)
const promise = new Promise((resolve) => setTimeout(() => resolve(60), 5))
engine.global.set('promise', promise)
Expand All @@ -104,12 +104,12 @@ describe('Promises', () => {
expect(check.mock.calls.length).to.be.equal(0)
await promise
await res
expect(check.mock.calls[0]).to.be.eql([60])
expect(check.mock.calls[0].arguments).to.be.eql([60])
})

it('awaited coroutines should ignore resume until it resolves the promise', async () => {
const engine = await getEngine()
const check = jestMock.fn()
const check = mock.fn()
engine.global.set('check', check)
const promise = new Promise((resolve) => setTimeout(() => resolve(60), 5))
engine.global.set('promise', promise)
Expand All @@ -129,7 +129,7 @@ describe('Promises', () => {
expect(check.mock.calls.length).to.be.equal(0)
await promise
await res
expect(check.mock.calls[0]).to.be.eql([60])
expect(check.mock.calls[0].arguments).to.be.eql([60])
})

it('await a thread run with async calls should succeed', async () => {
Expand Down Expand Up @@ -193,8 +193,8 @@ describe('Promises', () => {

it('catch a promise rejection should succeed', async () => {
const engine = await getEngine()
const fulfilled = jestMock.fn()
const rejected = jestMock.fn()
const fulfilled = mock.fn()
const rejected = mock.fn()
engine.global.set('handlers', { fulfilled, rejected })
engine.global.set('throw', new Promise((_, reject) => reject(new Error('expected test error'))))

Expand Down

0 comments on commit 651eab9

Please sign in to comment.