mirror of
https://github.com/LukeHagar/vercel.git
synced 2025-12-10 04:22:12 +00:00
This PR update the tests suite to wait for Vercel CLI tarball and then use that tarball to run E2E tests. This is valuable because it will package all the packages in this monorepo to make the tests follow more closely what will happen in production once merged. Since the current "Find Changes" step takes about 2 minutes, we run that first (it happens concurrently with the tarball preparation). Then once we complete "Find Changes" we wait for the tarball but it will likely be ready by that point since it also takes about 2 minutes. After both of those steps, the E2E tests continue as usual but with the `VERCEL_CLI_VERSION` set to the tarball. - Related to #7967 - Closes #8245 - Closes #8227
151 lines
3.5 KiB
TypeScript
Vendored
151 lines
3.5 KiB
TypeScript
Vendored
import path from 'path';
|
|
import { promises } from 'fs';
|
|
import { glob } from '@vercel/build-utils';
|
|
import { detectBuilders } from '../src';
|
|
const fs = promises;
|
|
|
|
import {
|
|
testDeployment,
|
|
// @ts-ignore
|
|
} from '../../../test/lib/deployment/test-deployment';
|
|
|
|
jest.setTimeout(4 * 60 * 1000);
|
|
|
|
it('Test `detectBuilders` and `detectRoutes`', async () => {
|
|
const fixture = path.join(__dirname, 'fixtures', '01-zero-config-api');
|
|
const json = await fs.readFile(path.join(fixture, 'package.json'), 'utf8');
|
|
const pkg = JSON.parse(json);
|
|
const fileList = await glob('**', { cwd: fixture });
|
|
const files = Object.keys(fileList);
|
|
|
|
const probes = [
|
|
{
|
|
path: '/api/my-endpoint',
|
|
mustContain: 'my-endpoint',
|
|
status: 200,
|
|
},
|
|
{
|
|
path: '/api/other-endpoint',
|
|
mustContain: 'other-endpoint',
|
|
status: 200,
|
|
},
|
|
{
|
|
path: '/api/team/zeit',
|
|
mustContain: 'team/zeit',
|
|
status: 200,
|
|
},
|
|
{
|
|
path: '/api/user/myself',
|
|
mustContain: 'user/myself',
|
|
status: 200,
|
|
},
|
|
{
|
|
path: '/api/not-okay/',
|
|
status: 404,
|
|
},
|
|
{
|
|
path: '/api',
|
|
status: 404,
|
|
},
|
|
{
|
|
path: '/api/',
|
|
status: 404,
|
|
},
|
|
{
|
|
path: '/',
|
|
mustContain: 'hello from index.txt',
|
|
},
|
|
];
|
|
|
|
const { builders, defaultRoutes } = await detectBuilders(files, pkg);
|
|
|
|
const nowConfig = { builds: builders, routes: defaultRoutes, probes };
|
|
|
|
await fs.writeFile(
|
|
path.join(fixture, 'now.json'),
|
|
JSON.stringify(nowConfig, null, 2)
|
|
);
|
|
|
|
const deployment = await testDeployment(fixture);
|
|
expect(deployment).toBeDefined();
|
|
});
|
|
|
|
it('Test `detectBuilders` with `index` files', async () => {
|
|
const fixture = path.join(__dirname, 'fixtures', '02-zero-config-api');
|
|
const json = await fs.readFile(path.join(fixture, 'package.json'), 'utf8');
|
|
const pkg = JSON.parse(json);
|
|
const fileList = await glob('**', fixture);
|
|
const files = Object.keys(fileList);
|
|
|
|
const probes = [
|
|
{
|
|
path: '/api/not-okay',
|
|
status: 404,
|
|
},
|
|
{
|
|
path: '/api',
|
|
mustContain: 'hello from api/index.js',
|
|
status: 200,
|
|
},
|
|
{
|
|
path: '/api/',
|
|
mustContain: 'hello from api/index.js',
|
|
status: 200,
|
|
},
|
|
{
|
|
path: '/api/index',
|
|
mustContain: 'hello from api/index.js',
|
|
status: 200,
|
|
},
|
|
{
|
|
path: '/api/index.js',
|
|
mustContain: 'hello from api/index.js',
|
|
status: 200,
|
|
},
|
|
{
|
|
path: '/api/date.js',
|
|
mustContain: 'hello from api/date.js',
|
|
status: 200,
|
|
},
|
|
{
|
|
// Someone might expect this to be `date.js`,
|
|
// but I doubt that there is any case were both
|
|
// `date/index.js` and `date.js` exists,
|
|
// so it is not special cased
|
|
path: '/api/date',
|
|
mustContain: 'hello from api/date/index.js',
|
|
status: 200,
|
|
},
|
|
{
|
|
path: '/api/date/',
|
|
mustContain: 'hello from api/date/index.js',
|
|
status: 200,
|
|
},
|
|
{
|
|
path: '/api/date/index',
|
|
mustContain: 'hello from api/date/index.js',
|
|
status: 200,
|
|
},
|
|
{
|
|
path: '/api/date/index.js',
|
|
mustContain: 'hello from api/date/index.js',
|
|
status: 200,
|
|
},
|
|
{
|
|
path: '/',
|
|
mustContain: 'hello from index.txt',
|
|
},
|
|
];
|
|
|
|
const { builders, defaultRoutes } = await detectBuilders(files, pkg);
|
|
|
|
const nowConfig = { builds: builders, routes: defaultRoutes, probes };
|
|
await fs.writeFile(
|
|
path.join(fixture, 'now.json'),
|
|
JSON.stringify(nowConfig, null, 2)
|
|
);
|
|
|
|
const deployment = await testDeployment(fixture);
|
|
expect(deployment).toBeDefined();
|
|
});
|