Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/cli-kit/src/public/node/context/fqdn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export async function identityFqdn(): Promise<string> {
const productionFqdn = 'accounts.shopify.com'
switch (environment) {
case 'local':
return new DevServer('identity').host()
return new DevServer('identity').host({useMockIfNotRunning: true})
default:
return productionFqdn
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import {createServer} from './dev-server-2024.js'
import {beforeEach, describe, expect, test} from 'vitest'
import {assertCompatibleEnvironment} from './env.js'
import {vi} from 'vitest'

vi.mock('./env.js')

beforeEach(() => {
vi.mocked(assertCompatibleEnvironment).mockImplementation(() => true)
})

describe('createServer', () => {
describe('host', () => {
test('throws when dev server is not running and useMockIfNotRunning is not set', () => {
const server = createServer('test-project')
expect(() => server.host()).toThrow()
})

test('does not throw when useMockIfNotRunning is true', () => {
const server = createServer('test-project')
expect(() => server.host({useMockIfNotRunning: true})).not.toThrow()
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@ export function createServer(projectName: string) {
}
}

function host(projectName: string, options: HostOptions = {}): string {
function host(projectName: string, options: HostOptions = {useMockIfNotRunning: false}): string {
assertCompatibleEnvironment()
;(assertRunningOverride || assertRunning2024)(projectName)

if (!options.useMockIfNotRunning) {
assertRunning2024(projectName)
}

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

Expand Down Expand Up @@ -80,10 +83,3 @@ function resolveBackendHost(name: string): string {
return host
}
}

// Allow overrides for more concise test setup. Meh.
let assertRunningOverride: typeof assertRunning2024 | undefined

export function setAssertRunning(override: typeof assertRunningOverride) {
assertRunningOverride = override
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ export interface DevServer {

export interface HostOptions {
nonstandardHostPrefix?: string
useMockIfNotRunning?: boolean
}