test: fixed deno/bun/browser tests
This commit is contained in:
parent
9622d2c0a2
commit
a9ef0198e9
5 changed files with 81 additions and 69 deletions
|
@ -1,6 +1,6 @@
|
||||||
// @ts-expect-error no typings
|
|
||||||
import util from 'node:util'
|
import util from 'node:util'
|
||||||
|
|
||||||
|
// @ts-expect-error no typings
|
||||||
import { describe as _describe, afterAll, afterEach, beforeAll, beforeEach, it } from 'jsr:@std/testing/bdd'
|
import { describe as _describe, afterAll, afterEach, beforeAll, beforeEach, it } from 'jsr:@std/testing/bdd'
|
||||||
// @ts-expect-error no typings
|
// @ts-expect-error no typings
|
||||||
import * as vitestSpy from 'npm:@vitest/spy@1.4.0'
|
import * as vitestSpy from 'npm:@vitest/spy@1.4.0'
|
||||||
|
|
|
@ -23,6 +23,8 @@ export default defineConfig({
|
||||||
// uses timers
|
// uses timers
|
||||||
'core/src/network/config-manager.test.ts',
|
'core/src/network/config-manager.test.ts',
|
||||||
'core/src/network/persistent-connection.test.ts',
|
'core/src/network/persistent-connection.test.ts',
|
||||||
|
// use fixtures
|
||||||
|
'convert/src/tdesktop/tdata.test.ts',
|
||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
formats: ['es'],
|
formats: ['es'],
|
||||||
|
|
|
@ -23,6 +23,8 @@ export default defineConfig({
|
||||||
// https://github.com/denoland/deno/issues/22470
|
// https://github.com/denoland/deno/issues/22470
|
||||||
'wasm/tests/gunzip.test.ts',
|
'wasm/tests/gunzip.test.ts',
|
||||||
'wasm/tests/zlib.test.ts',
|
'wasm/tests/zlib.test.ts',
|
||||||
|
// use fixtures
|
||||||
|
'convert/src/tdesktop/tdata.test.ts',
|
||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
formats: ['es'],
|
formats: ['es'],
|
||||||
|
|
|
@ -1,12 +1,7 @@
|
||||||
import { fileURLToPath } from 'node:url'
|
|
||||||
|
|
||||||
import { describe, expect, it } from 'vitest'
|
import { describe, expect, it } from 'vitest'
|
||||||
import { Long } from '@mtcute/core'
|
import { Long } from '@mtcute/core'
|
||||||
|
|
||||||
import type { INodeFsLike } from '../utils/fs.js'
|
import type { INodeFsLike } from '../utils/fs.js'
|
||||||
import { getDefaultCryptoProvider } from '../utils/crypto.js'
|
|
||||||
|
|
||||||
import { Tdata } from './tdata.js'
|
|
||||||
|
|
||||||
class FakeFs implements INodeFsLike {
|
class FakeFs implements INodeFsLike {
|
||||||
readonly files = new Map<string, Uint8Array>()
|
readonly files = new Map<string, Uint8Array>()
|
||||||
|
@ -31,7 +26,12 @@ class FakeFs implements INodeFsLike {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
describe('tdata', () => {
|
if (import.meta.env.TEST_ENV === 'node') {
|
||||||
|
describe('tdata', async () => {
|
||||||
|
const { getDefaultCryptoProvider } = await import('../utils/crypto.js')
|
||||||
|
const { fileURLToPath } = await import('node:url')
|
||||||
|
const { Tdata } = await import('./tdata.js')
|
||||||
|
|
||||||
it('should read simple tdata', async () => {
|
it('should read simple tdata', async () => {
|
||||||
const tdata = await Tdata.open({
|
const tdata = await Tdata.open({
|
||||||
path: fileURLToPath(new URL('./__fixtures__/simple', import.meta.url)),
|
path: fileURLToPath(new URL('./__fixtures__/simple', import.meta.url)),
|
||||||
|
@ -104,3 +104,6 @@ describe('tdata', () => {
|
||||||
expect(fs.files).toMatchSnapshot()
|
expect(fs.files).toMatchSnapshot()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
} else {
|
||||||
|
describe.skip('tdata', () => {})
|
||||||
|
}
|
||||||
|
|
|
@ -95,15 +95,20 @@ describe('ConfigManager', () => {
|
||||||
cm.onUpdated.add(listener)
|
cm.onUpdated.add(listener)
|
||||||
|
|
||||||
await cm.update()
|
await cm.update()
|
||||||
const call = structuredClone(listener.mock.calls[0][0]) as AsyncResourceContext<tl.RawConfig>
|
const call = listener.mock.calls[0][0] as AsyncResourceContext<tl.RawConfig>
|
||||||
|
const callCopy = structuredClone({
|
||||||
|
current: call.current,
|
||||||
|
currentFetchedAt: call.currentFetchedAt,
|
||||||
|
currentExpiresAt: call.currentExpiresAt,
|
||||||
|
isBackground: call.isBackground,
|
||||||
|
})
|
||||||
|
|
||||||
vi.setSystemTime(300_000)
|
vi.setSystemTime(300_000)
|
||||||
cm.onUpdated.remove(listener)
|
cm.onUpdated.remove(listener)
|
||||||
await cm.update()
|
await cm.update()
|
||||||
|
|
||||||
expect(listener).toHaveBeenCalledOnce()
|
expect(listener).toHaveBeenCalledOnce()
|
||||||
expect(call).toEqual({
|
expect(callCopy).toEqual({
|
||||||
abort: {},
|
|
||||||
current: config,
|
current: config,
|
||||||
currentExpiresAt: 300_000,
|
currentExpiresAt: 300_000,
|
||||||
currentFetchedAt: 0,
|
currentFetchedAt: 0,
|
||||||
|
|
Loading…
Reference in a new issue