Files
cypress/scripts/run-ct-examples.js
Barthélémy Ledoux 64cfa06c1e docs: make clean examples of vue component testing (#15796)
* remove all existsing examples

* create vue cli project

* add nuxt app example

* test: fix some vite tests

* docs: add tests to nuxt example

* add test script to nuxt example

* docs: add cy plugin nuxt

* fix: avoid creating support files

* test: add tests for vue cli

* test: fix CLI example

* fix the test

* test: make all vue examples be tested in ci

* ci: use minimist

* ci: fix cwd

* adjust the model for .env files making it easy to comment/uncomment the examples opened.

* protect empty module

* fix nuxt tests

* fix test protection

* more clear fix
2021-04-08 10:00:05 +10:00

64 lines
1.6 KiB
JavaScript

/* eslint-disable no-console */
const execa = require('execa')
const { chdir } = require('process')
const path = require('path')
const fs = require('fs')
const minimist = require('minimist')
const args = minimist(process.argv.slice(2))
const filePath = path.resolve(process.cwd(), args.examplesList)
const PROJECTS_FOR_CI = fs.readFileSync(filePath, { encoding: 'utf8' })
.split('\n')
.filter((a) => !/^\#/.test(a))
const testResultsDestination = path.resolve(process.cwd(), 'test_results')
const runTests = async (dir) => {
try {
chdir(dir)
if (dir !== __dirname) {
console.log(`Running yarn install in project ${dir}`)
await execa('yarn', ['install', '--frozen-lockfile'], { stdout: 'inherit' })
}
console.log(`Running yarn test in project ${dir}`)
await execa('yarn', [
'test',
'--reporter',
'cypress-circleci-reporter',
'--reporter-options',
`resultsDir=${testResultsDestination}`,
], { stdout: 'inherit' })
} catch (e) {
if (e.stdout) {
console.error(e.stdout)
}
const exitCode = e.exitCode ? e.exitCode : 1
console.error(`Tests failed with exit code ${exitCode}`)
process.exit(exitCode)
}
}
const main = async () => {
const NODE_INDEX = process.env.CIRCLE_NODE_INDEX || 0
if (NODE_INDEX > PROJECTS_FOR_CI.length - 1) {
return
}
const projectDir = `${process.cwd()}${PROJECTS_FOR_CI[NODE_INDEX]}`
console.log(`Running tests in ${projectDir}`)
await runTests(projectDir)
}
// execute main function if called from command line
if (require.main === module) {
main()
}