Skip to content

Commit 4fa6023

Browse files
author
DavertMik
committed
added file
1 parent fa7b767 commit 4fa6023

File tree

2 files changed

+175
-2
lines changed

2 files changed

+175
-2
lines changed

lib/command/check.js

Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
const { getConfig, getTestRoot } = require('./utils')
2+
const Codecept = require('../codecept')
3+
const output = require('../output')
4+
const standardActingHelpers = require('../plugin/standardActingHelpers')
5+
const store = require('../store')
6+
const container = require('../container')
7+
const figures = require('figures')
8+
const chalk = require('chalk')
9+
const { createTest } = require('../mocha/test')
10+
const { getMachineInfo } = require('./info')
11+
const definitions = require('./definitions')
12+
13+
module.exports = async function (test, options) {
14+
if (options.grep) process.env.grep = options.grep
15+
const configFile = options.config
16+
17+
setTimeout(() => {
18+
output.error("Something went wrong. Checks didn't pass and timed out. Please check your config and helpers.")
19+
process.exit(1)
20+
}, options.timeout || 50000)
21+
22+
const checks = {
23+
config: false,
24+
container: false,
25+
pageObjects: false,
26+
helpers: false,
27+
setup: false,
28+
tests: false,
29+
def: false,
30+
}
31+
32+
const testRoot = getTestRoot(configFile)
33+
let config = getConfig(configFile)
34+
35+
try {
36+
config = getConfig(configFile)
37+
checks['config'] = true
38+
} catch (err) {
39+
checks['config'] = err
40+
}
41+
42+
printCheck('config', checks['config'], config.name)
43+
44+
let codecept
45+
try {
46+
codecept = new Codecept(config, options)
47+
codecept.init(testRoot)
48+
await container.started()
49+
checks.container = true
50+
} catch (err) {
51+
checks.container = err
52+
}
53+
54+
printCheck('container', checks['container'])
55+
56+
if (codecept && options.bootstrap) {
57+
try {
58+
await codecept.bootstrap()
59+
checks.bootstrap = true
60+
} catch (err) {
61+
checks.bootstrap = err
62+
}
63+
printCheck('bootstrap', checks['bootstrap'])
64+
}
65+
66+
let numTests = 0
67+
if (codecept) {
68+
try {
69+
codecept.loadTests()
70+
const mocha = container.mocha()
71+
mocha.files = codecept.testFiles
72+
mocha.loadFiles()
73+
mocha.suite.suites.forEach(suite => {
74+
numTests += suite.tests.length
75+
})
76+
if (numTests > 0) {
77+
checks.tests = true
78+
} else {
79+
throw new Error('No tests found')
80+
}
81+
} catch (err) {
82+
checks.tests = err
83+
}
84+
}
85+
86+
printCheck('tests', checks['tests'], `Total: ${numTests} tests`)
87+
88+
store.dryRun = true
89+
90+
const helpers = container.helpers()
91+
92+
try {
93+
if (!Object.keys(helpers).length) throw new Error('No helpers found')
94+
// load helpers
95+
for (const helper of Object.values(helpers)) {
96+
helper._init()
97+
}
98+
checks.helpers = true
99+
} catch (err) {
100+
checks.helpers = err
101+
}
102+
103+
printCheck('helpers', checks['helpers'], `${Object.keys(helpers).join(', ')}`)
104+
105+
const pageObjects = container.support()
106+
107+
try {
108+
if (Object.keys(pageObjects).length) {
109+
for (const pageObject of Object.values(pageObjects)) {
110+
pageObject.name
111+
}
112+
}
113+
checks.pageObjects = true
114+
} catch (err) {
115+
checks.pageObjects = err
116+
}
117+
printCheck('page objects', checks['pageObjects'], `Total: ${Object.keys(pageObjects).length} support objects`)
118+
119+
if (Object.keys(helpers).length) {
120+
const suite = container.mocha().suite
121+
const test = createTest('test', () => {})
122+
try {
123+
for (const helper of Object.values(helpers)) {
124+
await helper._beforeSuite(suite)
125+
await helper._before(test)
126+
await helper._passed(test)
127+
await helper._after(test)
128+
await helper._finishTest(suite)
129+
await helper._afterSuite(suite)
130+
}
131+
checks.setup = true
132+
} catch (err) {
133+
checks.setup = err
134+
}
135+
}
136+
137+
printCheck('Helpers Hooks', checks['setup'], standardActingHelpers.some(h => Object.keys(helpers).includes(h)) ? 'Initializing and closing browser' : '')
138+
139+
try {
140+
definitions(configFile, { dryRun: true })
141+
checks.def = true
142+
} catch (err) {
143+
checks.def = err
144+
}
145+
146+
printCheck('TypeScript Definitions', checks['def'])
147+
148+
output.print('')
149+
150+
if (!Object.values(checks).every(check => check === true)) {
151+
output.error("Something went wrong. Checks didn't pass.")
152+
output.print()
153+
getMachineInfo()
154+
process.exit(1)
155+
}
156+
157+
output.print(output.styles.success('All checks passed'.toUpperCase()), 'Ready to run your tests 🚀')
158+
process.exit(0)
159+
}
160+
161+
function printCheck(name, value, comment = '') {
162+
let status = ''
163+
if (value == true) {
164+
status += chalk.bold.green(figures.tick)
165+
} else {
166+
status += chalk.bold.red(figures.cross)
167+
}
168+
169+
if (value instanceof Error) {
170+
comment = `${comment} ${chalk.red.italic(value.message)}`.trim()
171+
}
172+
173+
output.print(status, name.toUpperCase(), chalk.dim(comment))
174+
}

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "codeceptjs",
3-
"version": "3.7.0-beta.1",
3+
"version": "3.6.10",
44
"description": "Supercharged End 2 End Testing Framework for NodeJS",
55
"keywords": [
66
"acceptance",
@@ -93,7 +93,6 @@
9393
"fn-args": "4.0.0",
9494
"fs-extra": "11.2.0",
9595
"glob": "^11.0.0",
96-
"fuse.js": "^7.0.0",
9796
"html-minifier-terser": "7.2.0",
9897
"inquirer": "6.5.2",
9998
"invisi-data": "^1.0.0",

0 commit comments

Comments
 (0)