Skip to content

Commit

Permalink
fix: keep install npm packages before starting server
Browse files Browse the repository at this point in the history
  • Loading branch information
Skn0tt committed Dec 6, 2023
1 parent adc9def commit 78cfb32
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion tests/integration/commands/dev/edge-functions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const setupInternalEdgeFunctions = async ({ fixture }: FixtureTestContext) => {
describe.skipIf(isWindows)('edge functions', () => {
setupFixtureTests(
'dev-server-with-edge-functions',
{ devServer: true, mockApi: { routes }, setup: setupInternalEdgeFunctions },
{ devServer: true, mockApi: { routes }, setupDev: setupInternalEdgeFunctions },
() => {
test<FixtureTestContext>('should run edge functions in correct order', async ({ devServer }) => {
const response = await got(`http://localhost:${devServer.port}/ordertest`, {
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/utils/dev-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const getExecaOptions = ({ cwd, env }) => {
}
}

interface DevServer {
export interface DevServer {
url: string
host: string
port: number
Expand Down
16 changes: 11 additions & 5 deletions tests/integration/utils/fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { temporaryDirectory } from 'tempy'
import { afterAll, afterEach, beforeAll, beforeEach, describe } from 'vitest'

import { callCli } from './call-cli.js'
import { startDevServer } from './dev-server.ts'
import { DevServer, startDevServer } from './dev-server.ts'
import { MockApi, Route, getCLIOptions, startMockApi } from './mock-api-vitest.js'
import { SiteBuilder } from './site-builder.ts'

Expand All @@ -20,7 +20,7 @@ interface MockApiOptions {

export interface FixtureTestContext {
fixture: Fixture
devServer?: any
devServer?: DevServer
mockApi?: MockApi
}

Expand All @@ -33,6 +33,10 @@ export interface FixtureOptions {
* Executed after fixture setup, but before tests run
*/
setup?: LifecycleHook
/**
* Executed after fixture setup, after dev server was started, but before tests run
*/
setupDev?: LifecycleHook
/**
* Executed before fixture is cleaned up
*/
Expand Down Expand Up @@ -136,14 +140,16 @@ export async function setupFixtureTests(
}

describe(`fixture: ${fixturePath}`, async () => {
let devServer: any
let devServer: DevServer
let mockApi: MockApi | undefined
let fixture: Fixture

beforeAll(async () => {
if (options.mockApi) mockApi = await startMockApi(options.mockApi)
fixture = await Fixture.create(fixturePath, { apiUrl: mockApi?.apiUrl })

await options.setup?.({ fixture, mockApi })

if (options.devServer) {
devServer = await startDevServer({
serve: typeof options.devServer === 'object' && options.devServer.serve,
Expand All @@ -156,9 +162,9 @@ export async function setupFixtureTests(
NETLIFY_AUTH_TOKEN: 'fake-token',
},
})
}

await options.setup?.({ fixture, mockApi })
await options.setupDev?.({ fixture, mockApi, devServer })
}
}, HOOK_TIMEOUT)

beforeEach<FixtureTestContext>((context) => {
Expand Down

0 comments on commit 78cfb32

Please sign in to comment.