test(e2e-deno): use @mtcute/deno in tests

This commit is contained in:
alina 🌸 2024-04-29 18:10:43 +03:00
parent dc56deb08a
commit ac398e657a
Signed by: teidesu
SSH key fingerprint: SHA256:uNeCpw6aTSU4aIObXLvHfLkDa82HWH9EiOj9AXOIRpI
5 changed files with 14 additions and 9 deletions

View file

@ -45,7 +45,7 @@ case "$method" in
source .env source .env
fi fi
if [ -n "$DOCKER" ]; then if [ ! -z ${DOCKER+x} ]; then
# running behind a socat proxy seems to fix some of the docker networking issues (thx kamillaova) # running behind a socat proxy seems to fix some of the docker networking issues (thx kamillaova)
socat TCP-LISTEN:4873,fork,reuseaddr TCP4:jsr:80 & socat TCP-LISTEN:4873,fork,reuseaddr TCP4:jsr:80 &
socat_pid=$! socat_pid=$!
@ -54,7 +54,7 @@ case "$method" in
fi fi
export JSR_URL=http://localhost:4873 export JSR_URL=http://localhost:4873
if [ -z "$@" ]; then if [ $# -eq 0 ]; then
deno test -A tests/**/*.ts deno test -A tests/**/*.ts
else else
deno test -A $@ deno test -A $@

View file

@ -4,6 +4,7 @@
"@mtcute/wasm": "jsr:@mtcute/wasm@*", "@mtcute/wasm": "jsr:@mtcute/wasm@*",
"@mtcute/tl": "jsr:@mtcute/tl@*", "@mtcute/tl": "jsr:@mtcute/tl@*",
"@mtcute/tl-runtime": "jsr:@mtcute/tl-runtime@*", "@mtcute/tl-runtime": "jsr:@mtcute/tl-runtime@*",
"@mtcute/core": "jsr:@mtcute/core@*" "@mtcute/core": "jsr:@mtcute/core@*",
"@mtcute/deno": "jsr:@mtcute/deno@*"
} }
} }

View file

@ -1,7 +1,7 @@
import { MaybePromise, MemoryStorage } from '@mtcute/core' import { MaybePromise, MemoryStorage } from '@mtcute/core'
import { setPlatform } from '@mtcute/core/platform.js' import { setPlatform } from '@mtcute/core/platform.js'
import { LogManager, sleep } from '@mtcute/core/utils.js' import { LogManager, sleep } from '@mtcute/core/utils.js'
import { WebCryptoProvider, WebPlatform, WebSocketTransport } from '@mtcute/web' import { DenoCryptoProvider, DenoPlatform, TcpTransport } from '@mtcute/deno'
export const getApiParams = (storage?: string) => { export const getApiParams = (storage?: string) => {
if (storage) throw new Error('unsupported yet') if (storage) throw new Error('unsupported yet')
@ -10,7 +10,7 @@ export const getApiParams = (storage?: string) => {
throw new Error('API_ID and API_HASH env variables must be set') throw new Error('API_ID and API_HASH env variables must be set')
} }
setPlatform(new WebPlatform()) setPlatform(new DenoPlatform())
return { return {
apiId: parseInt(Deno.env.get('API_ID')!), apiId: parseInt(Deno.env.get('API_ID')!),
@ -18,8 +18,8 @@ export const getApiParams = (storage?: string) => {
testMode: true, testMode: true,
storage: new MemoryStorage(), storage: new MemoryStorage(),
logLevel: LogManager.VERBOSE, logLevel: LogManager.VERBOSE,
transport: () => new WebSocketTransport(), transport: () => new TcpTransport(),
crypto: new WebCryptoProvider(), crypto: new DenoCryptoProvider(),
} }
} }

View file

@ -9,6 +9,9 @@ import {
} from '@mtcute/test' } from '@mtcute/test'
if (import.meta.env.TEST_ENV === 'deno') { if (import.meta.env.TEST_ENV === 'deno') {
// load sqlite in advance so test runner doesn't complain about us leaking the library
// (it's not on us, @db/sqlite doesn't provide an api to unload the library)
await import('@db/sqlite')
const { SqliteStorage } = await import('./index.js') const { SqliteStorage } = await import('./index.js')
describe('SqliteStorage', () => { describe('SqliteStorage', () => {

View file

@ -134,7 +134,8 @@ if (import.meta.env.TEST_ENV === 'node') {
it('should propagate errors', async () => { it('should propagate errors', async () => {
const t = await create() const t = await create()
const spyEmit = vi.spyOn(t, 'emit').mockImplementation(() => true) const spyEmit = vi.fn()
t.on('error', spyEmit)
t.connect(defaultProductionDc.main, false) t.connect(defaultProductionDc.main, false)
await vi.waitFor(() => expect(t.state()).toEqual(TransportState.Ready)) await vi.waitFor(() => expect(t.state()).toEqual(TransportState.Ready))
@ -147,7 +148,7 @@ if (import.meta.env.TEST_ENV === 'node') {
] ]
onErrorCall[1](new Error('test error')) onErrorCall[1](new Error('test error'))
expect(spyEmit).toHaveBeenCalledWith('error', new Error('test error')) expect(spyEmit).toHaveBeenCalledWith(new Error('test error'))
}) })
}) })
} else { } else {