forked from cypress-io/cypress
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun-tests.js
More file actions
61 lines (50 loc) · 1.51 KB
/
run-tests.js
File metadata and controls
61 lines (50 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
const execa = require('execa')
const { chdir } = require('process')
const path = require('path')
const testResultsDestination = path.resolve(__dirname, 'test_results')
const REACT_PROJECTS_FOR_CI = [
'', // root project
'/examples/nextjs',
'/examples/react-scripts',
'/examples/webpack-file',
'/examples/react-scripts-folder',
'/examples/using-babel-typescript',
'/examples/webpack-options',
// '/examples/rollup',
'/examples/sass-and-ts',
]
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
// initial working directory is npm/react
const projectDir = `${__dirname}${REACT_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()
}