Rewrite @wdio/static-server to ESM
This commit is contained in:
parent
915d6a942c
commit
3014c039de
7 changed files with 38 additions and 26 deletions
|
|
@ -1,6 +1,8 @@
|
|||
const expressMock = jest.fn().mockReturnValue({
|
||||
use: jest.fn(),
|
||||
listen: jest.fn().mockImplementation(function (this: unknown, port, cb) {
|
||||
import { vi } from 'vitest'
|
||||
|
||||
const expressMock = vi.fn().mockReturnValue({
|
||||
use: vi.fn(),
|
||||
listen: vi.fn().mockImplementation(function (this: unknown, port, cb) {
|
||||
if (this === undefined) {
|
||||
return cb(
|
||||
new Error('This value missing when invoking server.listen()')
|
||||
|
|
@ -11,6 +13,6 @@ const expressMock = jest.fn().mockReturnValue({
|
|||
})
|
||||
}) as any
|
||||
|
||||
expressMock.static = jest.fn()
|
||||
expressMock.static = vi.fn()
|
||||
|
||||
export default expressMock
|
||||
|
|
@ -5,7 +5,6 @@
|
|||
"author": "Christian Bromann <mail@bromann.dev>",
|
||||
"homepage": "https://github.com/webdriverio/webdriverio/tree/main/packages/wdio-static-server-service",
|
||||
"license": "MIT",
|
||||
"main": "./build/index",
|
||||
"engines": {
|
||||
"node": "^16.13 || >=18"
|
||||
},
|
||||
|
|
@ -26,6 +25,20 @@
|
|||
"bugs": {
|
||||
"url": "https://github.com/webdriverio/webdriverio/issues"
|
||||
},
|
||||
"main": "./build/index.cjs.js",
|
||||
"type": "module",
|
||||
"module": "./build/index.js",
|
||||
"exports": {
|
||||
".": [
|
||||
{
|
||||
"import": "./build/index.js",
|
||||
"require": "./build/index.cjs.js"
|
||||
},
|
||||
"./build/index.cjs.js"
|
||||
]
|
||||
},
|
||||
"types": "./build/index.d.ts",
|
||||
"typeScriptVersion": "3.8.3",
|
||||
"dependencies": {
|
||||
"@types/express": "^4.17.8",
|
||||
"@types/fs-extra": "^9.0.1",
|
||||
|
|
@ -38,6 +51,5 @@
|
|||
},
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"types": "./build/index.d.ts"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
/* istanbul ignore file */
|
||||
|
||||
import StaticServerLauncher from './launcher'
|
||||
import { StaticServerOptions } from './types'
|
||||
import StaticServerLauncher from './launcher.js'
|
||||
import type { StaticServerOptions } from './types'
|
||||
|
||||
export default class StaticServerService { }
|
||||
export const launcher = StaticServerLauncher
|
||||
export * from './types'
|
||||
export * from './types.js'
|
||||
|
||||
declare global {
|
||||
namespace WebdriverIO {
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
import { join, resolve } from 'path'
|
||||
import { promisify } from 'util'
|
||||
import { join, resolve } from 'node:path'
|
||||
import { promisify } from 'node:util'
|
||||
import express from 'express'
|
||||
import fs from 'fs-extra'
|
||||
import morgan from 'morgan'
|
||||
import logger from '@wdio/logger'
|
||||
import type { Services } from '@wdio/types'
|
||||
|
||||
import { FolderOption, MiddleWareOption } from './types'
|
||||
import type { FolderOption, MiddleWareOption } from './types'
|
||||
|
||||
const log = logger('@wdio/static-server-service')
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +0,0 @@
|
|||
{
|
||||
"env": {
|
||||
"jest": true
|
||||
}
|
||||
}
|
||||
|
|
@ -1,10 +1,14 @@
|
|||
import path from 'node:path'
|
||||
import os from 'node:os'
|
||||
import express from 'express'
|
||||
import fs from 'fs-extra'
|
||||
import os from 'os'
|
||||
import { test, expect, vi, afterEach } from 'vitest'
|
||||
|
||||
import StaticServerLauncher from '../src/launcher'
|
||||
|
||||
jest.mock('fs-extra')
|
||||
vi.mock('fs-extra')
|
||||
vi.mock('express')
|
||||
vi.mock('@wdio/logger', () => import(path.join(process.cwd(), '__mocks__', '@wdio/logger')))
|
||||
|
||||
test('should not start server when no mount folder is defined', async () => {
|
||||
const service = new StaticServerLauncher({})
|
||||
|
|
@ -16,8 +20,7 @@ test('should be able to start server', async () => {
|
|||
const service = new StaticServerLauncher({
|
||||
folders: { mount: 'foo', path: 'bar' }
|
||||
})
|
||||
await service.onPrepare({});
|
||||
(service['_server']!.listen as jest.Mock).mock.calls[0][1]
|
||||
await service.onPrepare({})
|
||||
expect(express).toBeCalledTimes(1)
|
||||
expect(service['_server']!.use).toBeCalledWith('foo', undefined)
|
||||
expect(express.static).toBeCalledWith('bar')
|
||||
|
|
@ -30,8 +33,7 @@ test('should be able to mount multiple folder', async () => {
|
|||
{ mount: 'foo2', path: 'bar2' }
|
||||
]
|
||||
})
|
||||
await service.onPrepare({});
|
||||
(service['_server']!.listen as jest.Mock).mock.calls[0][1]
|
||||
await service.onPrepare({})
|
||||
expect(express).toBeCalledTimes(1)
|
||||
expect(service['_server']!.use).toBeCalledWith('foo', undefined)
|
||||
expect(express.static).toBeCalledWith('bar')
|
||||
|
|
@ -64,5 +66,5 @@ test('should register middlewares', async () => {
|
|||
})
|
||||
|
||||
afterEach(() => {
|
||||
(express as unknown as jest.Mock).mockClear()
|
||||
vi.mocked(express).mockClear()
|
||||
})
|
||||
|
|
|
|||
|
|
@ -24,7 +24,8 @@ export default defineConfig({
|
|||
'packages/wdio-sauce-service/**/*.test.ts',
|
||||
'packages/wdio-selenium-standalone-service/**/*.test.ts',
|
||||
'packages/wdio-shared-store-service/**/*.test.ts',
|
||||
'packages/wdio-spec-reporter/**/*.test.ts'
|
||||
'packages/wdio-spec-reporter/**/*.test.ts',
|
||||
'packages/wdio-static-server-service/**/*.test.ts'
|
||||
],
|
||||
coverage: {
|
||||
enabled: false,
|
||||
|
|
|
|||
Loading…
Reference in a new issue