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
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)
socat TCP-LISTEN:4873,fork,reuseaddr TCP4:jsr:80 &
socat_pid=$!
@ -54,7 +54,7 @@ case "$method" in
fi
export JSR_URL=http://localhost:4873
if [ -z "$@" ]; then
if [ $# -eq 0 ]; then
deno test -A tests/**/*.ts
else
deno test -A $@

View file

@ -4,6 +4,7 @@
"@mtcute/wasm": "jsr:@mtcute/wasm@*",
"@mtcute/tl": "jsr:@mtcute/tl@*",
"@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 { setPlatform } from '@mtcute/core/platform.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) => {
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')
}
setPlatform(new WebPlatform())
setPlatform(new DenoPlatform())
return {
apiId: parseInt(Deno.env.get('API_ID')!),
@ -18,8 +18,8 @@ export const getApiParams = (storage?: string) => {
testMode: true,
storage: new MemoryStorage(),
logLevel: LogManager.VERBOSE,
transport: () => new WebSocketTransport(),
crypto: new WebCryptoProvider(),
transport: () => new TcpTransport(),
crypto: new DenoCryptoProvider(),
}
}

View file

@ -9,6 +9,9 @@ import {
} from '@mtcute/test'
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')
describe('SqliteStorage', () => {

View file

@ -134,7 +134,8 @@ if (import.meta.env.TEST_ENV === 'node') {
it('should propagate errors', async () => {
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)
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'))
expect(spyEmit).toHaveBeenCalledWith('error', new Error('test error'))
expect(spyEmit).toHaveBeenCalledWith(new Error('test error'))
})
})
} else {