mirror of
https://github.com/tauri-apps/plugins-workspace.git
synced 2026-09-24 21:40:48 +02:00
tests(e2e): improve coverage
This commit is contained in:
@@ -4,10 +4,12 @@
|
||||
|
||||
import { browser } from '@wdio/globals'
|
||||
import type * as TauriApi from '@tauri-apps/api'
|
||||
import type * as Autostart from '@tauri-apps/plugin-autostart'
|
||||
import type * as BarcodeScanner from '@tauri-apps/plugin-barcode-scanner'
|
||||
import type * as Biometric from '@tauri-apps/plugin-biometric'
|
||||
import type * as Cli from '@tauri-apps/plugin-cli'
|
||||
import type * as ClipboardManager from '@tauri-apps/plugin-clipboard-manager'
|
||||
import type * as DeepLink from '@tauri-apps/plugin-deep-link'
|
||||
import type * as Dialog from '@tauri-apps/plugin-dialog'
|
||||
import type * as Fs from '@tauri-apps/plugin-fs'
|
||||
import type * as Geolocation from '@tauri-apps/plugin-geolocation'
|
||||
@@ -19,20 +21,26 @@ import type * as Nfc from '@tauri-apps/plugin-nfc'
|
||||
import type * as Notification from '@tauri-apps/plugin-notification'
|
||||
import type * as Opener from '@tauri-apps/plugin-opener'
|
||||
import type * as Os from '@tauri-apps/plugin-os'
|
||||
import type * as Positioner from '@tauri-apps/plugin-positioner'
|
||||
import type * as Process from '@tauri-apps/plugin-process'
|
||||
import type * as Shell from '@tauri-apps/plugin-shell'
|
||||
import type * as Sql from '@tauri-apps/plugin-sql'
|
||||
import type * as Store from '@tauri-apps/plugin-store'
|
||||
import type * as Stronghold from '@tauri-apps/plugin-stronghold'
|
||||
import type * as Updater from '@tauri-apps/plugin-updater'
|
||||
import type * as Upload from '@tauri-apps/plugin-upload'
|
||||
import type * as WebSocket from '@tauri-apps/plugin-websocket'
|
||||
import type * as WindowState from '@tauri-apps/plugin-window-state'
|
||||
|
||||
/**
|
||||
* The plugin APIs the example registers on every platform, keyed by the name
|
||||
* each plugin's `api-iife.js` defines on `window.__TAURI__` (the package name
|
||||
* without the `@tauri-apps/plugin-` prefix, camel-cased).
|
||||
* without the `@tauri-apps/plugin-` prefix, camel-cased). `sql` and `websocket`
|
||||
* only have a default export, so their global is that class itself.
|
||||
*/
|
||||
export interface CommonPluginApi {
|
||||
clipboardManager: typeof ClipboardManager
|
||||
deepLink: typeof DeepLink
|
||||
dialog: typeof Dialog
|
||||
fs: typeof Fs
|
||||
http: typeof Http
|
||||
@@ -42,14 +50,19 @@ export interface CommonPluginApi {
|
||||
os: typeof Os
|
||||
process: typeof Process
|
||||
shell: typeof Shell
|
||||
sql: typeof Sql.default
|
||||
store: typeof Store
|
||||
stronghold: typeof Stronghold
|
||||
upload: typeof Upload
|
||||
websocket: typeof WebSocket.default
|
||||
}
|
||||
|
||||
/** The plugin APIs the example only registers on desktop (`#[cfg(desktop)]`). */
|
||||
export interface DesktopPluginApi {
|
||||
autostart: typeof Autostart
|
||||
cli: typeof Cli
|
||||
globalShortcut: typeof GlobalShortcut
|
||||
positioner: typeof Positioner
|
||||
updater: typeof Updater
|
||||
windowState: typeof WindowState
|
||||
}
|
||||
@@ -231,8 +244,9 @@ const skippedModules = (process.env.E2E_SKIP ?? '')
|
||||
|
||||
export interface DescribePluginOptions {
|
||||
/**
|
||||
* The example only registers the plugin on desktop (`cli`, `global-shortcut`,
|
||||
* `updater`, `window-state`), so the whole suite is skipped on mobile.
|
||||
* The example only registers the plugin on desktop (`autostart`, `cli`,
|
||||
* `global-shortcut`, `positioner`, `updater`, `window-state`), so the whole
|
||||
* suite is skipped on mobile.
|
||||
*/
|
||||
desktopOnly?: boolean
|
||||
/**
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import http from 'node:http'
|
||||
import { WebSocketServer } from 'ws'
|
||||
|
||||
/**
|
||||
* Where the fixture server listens. The port is fixed because the updater
|
||||
@@ -23,6 +24,13 @@ export const UPDATER_FIXTURE_OLDER_VERSION = '1.0.0'
|
||||
export const DOWNLOAD_FIXTURE_BODY =
|
||||
'hello from the plugins e2e fixture server\n'.repeat(64)
|
||||
|
||||
/** WebSocket endpoint of the fixture server (the `ws://` twin of {@link FIXTURE_SERVER_URL}). */
|
||||
export const WEBSOCKET_FIXTURE_URL = `ws://127.0.0.1:${FIXTURE_SERVER_PORT}/ws`
|
||||
/** Text message that makes the `/ws` endpoint close the connection with {@link WEBSOCKET_CLOSE_CODE}. */
|
||||
export const WEBSOCKET_CLOSE_REQUEST = 'close-me'
|
||||
export const WEBSOCKET_CLOSE_CODE = 4000
|
||||
export const WEBSOCKET_CLOSE_REASON = 'closed by the fixture server'
|
||||
|
||||
export interface FixtureServer {
|
||||
close(): void
|
||||
}
|
||||
@@ -38,6 +46,10 @@ export interface FixtureServer {
|
||||
* - `GET /download` — {@link DOWNLOAD_FIXTURE_BODY} with a `Content-Length`.
|
||||
* - `* /echo` — a JSON description of the request (`method`, `url`, `headers`
|
||||
* and the utf-8 `body`).
|
||||
* - `ws /ws` — a WebSocket echo endpoint: text and binary messages are sent
|
||||
* back as-is, and {@link WEBSOCKET_CLOSE_REQUEST} makes the server close the
|
||||
* connection with {@link WEBSOCKET_CLOSE_CODE}. On `/ws/headers` the server
|
||||
* first sends the upgrade request's headers as a JSON text message.
|
||||
*/
|
||||
export function startFixtureServer(): Promise<FixtureServer> {
|
||||
const server = http.createServer((req, res) => {
|
||||
@@ -91,12 +103,39 @@ export function startFixtureServer(): Promise<FixtureServer> {
|
||||
})
|
||||
})
|
||||
|
||||
const wss = new WebSocketServer({ noServer: true })
|
||||
server.on('upgrade', (req, socket, head) => {
|
||||
const { pathname } = new URL(req.url ?? '/', FIXTURE_SERVER_URL)
|
||||
if (pathname !== '/ws' && pathname !== '/ws/headers') {
|
||||
socket.destroy()
|
||||
return
|
||||
}
|
||||
wss.handleUpgrade(req, socket, head, (ws) => {
|
||||
if (pathname === '/ws/headers') {
|
||||
ws.send(JSON.stringify(req.headers))
|
||||
}
|
||||
ws.on('message', (data, isBinary) => {
|
||||
if (
|
||||
!isBinary
|
||||
&& Buffer.isBuffer(data)
|
||||
&& data.toString('utf8') === WEBSOCKET_CLOSE_REQUEST
|
||||
) {
|
||||
ws.close(WEBSOCKET_CLOSE_CODE, WEBSOCKET_CLOSE_REASON)
|
||||
} else {
|
||||
ws.send(data, { binary: isBinary })
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
server.once('error', reject)
|
||||
server.listen(FIXTURE_SERVER_PORT, '127.0.0.1', () => {
|
||||
server.off('error', reject)
|
||||
resolve({
|
||||
close: () => {
|
||||
for (const client of wss.clients) client.terminate()
|
||||
wss.close()
|
||||
server.closeAllConnections()
|
||||
server.close()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user