test(e2e): add dev script which uses interactive cypress

This commit is contained in:
Benedikt Rötsch
2017-12-28 15:09:10 +01:00
committed by Benedikt Rötsch
parent 012492cf05
commit 3a6886e4f8
3 changed files with 42 additions and 10 deletions

View File

@@ -1,38 +1,60 @@
const http = require('http')
const { resolve } = require('path')
const execa = require('execa')
const argv = require('yargs').argv
require('dotenv').config({ path: 'variables.env' })
require('dotenv').config({ path: resolve(__dirname, 'e2e-variables.env') })
const app = require('../app')
const TEST_PORT = 3007
const {
CONTENTFUL_SPACE_ID, CONTENTFUL_DELIVERY_TOKEN, CONTENTFUL_PREVIEW_TOKEN,
CONTENTFUL_QA_SPACE_ID, CONTENTFUL_QA_DELIVERY_TOKEN, CONTENTFUL_QA_PREVIEW_TOKEN,
PORT
} = process.env
const TEST_PORT = parseInt(PORT)
app.set('port', TEST_PORT)
const server = http.createServer(app)
const { CONTENTFUL_SPACE_ID, CONTENTFUL_DELIVERY_TOKEN, CONTENTFUL_PREVIEW_TOKEN } = process.env
server.on('error', console.error)
server.listen(TEST_PORT, function () {
console.log(`Testserver listening at port ${TEST_PORT}`)
const cypressBin = resolve(__dirname, 'e2e', 'node_modules', '.bin', 'cypress')
execa(cypressBin, [
const env = [
`LANGUAGE=nodejs`,
`CONTENTFUL_SPACE_ID=${CONTENTFUL_SPACE_ID}`,
`CONTENTFUL_DELIVERY_TOKEN=${CONTENTFUL_DELIVERY_TOKEN}`,
`CONTENTFUL_PREVIEW_TOKEN=${CONTENTFUL_PREVIEW_TOKEN}`,
`CONTENTFUL_QA_SPACE_ID=${CONTENTFUL_QA_SPACE_ID}`,
`CONTENTFUL_QA_DELIVERY_TOKEN=${CONTENTFUL_QA_DELIVERY_TOKEN}`,
`CONTENTFUL_QA_PREVIEW_TOKEN=${CONTENTFUL_QA_PREVIEW_TOKEN}`
]
let command = [
'run',
!process.env.CI ? '--headed' : null,
!process.env.CI ? '--headed' : null
]
if (argv.dev) {
command = [
'open'
]
}
execa(cypressBin, [
...command,
'--env',
`LANGUAGE=nodejs,CONTENTFUL_SPACE_ID=${CONTENTFUL_SPACE_ID},CONTENTFUL_DELIVERY_TOKEN=${CONTENTFUL_DELIVERY_TOKEN},CONTENTFUL_PREVIEW_TOKEN=${CONTENTFUL_PREVIEW_TOKEN}`
env.join()
].filter(Boolean))
.then((result) => {
console.log('✔ e2e test succeeded:')
console.log(result.cmd)
console.log(result.stdout)
server.close()
process.exit(0)
})
.catch((error) => {
console.log(`✖ e2e test failed with status code ${error.code}:`)
console.error(error.cmd)
console.error(error.stdout)
console.error(error.stderr)
server.close()