Skip to content

Commit 4424419

Browse files
committed
validate deployment setup to ensure we are testing what we think we are testing
1 parent e3a806c commit 4424419

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

tests/utils/create-e2e-fixture.ts

+26-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,16 @@ export interface DeployResult {
2424

2525
type PackageManager = 'npm' | 'pnpm' | 'yarn' | 'bun' | 'berry'
2626

27+
const defaultValidateDeployOutput = async (siteAbsDir: string) => {
28+
// by default we expect Frameworks API to be used in the build
29+
const serverHandlerDir = join(siteAbsDir, '.netlify/functions/___netlify-server-handler')
30+
if (!existsSync(serverHandlerDir)) {
31+
throw new Error(`Server handler not found at ${siteAbsDir}`)
32+
}
33+
}
34+
35+
const staticExportValidateDeployOutput = defaultValidateDeployOutput //() => {}
36+
2737
interface E2EConfig {
2838
packageManger?: PackageManager
2939
packagePath?: string
@@ -44,6 +54,10 @@ interface E2EConfig {
4454
* Site ID to deploy to. Defaults to the `NETLIFY_SITE_ID` environment variable or a default site.
4555
*/
4656
siteId?: string
57+
/**
58+
*
59+
*/
60+
validateDeployFiles?: typeof defaultValidateDeployOutput
4761
}
4862

4963
/**
@@ -84,6 +98,14 @@ export const createE2EFixture = async (fixture: string, config: E2EConfig = {})
8498

8599
const result = await deploySite(isolatedFixtureRoot, config)
86100

101+
{
102+
const validateOutput = config.validateDeployFiles ?? defaultValidateDeployOutput
103+
104+
const siteRelDir = config.cwd ?? config.packagePath ?? ''
105+
106+
await validateOutput(join(isolatedFixtureRoot, siteRelDir))
107+
}
108+
87109
console.log(`🌍 Deployed site is live: ${result.url}`)
88110
deployID = result.deployID
89111
logs = result.logs
@@ -307,14 +329,17 @@ async function cleanup(dest: string, deployId?: string): Promise<void> {
307329

308330
export const fixtureFactories = {
309331
simple: () => createE2EFixture('simple'),
310-
outputExport: () => createE2EFixture('output-export'),
332+
outputExport: () =>
333+
createE2EFixture('output-export', { validateDeployFiles: staticExportValidateDeployOutput }),
311334
ouputExportPublishOut: () =>
312335
createE2EFixture('output-export', {
313336
publishDirectory: 'out',
337+
validateDeployFiles: staticExportValidateDeployOutput,
314338
}),
315339
outputExportCustomDist: () =>
316340
createE2EFixture('output-export-custom-dist', {
317341
publishDirectory: 'custom-dist',
342+
validateDeployFiles: staticExportValidateDeployOutput,
318343
}),
319344
distDir: () =>
320345
createE2EFixture('dist-dir', {

0 commit comments

Comments
 (0)