From ee7922dc237afd7ff3573bca2eb7215f1f03fb6f Mon Sep 17 00:00:00 2001 From: erezrokah Date: Wed, 20 May 2020 13:35:54 +0300 Subject: [PATCH 1/7] test: move cra test app install from github action to test setup --- .github/workflows/main.yml | 1 - tests/cra.test.js | 4 +++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index babcd2566ef..be001a13f4b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -23,7 +23,6 @@ jobs: with: node-version: ${{ matrix.node-version }} - run: npm ci - - run: npm ci --prefix tests/site-cra - run: npm test env: NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }} diff --git a/tests/cra.test.js b/tests/cra.test.js index 9b2ea7fafd4..3d5abc3984e 100644 --- a/tests/cra.test.js +++ b/tests/cra.test.js @@ -1,5 +1,5 @@ const path = require('path') -const { spawn } = require('child_process') +const { spawn, spawnSync } = require('child_process') const url = require('url') const test = require('ava') const fetch = require('node-fetch') @@ -10,6 +10,8 @@ const sitePath = path.join(__dirname, 'site-cra') let ps, host, port test.before(async t => { + console.log('Installing Create React App project dependencies') + spawnSync('npm', ['ci'], { cwd: sitePath }) console.log('Running Netlify Dev server in Create React App project') ps = await spawn(cliPath, ['dev', '-p', randomPort()], { cwd: sitePath, From 567a215e47c0a63658962a7df5c8b9eb4d7b9b9c Mon Sep 17 00:00:00 2001 From: erezrokah Date: Wed, 20 May 2020 14:17:46 +0300 Subject: [PATCH 2/7] chore: improve error logs --- tests/cra.test.js | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/tests/cra.test.js b/tests/cra.test.js index 3d5abc3984e..1e9e018279a 100644 --- a/tests/cra.test.js +++ b/tests/cra.test.js @@ -11,7 +11,14 @@ let ps, host, port test.before(async t => { console.log('Installing Create React App project dependencies') - spawnSync('npm', ['ci'], { cwd: sitePath }) + const { stdout, stderr, status } = spawnSync('npm', ['ci'], { cwd: sitePath }) + if (status !== 0) { + const message = 'Failed installing Create React App project dependencies' + console.error(message) + console.log('stdout:', stdout) + console.log('stderr:', stderr) + throw new Error(message) + } console.log('Running Netlify Dev server in Create React App project') ps = await spawn(cliPath, ['dev', '-p', randomPort()], { cwd: sitePath, @@ -34,6 +41,17 @@ test.before(async t => { resolve() } }) + + let error = '' + ps.stderr.on('data' ,(data) => { + error = error + data.toString() + }) + ps.on('close', (code) => { + if (code !== 0) { + console.error(error) + reject(error) + } + }) }) }) From 42dee9b96175b9cdb7773b3e3de680da8799f15f Mon Sep 17 00:00:00 2001 From: erezrokah Date: Wed, 20 May 2020 15:13:55 +0300 Subject: [PATCH 3/7] chore: improve error logs --- tests/cra.test.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/cra.test.js b/tests/cra.test.js index 1e9e018279a..2e0d1a178bb 100644 --- a/tests/cra.test.js +++ b/tests/cra.test.js @@ -13,10 +13,10 @@ test.before(async t => { console.log('Installing Create React App project dependencies') const { stdout, stderr, status } = spawnSync('npm', ['ci'], { cwd: sitePath }) if (status !== 0) { - const message = 'Failed installing Create React App project dependencies' + const message = `Failed installing Create React App project dependencies from path '${sitePath}'` console.error(message) - console.log('stdout:', stdout) - console.log('stderr:', stderr) + console.log('stdout:', stdout.toString()) + console.log('stderr:', stderr.toString()) throw new Error(message) } console.log('Running Netlify Dev server in Create React App project') From 22e3616e1ea2d69cce12d219d428582292e1127e Mon Sep 17 00:00:00 2001 From: erezrokah Date: Wed, 20 May 2020 15:39:36 +0300 Subject: [PATCH 4/7] chore: improve error logs --- tests/cra.test.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/tests/cra.test.js b/tests/cra.test.js index 2e0d1a178bb..0117eeb643b 100644 --- a/tests/cra.test.js +++ b/tests/cra.test.js @@ -11,12 +11,19 @@ let ps, host, port test.before(async t => { console.log('Installing Create React App project dependencies') - const { stdout, stderr, status } = spawnSync('npm', ['ci'], { cwd: sitePath }) + const { stdout, stderr, status, error } = spawnSync('npm', ['ci'], { cwd: sitePath }) if (status !== 0) { const message = `Failed installing Create React App project dependencies from path '${sitePath}'` console.error(message) - console.log('stdout:', stdout.toString()) - console.log('stderr:', stderr.toString()) + if (error) { + console.log('error:', error.message) + } + if (stdout) { + console.log('stdout:', stdout.toString()) + } + if (stderr) { + console.log('stderr:', stderr.toString()) + } throw new Error(message) } console.log('Running Netlify Dev server in Create React App project') From c8695c9a512a251e6c9e867c3ca34461e94661cb Mon Sep 17 00:00:00 2001 From: erezrokah Date: Wed, 20 May 2020 15:46:31 +0300 Subject: [PATCH 5/7] ci: use --prefix flag instead of cwd --- tests/cra.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/cra.test.js b/tests/cra.test.js index 0117eeb643b..8d2e536b744 100644 --- a/tests/cra.test.js +++ b/tests/cra.test.js @@ -11,7 +11,7 @@ let ps, host, port test.before(async t => { console.log('Installing Create React App project dependencies') - const { stdout, stderr, status, error } = spawnSync('npm', ['ci'], { cwd: sitePath }) + const { stdout, stderr, status, error } = spawnSync('npm', ['ci', '--prefix', 'tests/site-cra']) if (status !== 0) { const message = `Failed installing Create React App project dependencies from path '${sitePath}'` console.error(message) From ecac8a5a6ea8d1ebf81bbf8e6916277e50067c71 Mon Sep 17 00:00:00 2001 From: erezrokah Date: Wed, 20 May 2020 15:59:13 +0300 Subject: [PATCH 6/7] ci: add shell: true --- tests/cra.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/cra.test.js b/tests/cra.test.js index 8d2e536b744..31c0e92ab4d 100644 --- a/tests/cra.test.js +++ b/tests/cra.test.js @@ -11,7 +11,7 @@ let ps, host, port test.before(async t => { console.log('Installing Create React App project dependencies') - const { stdout, stderr, status, error } = spawnSync('npm', ['ci', '--prefix', 'tests/site-cra']) + const { stdout, stderr, status, error } = spawnSync('npm', ['ci', '--prefix', 'tests/site-cra'], { shell: true }) if (status !== 0) { const message = `Failed installing Create React App project dependencies from path '${sitePath}'` console.error(message) From 6e9c53900aa11a16c899107fa3ede290163e62a0 Mon Sep 17 00:00:00 2001 From: Raees Iqbal Date: Wed, 20 May 2020 23:40:41 -0700 Subject: [PATCH 7/7] Update cra.test.js --- tests/cra.test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/cra.test.js b/tests/cra.test.js index c2c1add0784..56be0335f61 100644 --- a/tests/cra.test.js +++ b/tests/cra.test.js @@ -49,10 +49,10 @@ test.before(async t => { }) let error = '' - ps.stderr.on('data' ,(data) => { + ps.stderr.on('data', data => { error = error + data.toString() }) - ps.on('close', (code) => { + ps.on('close', code => { if (code !== 0) { console.error(error) reject(error)