test(e2e): add dev script which uses interactive cypress
This commit is contained in:
committed by
Benedikt Rötsch
parent
012492cf05
commit
3a6886e4f8
@@ -13,6 +13,7 @@
|
|||||||
"pretest": "npm run lint",
|
"pretest": "npm run lint",
|
||||||
"test": "npm run test:unit && npm run test:integration && npm run test:e2e",
|
"test": "npm run test:unit && npm run test:integration && npm run test:e2e",
|
||||||
"test:e2e": "node test/run-e2e-test.js",
|
"test:e2e": "node test/run-e2e-test.js",
|
||||||
|
"test:e2e:dev": "node test/run-e2e-test.js --dev",
|
||||||
"test:integration": "jest test/integration",
|
"test:integration": "jest test/integration",
|
||||||
"test:integration:watch": "jest test/integration --watch",
|
"test:integration:watch": "jest test/integration --watch",
|
||||||
"test:unit": "jest test/unit",
|
"test:unit": "jest test/unit",
|
||||||
@@ -44,6 +45,7 @@
|
|||||||
"eslint-plugin-standard": "^2.0.1",
|
"eslint-plugin-standard": "^2.0.1",
|
||||||
"jest": "^21.2.1",
|
"jest": "^21.2.1",
|
||||||
"nodemon": "^1.12.1",
|
"nodemon": "^1.12.1",
|
||||||
"supertest": "^3.0.0"
|
"supertest": "^3.0.0",
|
||||||
|
"yargs": "^10.0.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
8
test/e2e-variables.env
Normal file
8
test/e2e-variables.env
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
NODE_ENV=development
|
||||||
|
CONTENTFUL_SPACE_ID=qz0n5cdakyl9
|
||||||
|
CONTENTFUL_DELIVERY_TOKEN=580d5944194846b690dd89b630a1cb98a0eef6a19b860ef71efc37ee8076ddb8
|
||||||
|
CONTENTFUL_PREVIEW_TOKEN=e8fc39d9661c7468d0285a7ff949f7a23539dd2e686fcb7bd84dc01b392d698b
|
||||||
|
CONTENTFUL_QA_SPACE_ID=jnzexv31feqf
|
||||||
|
CONTENTFUL_QA_DELIVERY_TOKEN=7c1c321a528a25c351c1ac5f53e6ddc6bcce0712ecebec60817f53b35dd3c42b
|
||||||
|
CONTENTFUL_QA_PREVIEW_TOKEN=4310226db935f0e9b6b34fb9ce6611e2061abe1aab5297fa25bd52af5caa531a
|
||||||
|
PORT=3007
|
||||||
@@ -1,38 +1,60 @@
|
|||||||
const http = require('http')
|
const http = require('http')
|
||||||
const { resolve } = require('path')
|
const { resolve } = require('path')
|
||||||
const execa = require('execa')
|
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 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)
|
app.set('port', TEST_PORT)
|
||||||
|
|
||||||
const server = http.createServer(app)
|
const server = http.createServer(app)
|
||||||
|
|
||||||
const { CONTENTFUL_SPACE_ID, CONTENTFUL_DELIVERY_TOKEN, CONTENTFUL_PREVIEW_TOKEN } = process.env
|
|
||||||
|
|
||||||
server.on('error', console.error)
|
server.on('error', console.error)
|
||||||
server.listen(TEST_PORT, function () {
|
server.listen(TEST_PORT, function () {
|
||||||
|
console.log(`Testserver listening at port ${TEST_PORT}`)
|
||||||
|
|
||||||
const cypressBin = resolve(__dirname, 'e2e', 'node_modules', '.bin', 'cypress')
|
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',
|
'run',
|
||||||
!process.env.CI ? '--headed' : null,
|
!process.env.CI ? '--headed' : null
|
||||||
|
]
|
||||||
|
if (argv.dev) {
|
||||||
|
command = [
|
||||||
|
'open'
|
||||||
|
]
|
||||||
|
}
|
||||||
|
execa(cypressBin, [
|
||||||
|
...command,
|
||||||
'--env',
|
'--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))
|
].filter(Boolean))
|
||||||
.then((result) => {
|
.then((result) => {
|
||||||
console.log('✔ e2e test succeeded:')
|
console.log('✔ e2e test succeeded:')
|
||||||
console.log(result.cmd)
|
|
||||||
console.log(result.stdout)
|
console.log(result.stdout)
|
||||||
server.close()
|
server.close()
|
||||||
process.exit(0)
|
process.exit(0)
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
console.log(`✖ e2e test failed with status code ${error.code}:`)
|
console.log(`✖ e2e test failed with status code ${error.code}:`)
|
||||||
console.error(error.cmd)
|
|
||||||
console.error(error.stdout)
|
console.error(error.stdout)
|
||||||
console.error(error.stderr)
|
console.error(error.stderr)
|
||||||
server.close()
|
server.close()
|
||||||
|
|||||||
Reference in New Issue
Block a user