mirror of
https://github.com/LukeHagar/vercel.git
synced 2025-12-09 12:57:46 +00:00
[tests] Pass in builder to runBuildLambda() (#9262)
Removes the need for `next`/`static-build` to be present in the root `package.json` file.
This commit is contained in:
@@ -13,8 +13,6 @@
|
||||
"@typescript-eslint/parser": "5.21.0",
|
||||
"@vercel/build-utils": "*",
|
||||
"@vercel/ncc": "0.24.0",
|
||||
"@vercel/next": "*",
|
||||
"@vercel/static-build": "*",
|
||||
"async-retry": "1.2.3",
|
||||
"buffer-replace": "1.0.0",
|
||||
"create-svelte": "2.0.1",
|
||||
|
||||
@@ -2,8 +2,12 @@ process.env.NEXT_TELEMETRY_DISABLED = '1';
|
||||
|
||||
const path = require('path');
|
||||
const fs = require('fs-extra');
|
||||
const builder = require('../../');
|
||||
const {
|
||||
createRunBuildLambda,
|
||||
} = require('../../../../test/lib/run-build-lambda');
|
||||
|
||||
const runBuildLambda = require('../../../../test/lib/run-build-lambda');
|
||||
const runBuildLambda = createRunBuildLambda(builder);
|
||||
|
||||
jest.setTimeout(360000);
|
||||
|
||||
|
||||
@@ -6,10 +6,13 @@ import type { Context } from '../types';
|
||||
import { duplicateWithConfig } from '../utils';
|
||||
import fs from 'fs-extra';
|
||||
import path from 'path';
|
||||
import runBuildLambda from '../../../../test/lib/run-build-lambda';
|
||||
import * as builder from '../../';
|
||||
import { createRunBuildLambda } from '../../../../test/lib/run-build-lambda';
|
||||
import { EdgeFunction, Files, streamToBuffer } from '@vercel/build-utils';
|
||||
import { createHash } from 'crypto';
|
||||
|
||||
const runBuildLambda = createRunBuildLambda(builder);
|
||||
|
||||
const SIMPLE_PROJECT = path.resolve(
|
||||
__dirname,
|
||||
'..',
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
describe('export', () => {
|
||||
it('should require by path main', async () => {
|
||||
const main = require('@vercel/next');
|
||||
expect(main).toBeDefined();
|
||||
});
|
||||
});
|
||||
5
packages/static-build/test/builds.test.js
vendored
5
packages/static-build/test/builds.test.js
vendored
@@ -1,6 +1,9 @@
|
||||
const path = require('path');
|
||||
const fs = require('fs-extra');
|
||||
const runBuildLambda = require('../../../test/lib/run-build-lambda');
|
||||
const builder = require('../');
|
||||
const { createRunBuildLambda } = require('../../../test/lib/run-build-lambda');
|
||||
|
||||
const runBuildLambda = createRunBuildLambda(builder);
|
||||
|
||||
const FOUR_MINUTES = 240000;
|
||||
|
||||
|
||||
12
pnpm-lock.yaml
generated
12
pnpm-lock.yaml
generated
@@ -9,8 +9,6 @@ importers:
|
||||
'@typescript-eslint/parser': 5.21.0
|
||||
'@vercel/build-utils': '*'
|
||||
'@vercel/ncc': 0.24.0
|
||||
'@vercel/next': '*'
|
||||
'@vercel/static-build': '*'
|
||||
async-retry: 1.2.3
|
||||
buffer-replace: 1.0.0
|
||||
create-svelte: 2.0.1
|
||||
@@ -40,8 +38,6 @@ importers:
|
||||
'@typescript-eslint/parser': 5.21.0_eslint@8.14.0
|
||||
'@vercel/build-utils': link:packages/build-utils
|
||||
'@vercel/ncc': 0.24.0
|
||||
'@vercel/next': link:packages/next
|
||||
'@vercel/static-build': link:packages/static-build
|
||||
async-retry: 1.2.3
|
||||
buffer-replace: 1.0.0
|
||||
create-svelte: 2.0.1
|
||||
@@ -1214,7 +1210,7 @@ packages:
|
||||
'@babel/core': ^7.0.0
|
||||
dependencies:
|
||||
'@babel/compat-data': 7.20.10
|
||||
'@babel/core': 7.20.12
|
||||
'@babel/core': 7.20.12_supports-color@7.2.0
|
||||
'@babel/helper-validator-option': 7.18.6
|
||||
browserslist: 4.21.4
|
||||
lru-cache: 5.1.1
|
||||
@@ -1719,7 +1715,7 @@ packages:
|
||||
peerDependencies:
|
||||
'@babel/core': ^7.0.0-0
|
||||
dependencies:
|
||||
'@babel/core': 7.20.12
|
||||
'@babel/core': 7.20.12_supports-color@7.2.0
|
||||
'@babel/helper-plugin-utils': 7.20.2
|
||||
dev: true
|
||||
|
||||
@@ -1849,7 +1845,7 @@ packages:
|
||||
peerDependencies:
|
||||
'@babel/core': ^7.0.0-0
|
||||
dependencies:
|
||||
'@babel/core': 7.20.12
|
||||
'@babel/core': 7.20.12_supports-color@7.2.0
|
||||
'@babel/helper-plugin-utils': 7.20.2
|
||||
dev: true
|
||||
|
||||
@@ -1858,7 +1854,7 @@ packages:
|
||||
peerDependencies:
|
||||
'@babel/core': ^7.0.0-0
|
||||
dependencies:
|
||||
'@babel/core': 7.20.12
|
||||
'@babel/core': 7.20.12_supports-color@7.2.0
|
||||
'@babel/helper-plugin-utils': 7.20.2
|
||||
dev: true
|
||||
|
||||
|
||||
@@ -4,15 +4,8 @@ const fs = require('fs-extra');
|
||||
const json5 = require('json5');
|
||||
const { glob } = 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) {
|
||||
exports.createRunBuildLambda = function (builder) {
|
||||
return async inputPath => {
|
||||
const inputFiles = await glob('**', inputPath);
|
||||
const nowJsonRef = inputFiles['vercel.json'] || inputFiles['now.json'];
|
||||
|
||||
@@ -30,16 +23,6 @@ async function runBuildLambda(inputPath) {
|
||||
if (typeof expect !== 'undefined') {
|
||||
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,
|
||||
});
|
||||
|
||||
let workPath = path.join(
|
||||
os.tmpdir(),
|
||||
`vercel-${Date.now()}-${Math.floor(Math.random() * 100)}`
|
||||
@@ -49,7 +32,7 @@ async function runBuildLambda(inputPath) {
|
||||
workPath = await fs.realpath(workPath);
|
||||
console.log('building in', workPath);
|
||||
|
||||
const buildResult = await wrapper.build({
|
||||
const buildResult = await builder.build({
|
||||
files: inputFiles,
|
||||
entrypoint,
|
||||
config: build.config,
|
||||
@@ -69,10 +52,8 @@ async function runBuildLambda(inputPath) {
|
||||
}
|
||||
|
||||
return {
|
||||
analyzeResult,
|
||||
buildResult,
|
||||
workPath,
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = runBuildLambda;
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user