Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: move CRA test app install from github action to test setup #913

Merged
merged 8 commits into from
May 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
# GitHub secrets are not available when running on PR from forks
Expand Down
29 changes: 28 additions & 1 deletion tests/cra.test.js
Original file line number Diff line number Diff line change
@@ -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')
Expand All @@ -10,6 +10,22 @@ const sitePath = path.join(__dirname, 'site-cra')
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'], { shell: true })
if (status !== 0) {
const message = `Failed installing Create React App project dependencies from path '${sitePath}'`
console.error(message)
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')
ps = await spawn(cliPath, ['dev', '-p', randomPort()], {
cwd: sitePath,
Expand All @@ -31,6 +47,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)
}
})
})
})

Expand Down