Files
vercel/packages/now-static-build/test/integration.test.js
Steven a7bef9387b [static-build] Fix error handling for unexpected output directory (#4727)
This PR improves the error handling when a zero config framework has an unexpected output directory.

Previously, setting a Docusaurus 2.0 build command to `docusaurus build && mv build foo` would fail with the following:

```
Error: ENOENT: no such file or directory, scandir '/vercel/514ce14b/build'
```

With this PR, the error message will show the expected:

```
Error: No Output Directory named "build" found after the Build completed. You can configure the Output Directory in your project settings. Learn more: https://vercel.com/docs/v2/platform/frequently-asked-questions#missing-public-directory
```

I also changed the usage of [`promisify(fs)`](https://nodejs.org/docs/latest-v10.x/api/util.html#util_util_promisify_original) to [`fs.promises`](https://nodejs.org/docs/latest-v10.x/api/fs.html#fs_fs_promises_api) which is available in Node 10 or newer.

Lastly, I updated the test suite to check if the correct error message is returned for builds we expect to fail.
2020-06-26 23:56:45 -04:00

79 lines
2.2 KiB
JavaScript
Vendored

const fs = require('fs');
const path = require('path');
const {
packAndDeploy,
testDeployment,
} = require('../../../test/lib/deployment/test-deployment.js');
jest.setTimeout(12 * 60 * 1000);
let buildUtilsUrl;
let builderUrl;
beforeAll(async () => {
if (!buildUtilsUrl) {
const buildUtilsPath = path.resolve(
__dirname,
'..',
'..',
'now-build-utils'
);
buildUtilsUrl = await packAndDeploy(buildUtilsPath);
console.log('buildUtilsUrl', buildUtilsUrl);
}
const builderPath = path.resolve(__dirname, '..');
builderUrl = await packAndDeploy(builderPath);
console.log('builderUrl', builderUrl);
});
const fixturesPath = path.resolve(__dirname, 'fixtures');
const testsThatFailToBuild = new Map([
[
'04-wrong-dist-dir',
'No Output Directory named "out" found after the Build completed. You can configure the Output Directory in your project settings.',
],
['05-empty-dist-dir', 'The Output Directory "dist" is empty.'],
[
'06-missing-script',
'Missing required "now-build" script in "package.json"',
],
['07-nonzero-sh', 'Command "./build.sh" exited with 1'],
[
'22-docusaurus-2-build-fail',
'No Output Directory named "build" found after the Build completed. You can configure the Output Directory in your project settings.',
],
[
'36-hugo-version-not-found',
'Version 0.0.0 of Hugo does not exist. Please specify a different one.',
],
]);
// eslint-disable-next-line no-restricted-syntax
for (const fixture of fs.readdirSync(fixturesPath)) {
const errMsg = testsThatFailToBuild.get(fixture);
if (errMsg) {
// eslint-disable-next-line no-loop-func
it(`should fail to build ${fixture}`, async () => {
try {
await testDeployment(
{ builderUrl, buildUtilsUrl },
path.join(fixturesPath, fixture)
);
} catch (err) {
expect(err).toBeTruthy();
expect(err.deployment).toBeTruthy();
expect(err.deployment.errorMessage).toBe(errMsg);
}
});
continue; //eslint-disable-line
}
it(`should build ${fixture}`, async () => {
await expect(
testDeployment(
{ builderUrl, buildUtilsUrl },
path.join(fixturesPath, fixture)
)
).resolves.toBeDefined();
});
}