Skip to content

Commit 0b66835

Browse files
add option to bypass running service check if configured
1 parent 591e90e commit 0b66835

File tree

4 files changed

+31
-10
lines changed

4 files changed

+31
-10
lines changed

packages/cli-kit/src/public/node/context/fqdn.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ export async function identityFqdn(): Promise<string> {
115115
const productionFqdn = 'accounts.shopify.com'
116116
switch (environment) {
117117
case 'local':
118-
return new DevServer('identity').host()
118+
return new DevServer('identity').host({useMockIfNotRunning: true})
119119
default:
120120
return productionFqdn
121121
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import {createServer} from './dev-server-2024.js'
2+
import {beforeEach, describe, expect, test} from 'vitest'
3+
import {assertCompatibleEnvironment} from './env.js'
4+
import {vi} from 'vitest'
5+
6+
vi.mock('./env.js')
7+
8+
beforeEach(() => {
9+
vi.mocked(assertCompatibleEnvironment).mockImplementation(() => true)
10+
})
11+
12+
describe('createServer', () => {
13+
describe('host', () => {
14+
test('throws when dev server is not running and useMockIfNotRunning is not set', () => {
15+
const server = createServer('test-project')
16+
expect(() => server.host()).toThrow()
17+
})
18+
19+
test('does not throw when useMockIfNotRunning is true', () => {
20+
const server = createServer('test-project')
21+
expect(() => server.host({useMockIfNotRunning: true})).not.toThrow()
22+
})
23+
})
24+
})

packages/cli-kit/src/public/node/vendor/dev_server/dev-server-2024.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,12 @@ export function createServer(projectName: string) {
1616
}
1717
}
1818

19-
function host(projectName: string, options: HostOptions = {}): string {
19+
function host(projectName: string, options: HostOptions = {useMockIfNotRunning: false}): string {
2020
assertCompatibleEnvironment()
21-
;(assertRunningOverride || assertRunning2024)(projectName)
21+
22+
if (!options.useMockIfNotRunning) {
23+
assertRunning2024(projectName)
24+
}
2225

2326
const prefix = (options.nonstandardHostPrefix || projectName).replace(/_/g, '-')
2427

@@ -80,10 +83,3 @@ function resolveBackendHost(name: string): string {
8083
return host
8184
}
8285
}
83-
84-
// Allow overrides for more concise test setup. Meh.
85-
let assertRunningOverride: typeof assertRunning2024 | undefined
86-
87-
export function setAssertRunning(override: typeof assertRunningOverride) {
88-
assertRunningOverride = override
89-
}

packages/cli-kit/src/public/node/vendor/dev_server/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ export interface DevServer {
1010

1111
export interface HostOptions {
1212
nonstandardHostPrefix?: string
13+
useMockIfNotRunning?: boolean
1314
}

0 commit comments

Comments
 (0)