[next] Update tests to run against latest canary (#4682)

In the latest canary of Next.js pages are no longer nested under the `BUILD_ID` folder and instead are nested under a hash for the page bundle content. To prevent these tests from breaking too often from changes in canary this updates to locate the page bundle using the `buildManifest`. This also updates our latest SSG fixture to test against the latest canary to help ensure the feature doesn't break with a new canary release
This commit is contained in:
JJ Kasper
2020-06-22 16:31:37 -05:00
committed by GitHub
parent bb705cd091
commit b454021234
21 changed files with 102 additions and 47 deletions

View File

@@ -95,6 +95,7 @@ async function testDeployment(
bodies[configName] = Buffer.from(JSON.stringify(nowJson));
delete bodies['probe.js'];
const { deploymentId, deploymentUrl } = await nowDeploy(bodies, randomness);
let nextBuildManifest;
for (const probe of nowJson.probes || []) {
console.log('testing', JSON.stringify(probe));
@@ -102,6 +103,42 @@ async function testDeployment(
await new Promise(resolve => setTimeout(resolve, probe.delay));
continue;
}
const nextScriptIndex = probe.path.indexOf('__NEXT_SCRIPT__(');
if (nextScriptIndex > -1) {
const scriptNameEnd = probe.path.lastIndexOf(')');
let scriptName = probe.path.substring(
nextScriptIndex + '__NEXT_SCRIPT__('.length,
scriptNameEnd
);
const scriptArgs = scriptName.split(',');
scriptName = scriptArgs.shift();
const manifestPrefix = scriptArgs.shift() || '';
if (!nextBuildManifest) {
const manifestUrl = `https://${deploymentUrl}${manifestPrefix}/_next/static/testing-build-id/_buildManifest.js`;
console.log('fetching buildManifest at', manifestUrl);
const { text: manifestContent } = await fetchDeploymentUrl(manifestUrl);
// we must eval it since we use devalue to stringify it
global.__BUILD_MANIFEST_CB = null;
nextBuildManifest = eval(
manifestContent
.replace('self.__BUILD_MANIFEST', 'manifest')
.replace(/self.__BUILD_MANIFEST_CB.*/, '')
);
}
const scriptRelativePath = nextBuildManifest[scriptName];
probe.path =
probe.path.substring(0, nextScriptIndex) +
scriptRelativePath +
probe.path.substr(scriptNameEnd + 1);
}
const probeUrl = `https://${deploymentUrl}${probe.path}`;
const fetchOpts = {
...probe.fetchOptions,