Files
vercel/test/lib/run-build-lambda.js
Steven f459db9f83 [now-cli] Add e2e test for vercel.json and .vercelignore (#4292)
This PR adds a test for a deployment as well as `now dev` to ensure both `vercel.json` and `.vercelignore` are applied.

I also fixed the remaining test helpers to work with `vercel.json`.
2020-05-07 18:04:37 +00:00

59 lines
1.5 KiB
JavaScript

const { glob, getWriteableDirectory } = require('@vercel/build-utils');
function runAnalyze(wrapper, context) {
if (wrapper.analyze) {
return wrapper.analyze(context);
}
return 'this-is-a-fake-analyze-result-from-default-analyze';
}
async function runBuildLambda(inputPath) {
const inputFiles = await glob('**', inputPath);
const nowJsonRef = inputFiles['vercel.json'] || inputFiles['now.json'];
expect(nowJsonRef).toBeDefined();
const nowJson = require(nowJsonRef.fsPath);
expect(nowJson.builds.length).toBe(1);
const build = nowJson.builds[0];
expect(build.src.includes('*')).toBeFalsy();
const entrypoint = build.src.replace(/^\//, ''); // strip leftmost slash
expect(inputFiles[entrypoint]).toBeDefined();
inputFiles[entrypoint].digest =
'this-is-a-fake-digest-for-non-default-analyze';
const wrapper = require(build.use);
const analyzeResult = runAnalyze(wrapper, {
files: inputFiles,
entrypoint,
config: build.config,
});
const workPath = await getWriteableDirectory();
const buildResult = await wrapper.build({
files: inputFiles,
entrypoint,
config: build.config,
workPath,
});
const { output } = buildResult;
// Windows support
if (output) {
buildResult.output = Object.keys(output).reduce(
(result, path) => ({
...result,
[path.replace(/\\/g, '/')]: output[path],
}),
{}
);
}
return {
analyzeResult,
buildResult,
workPath,
};
}
module.exports = runBuildLambda;