rsnext/scripts/reset-vercel-project.mjs
JJ Kasper 073a05a1be
Add handling for testing against deployments (#36285)
This adds a new test mode `next-deploy` which allows testing against deployments using the Vercel CLI. After running these tests they uncovered some bugs we need to correct before fully enabling. Patching the uncovered issues will be done in follow-up PRs and then after resolved this will be enabled to run after new publishes. 

Tests that uncovered bugs to patch in follow-ups:

- [ ] test/e2e/getserversideprops/test/index.test.ts (req.url normalizing)
- [ ] test/e2e/i18n-api-support/index.test.ts (locale prefixed API routes matching)
- [ ] test/e2e/prerender.test.ts (/_next/data/build-id/ does not 404)
2022-04-20 12:23:09 +00:00

59 lines
1.4 KiB
JavaScript

import fetch from 'node-fetch'
export const TEST_PROJECT_NAME = 'vtest314-e2e-tests'
export const TEST_TEAM_NAME = 'vtest314-next-e2e-tests'
export const TEST_TOKEN = process.env.VERCEL_TEST_TOKEN
async function resetProject() {
// TODO: error/bail if existing deployments are pending
const deleteRes = await fetch(
`https://vercel.com/api/v8/projects/${encodeURIComponent(
TEST_PROJECT_NAME
)}?teamId=${TEST_TEAM_NAME}`,
{
method: 'DELETE',
headers: {
Authorization: `Bearer ${TEST_TOKEN}`,
},
}
)
if (!deleteRes.ok && deleteRes.status !== 404) {
throw new Error(
`Failed to delete project got status ${
deleteRes.status
}, ${await deleteRes.text()}`
)
}
const createRes = await fetch(
`https://vercel.com/api/v8/projects?teamId=${TEST_TEAM_NAME}`,
{
method: 'POST',
headers: {
'content-type': 'application/json',
Authorization: `Bearer ${TEST_TOKEN}`,
},
body: JSON.stringify({
framework: 'nextjs',
name: TEST_PROJECT_NAME,
}),
}
)
if (!createRes.ok) {
throw new Error(
`Failed to create project got status ${
createRes.status
}, ${await createRes.text()}`
)
}
console.log(
`Successfully created fresh Vercel project ${TEST_TEAM_NAME}/${TEST_PROJECT_NAME}`
)
}
if (process.env.RESET_VC_PROJECT) {
resetProject().catch(console.error)
}