Skip to content
Merged
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
5 changes: 5 additions & 0 deletions .changeset/prompt-for-localhost-certificate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/app': patch
---

Prompt to generate the localhost certificate again instead of aborting on `app dev --use-localhost`
62 changes: 47 additions & 15 deletions packages/app/src/cli/commands/app/dev.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,27 @@ describe('app dev command', () => {
vi.mocked(addPublicMetadata).mockReset()
})

function mockAppAndStore(directory: string) {
const appContextResult = {
app: testAppLinked({directory}),
remoteApp: testOrganizationApp(),
organization: testOrganization(),
project: testProject(),
activeConfig: {} as never,
specifications: [],
developerPlatformClient: testDeveloperPlatformClient(),
} as Awaited<ReturnType<typeof linkedAppContext>>
const store = testOrganizationStore({shopDomain: 'dev-store.myshopify.com'})

vi.mocked(linkedAppContext).mockResolvedValue(appContextResult)
vi.mocked(storeContext).mockResolvedValue(store)

return {store}
}

test('does not require --use-localhost when --install-mkcert is not passed', async () => {
await inTemporaryDirectory(async (tmp) => {
const app = testAppLinked({directory: tmp})
const appContextResult = {
app,
remoteApp: testOrganizationApp(),
organization: testOrganization(),
project: testProject(),
activeConfig: {} as never,
specifications: [],
developerPlatformClient: testDeveloperPlatformClient(),
} as Awaited<ReturnType<typeof linkedAppContext>>
const store = testOrganizationStore({shopDomain: 'dev-store.myshopify.com'})

vi.mocked(linkedAppContext).mockResolvedValue(appContextResult)
vi.mocked(storeContext).mockResolvedValue(store)
const {store} = mockAppAndStore(tmp)
vi.mocked(getTunnelMode).mockResolvedValue({mode: 'auto'})

await Dev.run(['--path', tmp, '--store', store.shopDomain], import.meta.url)
Expand All @@ -58,7 +63,34 @@ describe('app dev command', () => {
tunnelUrl: undefined,
localhostPort: undefined,
})
expect(dev).toHaveBeenCalledWith(expect.objectContaining({installMkcert: false, tunnel: {mode: 'auto'}}))
expect(dev).toHaveBeenCalledWith(expect.objectContaining({installMkcert: undefined, tunnel: {mode: 'auto'}}))
})
})

// `generateCertificate()` only shows the "generate it now?" prompt when `installMkcert` is nullish, so an
// omitted --install-mkcert must stay undefined rather than being collapsed into an explicit `false`.
test('leaves installMkcert undefined with --use-localhost so the certificate prompt is reached', async () => {
await inTemporaryDirectory(async (tmp) => {
const {store} = mockAppAndStore(tmp)
vi.mocked(getTunnelMode).mockResolvedValue({mode: 'use-localhost', requestedPort: 3458, actualPort: 3458})

await Dev.run(['--path', tmp, '--store', store.shopDomain, '--use-localhost'], import.meta.url)

expect(dev).toHaveBeenCalledWith(expect.objectContaining({installMkcert: undefined}))
})
})

test('sets installMkcert to true when --install-mkcert is passed', async () => {
await inTemporaryDirectory(async (tmp) => {
const {store} = mockAppAndStore(tmp)
vi.mocked(getTunnelMode).mockResolvedValue({mode: 'use-localhost', requestedPort: 3458, actualPort: 3458})

await Dev.run(
['--path', tmp, '--store', store.shopDomain, '--use-localhost', '--install-mkcert'],
import.meta.url,
)

expect(dev).toHaveBeenCalledWith(expect.objectContaining({installMkcert: true}))
})
})

Expand Down
3 changes: 2 additions & 1 deletion packages/app/src/cli/commands/app/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ export default class Dev extends AppLinkedCommand {
notify: flags.notify,
graphiqlPort: flags['graphiql-port'],
graphiqlKey: flags['graphiql-key'],
installMkcert: flags['install-mkcert'] ?? false,
// Must stay undefined when the flag is absent: generateCertificate() only prompts when this is nullish.
installMkcert: flags['install-mkcert'],
tunnel: tunnelMode,
}

Expand Down
Loading