-
-
Notifications
You must be signed in to change notification settings - Fork 753
Check command #4727
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Check command #4727
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
9aa62fe
3.7.0-beta.1
b88077e
Merge branch '3.x' of github.com:codeceptjs/CodeceptJS into 3.x
fa7b767
added check command
4fa6023
added file
2e33858
added debug for container, fixed check command
400059c
added support for custom config -c, added checks to workflows
06b39f3
fixed check command
5c67b95
added await for check
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,173 @@ | ||
| const { getConfig, getTestRoot } = require('./utils') | ||
| const Codecept = require('../codecept') | ||
| const output = require('../output') | ||
| const standardActingHelpers = require('../plugin/standardActingHelpers') | ||
| const store = require('../store') | ||
| const container = require('../container') | ||
| const figures = require('figures') | ||
| const chalk = require('chalk') | ||
| const { createTest } = require('../mocha/test') | ||
| const { getMachineInfo } = require('./info') | ||
| const definitions = require('./definitions') | ||
|
|
||
| module.exports = async function (options) { | ||
| const configFile = options.config | ||
|
|
||
| setTimeout(() => { | ||
| output.error("Something went wrong. Checks didn't pass and timed out. Please check your config and helpers.") | ||
| process.exit(1) | ||
| }, options.timeout || 50000) | ||
|
|
||
| const checks = { | ||
| config: false, | ||
| container: false, | ||
| pageObjects: false, | ||
| helpers: false, | ||
| setup: false, | ||
| tests: false, | ||
| def: false, | ||
| } | ||
|
|
||
| const testRoot = getTestRoot(configFile) | ||
| let config = getConfig(configFile) | ||
|
|
||
| try { | ||
| config = getConfig(configFile) | ||
| checks['config'] = true | ||
| } catch (err) { | ||
| checks['config'] = err | ||
| } | ||
|
|
||
| printCheck('config', checks['config'], config.name) | ||
|
|
||
| let codecept | ||
| try { | ||
| codecept = new Codecept(config, options) | ||
| codecept.init(testRoot) | ||
| await container.started() | ||
| checks.container = true | ||
| } catch (err) { | ||
| checks.container = err | ||
| } | ||
|
|
||
| printCheck('container', checks['container']) | ||
|
|
||
| if (codecept) { | ||
| try { | ||
| if (options.bootstrap) await codecept.bootstrap() | ||
| checks.bootstrap = true | ||
| } catch (err) { | ||
| checks.bootstrap = err | ||
| } | ||
| printCheck('bootstrap', checks['bootstrap'], options.bootstrap ? 'Bootstrap was executed' : 'No bootstrap command') | ||
| } | ||
|
|
||
| let numTests = 0 | ||
| if (codecept) { | ||
| try { | ||
| codecept.loadTests() | ||
| const mocha = container.mocha() | ||
| mocha.files = codecept.testFiles | ||
| mocha.loadFiles() | ||
| mocha.suite.suites.forEach(suite => { | ||
| numTests += suite.tests.length | ||
| }) | ||
| if (numTests > 0) { | ||
| checks.tests = true | ||
| } else { | ||
| throw new Error('No tests found') | ||
| } | ||
| } catch (err) { | ||
| checks.tests = err | ||
| } | ||
| } | ||
|
|
||
| printCheck('tests', checks['tests'], `Total: ${numTests} tests`) | ||
|
|
||
| store.dryRun = true | ||
|
|
||
| const helpers = container.helpers() | ||
|
|
||
| try { | ||
| if (!Object.keys(helpers).length) throw new Error('No helpers found') | ||
| // load helpers | ||
| for (const helper of Object.values(helpers)) { | ||
| if (helper._init) helper._init() | ||
| } | ||
| checks.helpers = true | ||
| } catch (err) { | ||
| checks.helpers = err | ||
| } | ||
|
|
||
| printCheck('helpers', checks['helpers'], `${Object.keys(helpers).join(', ')}`) | ||
|
|
||
| const pageObjects = container.support() | ||
|
|
||
| try { | ||
| if (Object.keys(pageObjects).length) { | ||
| for (const pageObject of Object.values(pageObjects)) { | ||
| pageObject.name | ||
| } | ||
| } | ||
| checks.pageObjects = true | ||
| } catch (err) { | ||
| checks.pageObjects = err | ||
| } | ||
| printCheck('page objects', checks['pageObjects'], `Total: ${Object.keys(pageObjects).length} support objects`) | ||
|
|
||
| if (Object.keys(helpers).length) { | ||
| const suite = container.mocha().suite | ||
| const test = createTest('test', () => {}) | ||
| try { | ||
| for (const helper of Object.values(helpers)) { | ||
| if (helper._beforeSuite) await helper._beforeSuite(suite) | ||
| if (helper._before) await helper._before(test) | ||
| if (helper._passed) await helper._passed(test) | ||
| if (helper._after) await helper._after(test) | ||
| if (helper._finishTest) await helper._finishTest(suite) | ||
| if (helper._afterSuite) await helper._afterSuite(suite) | ||
| } | ||
| checks.setup = true | ||
| } catch (err) { | ||
| checks.setup = err | ||
| } | ||
| } | ||
|
|
||
| printCheck('Helpers Before/After', checks['setup'], standardActingHelpers.some(h => Object.keys(helpers).includes(h)) ? 'Initializing and closing browser' : '') | ||
|
|
||
| try { | ||
| definitions(configFile, { dryRun: true }) | ||
| checks.def = true | ||
| } catch (err) { | ||
| checks.def = err | ||
| } | ||
|
|
||
| printCheck('TypeScript Definitions', checks['def']) | ||
|
|
||
| output.print('') | ||
|
|
||
| if (!Object.values(checks).every(check => check === true)) { | ||
| output.error("Something went wrong. Checks didn't pass.") | ||
| output.print() | ||
| await getMachineInfo() | ||
| process.exit(1) | ||
| } | ||
|
|
||
| output.print(output.styles.success('All checks passed'.toUpperCase()), 'Ready to run your tests 🚀') | ||
| process.exit(0) | ||
| } | ||
|
|
||
| function printCheck(name, value, comment = '') { | ||
| let status = '' | ||
| if (value == true) { | ||
| status += chalk.bold.green(figures.tick) | ||
| } else { | ||
| status += chalk.bold.red(figures.cross) | ||
| } | ||
|
|
||
| if (value instanceof Error) { | ||
| comment = `${comment} ${chalk.red.italic(value.message)}`.trim() | ||
| } | ||
|
|
||
| output.print(status, name.toUpperCase(), chalk.dim(comment)) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about
config namehere?