mirror of
https://github.com/LukeHagar/vercel.git
synced 2025-12-09 21:07:46 +00:00
[now-cli] Install dependencies before running now dev in tests (#2948)
* [now-cli] Install dependencies before running `now dev` in tests * Check install exit code * Add more logging * Add more logging * More logging * Include yarn.lock file * Add lock files to dev fixtures * Ignore test * Ignore another test * Ignore another test * Whitespace * Install deps for unit tests * Whitespace
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -12,6 +12,7 @@ packages/now-cli/.builders
|
||||
packages/now-cli/assets
|
||||
packages/now-cli/src/util/dev/templates/*.ts
|
||||
packages/now-cli/test/**/yarn.lock
|
||||
!packages/now-cli/test/dev/**/yarn.lock
|
||||
packages/now-cli/test/**/node_modules
|
||||
packages/now-cli/test/dev/fixtures/08-hugo/hugo
|
||||
packages/now-cli/test/dev/fixtures/**/dist
|
||||
|
||||
1
packages/now-cli/test/dev-builder.unit.js
vendored
1
packages/now-cli/test/dev-builder.unit.js
vendored
@@ -1,5 +1,4 @@
|
||||
import test from 'ava';
|
||||
|
||||
import { filterPackage } from '../src/util/dev/builder-cache';
|
||||
|
||||
test('[dev-builder] filter install "latest", cached canary', async t => {
|
||||
|
||||
1
packages/now-cli/test/dev-router.unit.js
vendored
1
packages/now-cli/test/dev-router.unit.js
vendored
@@ -1,5 +1,4 @@
|
||||
import test from 'ava';
|
||||
|
||||
import devRouter from '../src/util/dev/router';
|
||||
|
||||
test('[dev-router] 301 redirection', async t => {
|
||||
|
||||
14
packages/now-cli/test/dev-server.unit.js
vendored
14
packages/now-cli/test/dev-server.unit.js
vendored
@@ -1,6 +1,8 @@
|
||||
import url from 'url';
|
||||
import test from 'ava';
|
||||
import path from 'path';
|
||||
import execa from 'execa';
|
||||
import fs from 'fs-extra';
|
||||
import fetch from 'node-fetch';
|
||||
import listen from 'async-listen';
|
||||
import { request, createServer } from 'http';
|
||||
@@ -9,9 +11,20 @@ import DevServer from '../src/util/dev/server';
|
||||
import { installBuilders, getBuildUtils } from '../src/util/dev/builder-cache';
|
||||
import parseListen from '../src/util/dev/parse-listen';
|
||||
|
||||
async function runNpmInstall(fixturePath) {
|
||||
if (await fs.exists(path.join(fixturePath, 'package.json'))) {
|
||||
return execa('yarn', ['install'], { cwd: fixturePath });
|
||||
}
|
||||
}
|
||||
|
||||
function testFixture(name, fn) {
|
||||
return async t => {
|
||||
let server;
|
||||
|
||||
const fixturePath = path.join(__dirname, 'fixtures', 'unit', name);
|
||||
|
||||
await runNpmInstall(fixturePath);
|
||||
|
||||
try {
|
||||
let readyResolve;
|
||||
let readyPromise = new Promise(resolve => {
|
||||
@@ -29,7 +42,6 @@ function testFixture(name, fn) {
|
||||
origReady(msg);
|
||||
};
|
||||
|
||||
const fixturePath = path.join(__dirname, `fixtures/unit/${name}`);
|
||||
server = new DevServer(fixturePath, { output, debug });
|
||||
|
||||
await server.start(0);
|
||||
|
||||
8
packages/now-cli/test/dev/fixtures/01-node/yarn.lock
Normal file
8
packages/now-cli/test/dev/fixtures/01-node/yarn.lock
Normal file
@@ -0,0 +1,8 @@
|
||||
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
|
||||
# yarn lockfile v1
|
||||
|
||||
|
||||
moment@^2.24.0:
|
||||
version "2.24.0"
|
||||
resolved "https://registry.yarnpkg.com/moment/-/moment-2.24.0.tgz#0d055d53f5052aa653c9f6eb68bb5d12bf5c2b5b"
|
||||
integrity sha512-bV7f+6l2QigeBBZSM/6yTNq4P2fNpSWj/0e7jQcy87A8e7o2nAfP/34/2ky5Vw4B9S446EtIhodAzkFCcR4dQg==
|
||||
7171
packages/now-cli/test/dev/fixtures/02-angular-node/yarn.lock
Normal file
7171
packages/now-cli/test/dev/fixtures/02-angular-node/yarn.lock
Normal file
File diff suppressed because it is too large
Load Diff
@@ -34,3 +34,5 @@ node_modules
|
||||
/public
|
||||
/test/coverage-jest
|
||||
/test/coverage-karma
|
||||
|
||||
!yarn.lock
|
||||
|
||||
@@ -1,2 +1 @@
|
||||
README.md
|
||||
yarn.lock
|
||||
9302
packages/now-cli/test/dev/fixtures/03-aurelia/yarn.lock
Normal file
9302
packages/now-cli/test/dev/fixtures/03-aurelia/yarn.lock
Normal file
File diff suppressed because it is too large
Load Diff
12119
packages/now-cli/test/dev/fixtures/05-gatsby/yarn.lock
Normal file
12119
packages/now-cli/test/dev/fixtures/05-gatsby/yarn.lock
Normal file
File diff suppressed because it is too large
Load Diff
2544
packages/now-cli/test/dev/fixtures/07-hexo-node/yarn.lock
Normal file
2544
packages/now-cli/test/dev/fixtures/07-hexo-node/yarn.lock
Normal file
File diff suppressed because it is too large
Load Diff
4
packages/now-cli/test/dev/fixtures/08-hugo/yarn.lock
Normal file
4
packages/now-cli/test/dev/fixtures/08-hugo/yarn.lock
Normal file
@@ -0,0 +1,4 @@
|
||||
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
|
||||
# yarn lockfile v1
|
||||
|
||||
|
||||
4606
packages/now-cli/test/dev/fixtures/10-nextjs-node/yarn.lock
Normal file
4606
packages/now-cli/test/dev/fixtures/10-nextjs-node/yarn.lock
Normal file
File diff suppressed because it is too large
Load Diff
7401
packages/now-cli/test/dev/fixtures/11-nuxtjs-node/yarn.lock
Normal file
7401
packages/now-cli/test/dev/fixtures/11-nuxtjs-node/yarn.lock
Normal file
File diff suppressed because it is too large
Load Diff
8752
packages/now-cli/test/dev/fixtures/12-polymer-node/yarn.lock
Normal file
8752
packages/now-cli/test/dev/fixtures/12-polymer-node/yarn.lock
Normal file
File diff suppressed because it is too large
Load Diff
1862
packages/now-cli/test/dev/fixtures/14-svelte-node/yarn.lock
Normal file
1862
packages/now-cli/test/dev/fixtures/14-svelte-node/yarn.lock
Normal file
File diff suppressed because it is too large
Load Diff
7566
packages/now-cli/test/dev/fixtures/16-vue-node/yarn.lock
Normal file
7566
packages/now-cli/test/dev/fixtures/16-vue-node/yarn.lock
Normal file
File diff suppressed because it is too large
Load Diff
8311
packages/now-cli/test/dev/fixtures/17-vuepress-node/yarn.lock
Normal file
8311
packages/now-cli/test/dev/fixtures/17-vuepress-node/yarn.lock
Normal file
File diff suppressed because it is too large
Load Diff
4776
packages/now-cli/test/dev/fixtures/18-marko/yarn.lock
Normal file
4776
packages/now-cli/test/dev/fixtures/18-marko/yarn.lock
Normal file
File diff suppressed because it is too large
Load Diff
2912
packages/now-cli/test/dev/fixtures/19-mithril/yarn.lock
Normal file
2912
packages/now-cli/test/dev/fixtures/19-mithril/yarn.lock
Normal file
File diff suppressed because it is too large
Load Diff
4979
packages/now-cli/test/dev/fixtures/20-riot/yarn.lock
Normal file
4979
packages/now-cli/test/dev/fixtures/20-riot/yarn.lock
Normal file
File diff suppressed because it is too large
Load Diff
4714
packages/now-cli/test/dev/fixtures/21-charge/yarn.lock
Normal file
4714
packages/now-cli/test/dev/fixtures/21-charge/yarn.lock
Normal file
File diff suppressed because it is too large
Load Diff
3631
packages/now-cli/test/dev/fixtures/22-brunch/yarn.lock
Normal file
3631
packages/now-cli/test/dev/fixtures/22-brunch/yarn.lock
Normal file
File diff suppressed because it is too large
Load Diff
7799
packages/now-cli/test/dev/fixtures/24-ember/yarn.lock
Normal file
7799
packages/now-cli/test/dev/fixtures/24-ember/yarn.lock
Normal file
File diff suppressed because it is too large
Load Diff
14029
packages/now-cli/test/dev/fixtures/handle-filesystem-missing/yarn.lock
Normal file
14029
packages/now-cli/test/dev/fixtures/handle-filesystem-missing/yarn.lock
Normal file
File diff suppressed because it is too large
Load Diff
@@ -53,11 +53,19 @@ async function exec(directory, args = []) {
|
||||
});
|
||||
}
|
||||
|
||||
async function runNpmInstall(fixturePath) {
|
||||
if (await fs.exists(path.join(fixturePath, 'package.json'))) {
|
||||
return execa('yarn', ['install'], { cwd: fixturePath });
|
||||
}
|
||||
}
|
||||
|
||||
function formatOutput({ stderr, stdout }) {
|
||||
return `Received:\n"${stderr}"\n"${stdout}"`;
|
||||
}
|
||||
|
||||
function testFixture(directory, opts = {}, args = []) {
|
||||
async function testFixture(directory, opts = {}, args = []) {
|
||||
await runNpmInstall(directory);
|
||||
|
||||
port = ++port;
|
||||
return {
|
||||
dev: execa(binaryPath, ['dev', directory, '-l', String(port), ...args], {
|
||||
@@ -74,6 +82,9 @@ function testFixtureStdio(directory, fn) {
|
||||
return async t => {
|
||||
let dev;
|
||||
const dir = fixture(directory);
|
||||
|
||||
await runNpmInstall(dir);
|
||||
|
||||
try {
|
||||
port = ++port;
|
||||
let output = '';
|
||||
@@ -112,7 +123,10 @@ test('[now dev] validate builds', async t => {
|
||||
const output = await exec(directory);
|
||||
|
||||
t.is(output.code, 1, formatOutput(output));
|
||||
t.regex(output.stderr, /Invalid `builds` property: \[0\]\.src should be string/gm);
|
||||
t.regex(
|
||||
output.stderr,
|
||||
/Invalid `builds` property: \[0\]\.src should be string/gm
|
||||
);
|
||||
});
|
||||
|
||||
test('[now dev] validate routes', async t => {
|
||||
@@ -120,12 +134,15 @@ test('[now dev] validate routes', async t => {
|
||||
const output = await exec(directory);
|
||||
|
||||
t.is(output.code, 1, formatOutput(output));
|
||||
t.regex(output.stderr, /Invalid `routes` property: \[0\]\.src should be string/gm);
|
||||
t.regex(
|
||||
output.stderr,
|
||||
/Invalid `routes` property: \[0\]\.src should be string/gm
|
||||
);
|
||||
});
|
||||
|
||||
test('[now dev] 00-list-directory', async t => {
|
||||
const directory = fixture('00-list-directory');
|
||||
const { dev, port } = testFixture(directory);
|
||||
const { dev, port } = await testFixture(directory);
|
||||
|
||||
try {
|
||||
// start `now dev` detached in child_process
|
||||
@@ -147,7 +164,7 @@ test('[now dev] 00-list-directory', async t => {
|
||||
|
||||
test('[now dev] 01-node', async t => {
|
||||
const directory = fixture('01-node');
|
||||
const { dev, port } = testFixture(directory);
|
||||
const { dev, port } = await testFixture(directory);
|
||||
|
||||
try {
|
||||
// start `now dev` detached in child_process
|
||||
@@ -169,7 +186,9 @@ test('[now dev] 01-node', async t => {
|
||||
if (satisfies(process.version, '10.x')) {
|
||||
test('[now dev] 02-angular-node', async t => {
|
||||
const directory = fixture('02-angular-node');
|
||||
const { dev, port } = testFixture(directory, { stdio: 'pipe' }, ['--debug']);
|
||||
const { dev, port } = await testFixture(directory, { stdio: 'pipe' }, [
|
||||
'--debug'
|
||||
]);
|
||||
|
||||
let stderr = '';
|
||||
|
||||
@@ -256,7 +275,7 @@ test(
|
||||
|
||||
test('[now dev] 07-hexo-node', async t => {
|
||||
const directory = fixture('07-hexo-node');
|
||||
const { dev, port } = testFixture(directory);
|
||||
const { dev, port } = await testFixture(directory);
|
||||
|
||||
try {
|
||||
// start `now dev` detached in child_process
|
||||
@@ -289,7 +308,7 @@ test(
|
||||
|
||||
test('[now dev] 10-nextjs-node', async t => {
|
||||
const directory = fixture('10-nextjs-node');
|
||||
const { dev, port } = testFixture(directory);
|
||||
const { dev, port } = await testFixture(directory);
|
||||
|
||||
try {
|
||||
// start `now dev` detached in child_process
|
||||
@@ -309,7 +328,7 @@ test('[now dev] 10-nextjs-node', async t => {
|
||||
|
||||
// test('[now dev] 11-nuxtjs-node', async t => {
|
||||
// const directory = fixture('11-nuxtjs-node');
|
||||
// const { dev, port } = testFixture(directory);
|
||||
// const { dev, port } = await testFixture(directory);
|
||||
|
||||
// try {
|
||||
// // start `now dev` detached in child_process
|
||||
@@ -330,7 +349,7 @@ test('[now dev] 10-nextjs-node', async t => {
|
||||
|
||||
test('[now dev] 12-polymer-node', async t => {
|
||||
const directory = fixture('12-polymer-node');
|
||||
const { dev, port } = testFixture(directory);
|
||||
const { dev, port } = await testFixture(directory);
|
||||
|
||||
try {
|
||||
// start `now dev` detached in child_process
|
||||
@@ -350,7 +369,7 @@ test('[now dev] 12-polymer-node', async t => {
|
||||
|
||||
test('[now dev] 13-preact-node', async t => {
|
||||
const directory = fixture('13-preact-node');
|
||||
const { dev, port } = testFixture(directory);
|
||||
const { dev, port } = await testFixture(directory);
|
||||
|
||||
try {
|
||||
// start `now dev` detached in child_process
|
||||
@@ -370,7 +389,7 @@ test('[now dev] 13-preact-node', async t => {
|
||||
|
||||
test('[now dev] 14-svelte-node', async t => {
|
||||
const directory = fixture('14-svelte-node');
|
||||
const { dev, port } = testFixture(directory);
|
||||
const { dev, port } = await testFixture(directory);
|
||||
|
||||
try {
|
||||
// start `now dev` detached in child_process
|
||||
@@ -390,7 +409,7 @@ test('[now dev] 14-svelte-node', async t => {
|
||||
|
||||
// test('[now dev] 15-umijs-node', async t => {
|
||||
// const directory = fixture('15-umijs-node');
|
||||
// const { dev, port } = testFixture(directory);
|
||||
// const { dev, port } = await testFixture(directory);
|
||||
|
||||
// try {
|
||||
// // start `now dev` detached in child_process
|
||||
@@ -409,49 +428,54 @@ test('[now dev] 14-svelte-node', async t => {
|
||||
// }
|
||||
// });
|
||||
|
||||
test('[now dev] 16-vue-node', async t => {
|
||||
const directory = fixture('16-vue-node');
|
||||
const { dev, port } = testFixture(directory);
|
||||
if (satisfies(process.version, '^8.12.0 || >=9.7.0')) {
|
||||
test('[now dev] 16-vue-node', async t => {
|
||||
const directory = fixture('16-vue-node');
|
||||
const { dev, port } = await testFixture(directory);
|
||||
|
||||
try {
|
||||
// start `now dev` detached in child_process
|
||||
dev.unref();
|
||||
try {
|
||||
// start `now dev` detached in child_process
|
||||
dev.unref();
|
||||
|
||||
const result = await fetchWithRetry(`http://localhost:${port}`, 180);
|
||||
const response = await result;
|
||||
const result = await fetchWithRetry(`http://localhost:${port}`, 180);
|
||||
const response = await result;
|
||||
|
||||
validateResponseHeaders(t, response);
|
||||
validateResponseHeaders(t, response);
|
||||
|
||||
const body = await response.text();
|
||||
t.regex(body, /Vue.js \+ Node.js API/gm);
|
||||
} finally {
|
||||
dev.kill('SIGTERM');
|
||||
}
|
||||
});
|
||||
const body = await response.text();
|
||||
t.regex(body, /Vue.js \+ Node.js API/gm);
|
||||
} finally {
|
||||
dev.kill('SIGTERM');
|
||||
}
|
||||
});
|
||||
test('[now dev] 17-vuepress-node', async t => {
|
||||
const directory = fixture('17-vuepress-node');
|
||||
const { dev, port } = await testFixture(directory);
|
||||
|
||||
test('[now dev] 17-vuepress-node', async t => {
|
||||
const directory = fixture('17-vuepress-node');
|
||||
const { dev, port } = testFixture(directory);
|
||||
try {
|
||||
// start `now dev` detached in child_process
|
||||
dev.unref();
|
||||
|
||||
try {
|
||||
// start `now dev` detached in child_process
|
||||
dev.unref();
|
||||
const result = await fetchWithRetry(`http://localhost:${port}`, 180);
|
||||
const response = await result;
|
||||
|
||||
const result = await fetchWithRetry(`http://localhost:${port}`, 180);
|
||||
const response = await result;
|
||||
validateResponseHeaders(t, response);
|
||||
|
||||
validateResponseHeaders(t, response);
|
||||
|
||||
const body = await response.text();
|
||||
t.regex(body, /VuePress \+ Node.js API/gm);
|
||||
} finally {
|
||||
dev.kill('SIGTERM');
|
||||
}
|
||||
});
|
||||
const body = await response.text();
|
||||
t.regex(body, /VuePress \+ Node.js API/gm);
|
||||
} finally {
|
||||
dev.kill('SIGTERM');
|
||||
}
|
||||
});
|
||||
} else {
|
||||
console.log(
|
||||
'Skipping `10-vue-node` and `17-vuepress-node` test since it requires Node ^8.12.0 || >=9.7.0'
|
||||
);
|
||||
}
|
||||
|
||||
test('[now dev] double slashes redirect', async t => {
|
||||
const directory = fixture('01-node');
|
||||
const { dev, port } = testFixture(directory);
|
||||
const { dev, port } = await testFixture(directory);
|
||||
|
||||
try {
|
||||
// start `now dev` detached in child_process
|
||||
@@ -596,7 +620,7 @@ test(
|
||||
|
||||
test('[now dev] temporary directory listing', async t => {
|
||||
const directory = fixture('temporary-directory-listing');
|
||||
const { dev, port } = testFixture(directory);
|
||||
const { dev, port } = await testFixture(directory);
|
||||
|
||||
try {
|
||||
// start `now dev` detached in child_process
|
||||
@@ -629,7 +653,7 @@ test('[now dev] temporary directory listing', async t => {
|
||||
|
||||
test('[now dev] add a `package.json` to trigger `@now/static-build`', async t => {
|
||||
const directory = fixture('trigger-static-build');
|
||||
const { dev, port } = testFixture(directory);
|
||||
const { dev, port } = await testFixture(directory);
|
||||
|
||||
try {
|
||||
dev.unref();
|
||||
@@ -666,7 +690,7 @@ test('[now dev] add a `package.json` to trigger `@now/static-build`', async t =>
|
||||
|
||||
test('[now dev] no build matches warning', async t => {
|
||||
const directory = fixture('no-build-matches');
|
||||
const { dev } = testFixture(directory, {
|
||||
const { dev } = await testFixture(directory, {
|
||||
stdio: ['ignore', 'pipe', 'pipe']
|
||||
});
|
||||
|
||||
@@ -689,33 +713,39 @@ test('[now dev] no build matches warning', async t => {
|
||||
}
|
||||
});
|
||||
|
||||
test('[now dev] do not recursivly check the path', async t => {
|
||||
const directory = fixture('handle-filesystem-missing');
|
||||
const { dev, port } = testFixture(directory);
|
||||
if (satisfies(process.version, '^8.10.0 || ^10.13.0 || >=11.10.1')) {
|
||||
test('[now dev] do not recursivly check the path', async t => {
|
||||
const directory = fixture('handle-filesystem-missing');
|
||||
const { dev, port } = await testFixture(directory);
|
||||
|
||||
try {
|
||||
dev.unref();
|
||||
try {
|
||||
dev.unref();
|
||||
|
||||
{
|
||||
const response = await fetchWithRetry(`http://localhost:${port}`, 180);
|
||||
validateResponseHeaders(t, response);
|
||||
const body = await response.text();
|
||||
t.is(body.trim(), 'hello');
|
||||
{
|
||||
const response = await fetchWithRetry(`http://localhost:${port}`, 180);
|
||||
validateResponseHeaders(t, response);
|
||||
const body = await response.text();
|
||||
t.is(body.trim(), 'hello');
|
||||
}
|
||||
|
||||
{
|
||||
const response = await fetch(`http://localhost:${port}/favicon.txt`);
|
||||
validateResponseHeaders(t, response);
|
||||
t.is(response.status, 404);
|
||||
}
|
||||
} finally {
|
||||
dev.kill('SIGTERM');
|
||||
}
|
||||
|
||||
{
|
||||
const response = await fetch(`http://localhost:${port}/favicon.txt`);
|
||||
validateResponseHeaders(t, response);
|
||||
t.is(response.status, 404);
|
||||
}
|
||||
} finally {
|
||||
dev.kill('SIGTERM');
|
||||
}
|
||||
});
|
||||
});
|
||||
} else {
|
||||
console.log(
|
||||
'Skipping `do not recursivly check the path` test since it requires Node ^8.10.0 || ^10.13.0 || >=11.10.1'
|
||||
);
|
||||
}
|
||||
|
||||
test('[now dev] render warning for empty cwd dir', async t => {
|
||||
const directory = fixture('empty');
|
||||
const { dev, port } = testFixture(directory, {
|
||||
const { dev, port } = await testFixture(directory, {
|
||||
stdio: ['ignore', 'pipe', 'pipe']
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user