Skip to content
This repository was archived by the owner on Sep 11, 2025. It is now read-only.

Commit 6830163

Browse files
authored
Improve basePath logic (#16)
1 parent 3f80c37 commit 6830163

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/index.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,16 @@ function getIsPortTaken(config: JestProcessManagerOptions) {
133133
})
134134
}
135135

136+
const basePathUrlPostfix = (basePath?: string): string => {
137+
if (basePath) {
138+
if (basePath.includes('/')) {
139+
return basePath
140+
}
141+
return `/${basePath}`
142+
}
143+
return ''
144+
}
145+
136146
export async function setup(providedConfigs: JestProcessManagerOptions | JestProcessManagerOptions[]): Promise<void> {
137147
// Compatible with older versions
138148
const configs = Array.isArray(providedConfigs)
@@ -209,11 +219,13 @@ async function setupJestServer(providedConfig: JestProcessManagerOptions, index:
209219
runServer(config, index)
210220
}
211221

222+
const urlPostfix = basePathUrlPostfix(basePath)
223+
212224
let url = ''
213225
if (protocol === 'tcp' || protocol === 'socket') {
214-
url = `${protocol}:${host}:${port}${basePath ? `/${basePath}` : ''}`
226+
url = `${protocol}:${host}:${port}${urlPostfix}`
215227
} else {
216-
url = `${protocol}://${host}:${port}${basePath ? `/${basePath}` : ''}`
228+
url = `${protocol}://${host}:${port}${urlPostfix}`
217229
}
218230
const opts = {
219231
resources: [url],

0 commit comments

Comments
 (0)