Skip to content

Commit b5b792e

Browse files
authored
[tests] Update tests to run with vercel cli tarball (vercel#8257)
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 vercel#7967 - Closes vercel#8245 - Closes vercel#8227
1 parent 8993a3c commit b5b792e

File tree

22 files changed

+2392
-338
lines changed

22 files changed

+2392
-338
lines changed

.github/workflows/test.yml

+9-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ jobs:
1717
runs-on: ubuntu-latest
1818
outputs:
1919
tests: ${{ steps['set-tests'].outputs['tests'] }}
20+
dplUrl: ${{ steps.waitForTarball.outputs.url }}
2021
steps:
2122
- uses: actions/checkout@v2
2223
- run: git --version
@@ -32,6 +33,12 @@ jobs:
3233
echo "Files to test:"
3334
echo "$TESTS_ARRAY"
3435
echo "::set-output name=tests::$TESTS_ARRAY"
36+
- uses: patrickedqvist/wait-for-vercel-preview@ae34b392ef30297f2b672f9afb3c329bde9bd487
37+
id: waitForTarball
38+
with:
39+
token: ${{ secrets.GITHUB_TOKEN }}
40+
max_timeout: 360
41+
check_interval: 5
3542

3643
test:
3744
timeout-minutes: 120
@@ -69,13 +76,14 @@ jobs:
6976
- run: yarn install --network-timeout 1000000
7077

7178
- name: Build ${{matrix.packageName}} and all its dependencies
72-
run: yarn turbo run build --cache-dir=".turbo" --scope=${{matrix.packageName}} --include-dependencies --no-deps
79+
run: node_modules/.bin/turbo run build --cache-dir=".turbo" --scope=${{matrix.packageName}} --include-dependencies --no-deps
7380
env:
7481
FORCE_COLOR: '1'
7582
- name: Test ${{matrix.packageName}}
7683
run: node_modules/.bin/turbo run test --cache-dir=".turbo" --scope=${{matrix.packageName}} --no-deps -- ${{ join(matrix.testPaths, ' ') }}
7784
shell: bash
7885
env:
86+
VERCEL_CLI_VERSION: ${{ needs.setup.outputs.dplUrl }}/tarballs/vercel.tgz
7987
VERCEL_TEAM_TOKEN: ${{ secrets.VERCEL_TEAM_TOKEN }}
8088
VERCEL_REGISTRATION_URL: ${{ secrets.VERCEL_REGISTRATION_URL }}
8189
FORCE_COLOR: '1'

packages/build-utils/test/integration.test.ts

+2-18
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,12 @@
11
import path from 'path';
22
import fs from 'fs-extra';
33
import {
4-
packAndDeploy,
54
testDeployment,
65
// @ts-ignore
76
} from '../../../test/lib/deployment/test-deployment';
87

98
jest.setTimeout(4 * 60 * 1000);
109

11-
const builderUrl = '@canary';
12-
let buildUtilsUrl: string;
13-
14-
beforeAll(async () => {
15-
const buildUtilsPath = path.resolve(__dirname, '..');
16-
buildUtilsUrl = await packAndDeploy(buildUtilsPath);
17-
console.log('buildUtilsUrl', buildUtilsUrl);
18-
});
19-
2010
const fixturesPath = path.resolve(__dirname, 'fixtures');
2111

2212
// Fixtures that have separate tests and should be skipped in the loop
@@ -42,10 +32,7 @@ for (const fixture of fs.readdirSync(fixturesPath)) {
4232
// eslint-disable-next-line no-loop-func
4333
it(`Should build "${fixture}"`, async () => {
4434
await expect(
45-
testDeployment(
46-
{ builderUrl, buildUtilsUrl },
47-
path.join(fixturesPath, fixture)
48-
)
35+
testDeployment(path.join(fixturesPath, fixture))
4936
).resolves.toBeDefined();
5037
});
5138
}
@@ -68,10 +55,7 @@ for (const builder of buildersToTestWith) {
6855
// eslint-disable-next-line no-loop-func
6956
it(`Should build "${builder}/${fixture}"`, async () => {
7057
await expect(
71-
testDeployment(
72-
{ builderUrl, buildUtilsUrl },
73-
path.join(fixturesPath2, fixture)
74-
)
58+
testDeployment(path.join(fixturesPath2, fixture))
7559
).resolves.toBeDefined();
7660
});
7761
}

packages/fs-detectors/test/integration.test.ts

+2-18
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,12 @@ import { detectBuilders } from '../src';
55
const fs = promises;
66

77
import {
8-
packAndDeploy,
98
testDeployment,
109
// @ts-ignore
1110
} from '../../../test/lib/deployment/test-deployment';
1211

1312
jest.setTimeout(4 * 60 * 1000);
1413

15-
const builderUrl = '@canary';
16-
let buildUtilsUrl: string;
17-
18-
beforeAll(async () => {
19-
const buildUtilsPath = path.resolve(__dirname, '..');
20-
buildUtilsUrl = await packAndDeploy(buildUtilsPath);
21-
console.log('buildUtilsUrl', buildUtilsUrl);
22-
});
23-
2414
it('Test `detectBuilders` and `detectRoutes`', async () => {
2515
const fixture = path.join(__dirname, 'fixtures', '01-zero-config-api');
2616
const json = await fs.readFile(path.join(fixture, 'package.json'), 'utf8');
@@ -76,10 +66,7 @@ it('Test `detectBuilders` and `detectRoutes`', async () => {
7666
JSON.stringify(nowConfig, null, 2)
7767
);
7868

79-
const deployment = await testDeployment(
80-
{ builderUrl, buildUtilsUrl },
81-
fixture
82-
);
69+
const deployment = await testDeployment(fixture);
8370
expect(deployment).toBeDefined();
8471
});
8572

@@ -158,9 +145,6 @@ it('Test `detectBuilders` with `index` files', async () => {
158145
JSON.stringify(nowConfig, null, 2)
159146
);
160147

161-
const deployment = await testDeployment(
162-
{ builderUrl, buildUtilsUrl },
163-
fixture
164-
);
148+
const deployment = await testDeployment(fixture);
165149
expect(deployment).toBeDefined();
166150
});

packages/go/test/fixtures/17-go-mod-api/vercel.json

+1-8
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,8 @@
11
{
22
"version": 2,
3-
"builds": [
4-
{
5-
"src": "api/v1/routes/**/*.go",
6-
"use": "@vercel/go",
7-
"config": { "zeroConfig": true }
8-
}
9-
],
103
"probes": [
114
{
12-
"path": "/api/v1/routes/someroute.go",
5+
"path": "/api/v1/routes/someroute",
136
"mustContain": "version:go1.13.15:Dependency:RANDOMNESS_PLACEHOLDER"
147
}
158
]

packages/go/test/test.js

+1-18
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,10 @@ const fs = require('fs');
22
const path = require('path');
33

44
const {
5-
packAndDeploy,
65
testDeployment,
76
} = require('../../../test/lib/deployment/test-deployment.js');
87

98
jest.setTimeout(4 * 60 * 1000);
10-
let buildUtilsUrl;
11-
let builderUrl;
12-
13-
beforeAll(async () => {
14-
if (!buildUtilsUrl) {
15-
const buildUtilsPath = path.resolve(__dirname, '..', '..', 'build-utils');
16-
buildUtilsUrl = await packAndDeploy(buildUtilsPath);
17-
console.log('buildUtilsUrl', buildUtilsUrl);
18-
}
19-
const builderPath = path.resolve(__dirname, '..');
20-
builderUrl = await packAndDeploy(builderPath);
21-
console.log('builderUrl', builderUrl);
22-
});
239

2410
const skipFixtures = ['08-include-files'];
2511
const fixturesPath = path.resolve(__dirname, 'fixtures');
@@ -33,10 +19,7 @@ for (const fixture of fs.readdirSync(fixturesPath)) {
3319
// eslint-disable-next-line no-loop-func
3420
it(`should build ${fixture}`, async () => {
3521
await expect(
36-
testDeployment(
37-
{ builderUrl, buildUtilsUrl },
38-
path.join(fixturesPath, fixture)
39-
)
22+
testDeployment(path.join(fixturesPath, fixture))
4023
).resolves.toBeDefined();
4124
});
4225
}

packages/hydrogen/test/test.js

+1-15
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,20 @@
11
const fs = require('fs');
22
const path = require('path');
3-
const { version } = require('../package.json');
43

54
const {
6-
packAndDeploy,
75
testDeployment,
86
} = require('../../../test/lib/deployment/test-deployment.js');
97

108
jest.setTimeout(12 * 60 * 1000);
119

12-
let builderUrl;
13-
const buildUtilsUrl = version.includes('canary') ? '@canary' : undefined;
14-
15-
beforeAll(async () => {
16-
const builderPath = path.resolve(__dirname, '..');
17-
builderUrl = await packAndDeploy(builderPath);
18-
console.log('builderUrl', builderUrl);
19-
});
20-
2110
const fixturesPath = path.resolve(__dirname, 'fixtures');
2211

2312
// eslint-disable-next-line no-restricted-syntax
2413
for (const fixture of fs.readdirSync(fixturesPath)) {
2514
// eslint-disable-next-line no-loop-func
2615
it(`should build ${fixture}`, async () => {
2716
await expect(
28-
testDeployment(
29-
{ builderUrl, buildUtilsUrl },
30-
path.join(fixturesPath, fixture)
31-
)
17+
testDeployment(path.join(fixturesPath, fixture))
3218
).resolves.toBeDefined();
3319
});
3420
}

packages/next/test/utils.ts

+2-52
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
import type { Context, LoggerServer, Dictionary } from './types';
22
import type { IncomingMessage } from 'http';
33

4-
import {
5-
packAndDeploy,
6-
testDeployment,
7-
} from '../../../test/lib/deployment/test-deployment';
8-
import { fetchTokenWithRetry } from '../../../test/lib/deployment/now-deploy';
4+
import { testDeployment } from '../../../test/lib/deployment/test-deployment';
95

106
import fs from 'fs-extra';
117
import http from 'http';
@@ -72,56 +68,10 @@ export const createLoggerServer = async (): Promise<LoggerServer> => {
7268
return { url, close, content };
7369
};
7470

75-
let builderUrlPromise;
76-
let builderUrlLastUpdated = 0;
77-
const buildUtilsUrl = '@canary';
78-
7971
process.env.NEXT_TELEMETRY_DISABLED = '1';
8072

8173
export async function deployAndTest(fixtureDir) {
82-
let builderInfo;
83-
const builderInfoPath = path.join(__dirname, 'builder-info.json');
84-
85-
try {
86-
builderInfo = await fs.readJSON(builderInfoPath);
87-
} catch (_) {
88-
/**/
89-
}
90-
let tempToken;
91-
92-
if (!builderUrlPromise && builderInfo) {
93-
builderUrlPromise = Promise.resolve(builderInfo.builderUrl);
94-
builderUrlLastUpdated = builderInfo.lastUpdated;
95-
tempToken = builderInfo.tempToken;
96-
}
97-
const builderUrlIsStale = builderUrlLastUpdated < Date.now() - ms('25min');
98-
99-
if (!process.env.VERCEL_TOKEN && (builderUrlIsStale || !tempToken)) {
100-
tempToken = await fetchTokenWithRetry();
101-
}
102-
process.env.TEMP_TOKEN = tempToken;
103-
104-
if (builderUrlIsStale) {
105-
const builderPath = path.resolve(__dirname, '..');
106-
builderUrlPromise = packAndDeploy(builderPath, false);
107-
builderUrlLastUpdated = Date.now();
108-
}
109-
110-
const builderUrl = await builderUrlPromise;
111-
112-
await fs.writeFile(
113-
builderInfoPath,
114-
JSON.stringify({
115-
tempToken,
116-
builderUrl,
117-
lastUpdated: builderUrlLastUpdated,
118-
})
119-
);
120-
121-
const { deploymentId, deploymentUrl } = await testDeployment(
122-
{ builderUrl, buildUtilsUrl },
123-
fixtureDir
124-
);
74+
const { deploymentId, deploymentUrl } = await testDeployment(fixtureDir);
12575

12676
return {
12777
deploymentId,

packages/node/test/fixtures/35-puppeteer/screenshot/index.js packages/node/test/fixtures/35-puppeteer/api/screenshot.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ async function getScreenshot(url) {
2828
module.exports = async (req, res) => {
2929
const buffer = await getScreenshot('https://vercel.com/about');
3030
if (buffer.length > 0) {
31-
res.end('screenshot:RANDOMNESS_PLACEHOLDER');
31+
res.end('/api/screenshot:RANDOMNESS_PLACEHOLDER');
3232
} else {
3333
res.end('buffer is empty');
3434
}

packages/node/test/fixtures/35-puppeteer/lighthouse/index.js

-35
This file was deleted.

packages/node/test/fixtures/35-puppeteer/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"private": true,
23
"engines": {
34
"node": "14.x"
45
},

packages/node/test/fixtures/35-puppeteer/probe.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ async function tryTest({
99
retries = 4,
1010
}) {
1111
try {
12-
const res = await fetch(`https://${deploymentUrl}/${testName}`);
12+
const res = await fetch(`https://${deploymentUrl}${testName}`);
1313
assert.equal(res.status, 200);
1414
const text = await res.text();
1515
assert.equal(text.trim(), `${testName}:${randomness}`);
@@ -32,6 +32,10 @@ async function tryTest({
3232
}
3333

3434
module.exports = async ({ deploymentUrl, fetch, randomness }) => {
35-
await tryTest({ testName: 'lighthouse', deploymentUrl, fetch, randomness });
36-
await tryTest({ testName: 'screenshot', deploymentUrl, fetch, randomness });
35+
await tryTest({
36+
testName: '/api/screenshot',
37+
deploymentUrl,
38+
fetch,
39+
randomness,
40+
});
3741
};
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,8 @@
11
{
2-
"version": 2,
3-
"builds": [
4-
{
5-
"src": "**/*.js",
6-
"use": "@vercel/node",
7-
"config": {
8-
"functions": {
9-
"**/*.js": {
10-
"memory": 3008,
11-
"maxDuration": 30
12-
}
13-
}
14-
}
2+
"functions": {
3+
"api/**/*.js": {
4+
"memory": 1024,
5+
"maxDuration": 10
156
}
16-
]
7+
}
178
}

0 commit comments

Comments
 (0)