Files
vercel/packages/python/test/integration.test.ts
Steven b5b792e42f [tests] Update tests to run with vercel cli tarball (#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 #7967 
- Closes #8245 
- Closes #8227
2022-07-27 17:56:03 -04:00

83 lines
2.2 KiB
TypeScript
Vendored

const fs = require('fs');
const path = require('path');
const assert = require('assert');
const fetch = require('node-fetch');
const execa = require('execa');
const { spawn } = require('child_process');
const {
testDeployment,
} = require('../../../test/lib/deployment/test-deployment.js');
jest.setTimeout(4 * 60 * 1000);
const fixturesPath = path.resolve(__dirname, 'fixtures');
it('should match the probes against Python dev servers', async () => {
const fixture = path.join(fixturesPath, '00-request-path');
await execa(
'pip3',
['install', '--user', '--upgrade', 'setuptools', 'wheel'],
{
cwd: fixture,
stdio: 'inherit',
}
);
await execa('pip3', ['install', '--user', '-r', 'requirements.txt'], {
cwd: fixture,
stdio: 'inherit',
});
const ports = new Map();
ports.set('/api/python.py', 8001);
ports.set('/api/wsgi.py', 8002);
ports.set('/api/asgi.py', 8003);
const { probes } = require(path.join(fixture, 'vercel.json'));
const pythonServer = spawn('python3', ['api/python.py'], {
cwd: fixture,
stdio: 'inherit',
});
const wsgiServer = spawn('python3', ['api/wsgi.py'], {
cwd: fixture,
stdio: 'inherit',
});
const asgiServer = spawn('python3', ['api/asgi.py'], {
cwd: fixture,
stdio: 'inherit',
});
try {
// wait a few seconds for the dev servers to boot-up
await new Promise(r => setTimeout(r, 3000));
for (const { path, mustContain } of probes) {
const port = ports.get(path.substring(0, path.indexOf('?')));
const res = await fetch(`http://localhost:${port}${path}`);
const body = await res.text();
assert(
body.includes(mustContain),
`Expected to contain "${mustContain}" but got "${body}"`
);
}
} finally {
process.kill(pythonServer.pid);
process.kill(wsgiServer.pid);
process.kill(asgiServer.pid);
}
});
// eslint-disable-next-line no-restricted-syntax
for (const fixture of fs.readdirSync(fixturesPath)) {
// eslint-disable-next-line no-loop-func
it(`should build ${fixture}`, async () => {
await expect(
testDeployment(path.join(fixturesPath, fixture))
).resolves.toBeDefined();
});
}