Skip to content

Commit 9075ba8

Browse files
author
DavertMik
committed
Merge branch '3.x' into feat/test-meta-remarks
2 parents b62dd35 + 6edc423 commit 9075ba8

File tree

17 files changed

+508
-187
lines changed

17 files changed

+508
-187
lines changed

.github/workflows/playwright.yml

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -15,40 +15,41 @@ env:
1515

1616
jobs:
1717
build:
18-
1918
runs-on: ubuntu-latest
2019

2120
strategy:
2221
matrix:
2322
node-version: [20.x]
2423

2524
steps:
26-
- uses: actions/checkout@v4
27-
- name: Use Node.js ${{ matrix.node-version }}
28-
uses: actions/setup-node@v4
29-
with:
30-
node-version: ${{ matrix.node-version }}
31-
- uses: shivammathur/setup-php@v2
32-
with:
33-
php-version: 7.4
34-
- name: npm install
35-
run: |
36-
npm i --force
37-
env:
38-
PUPPETEER_SKIP_CHROMIUM_DOWNLOAD: true
39-
- name: Install browsers and deps
40-
run: npx playwright install && npx playwright install-deps
41-
- name: start a server
42-
run: "php -S 127.0.0.1:8000 -t test/data/app &"
43-
- name: run chromium tests
44-
run: "./bin/codecept.js run -c test/acceptance/codecept.Playwright.js --grep @Playwright --debug"
45-
- name: run chromium with restart==browser tests
46-
run: "BROWSER_RESTART=browser ./bin/codecept.js run -c test/acceptance/codecept.Playwright.js --grep @Playwright --debug"
47-
- name: run chromium with restart==session tests
48-
run: "BROWSER_RESTART=session ./bin/codecept.js run -c test/acceptance/codecept.Playwright.js --grep @Playwright --debug"
49-
- name: run firefox tests
50-
run: "BROWSER=firefox node ./bin/codecept.js run -c test/acceptance/codecept.Playwright.js --grep @Playwright --debug"
51-
- name: run webkit tests
52-
run: "BROWSER=webkit node ./bin/codecept.js run -c test/acceptance/codecept.Playwright.js --grep @Playwright --debug"
53-
- name: run chromium unit tests
54-
run: ./node_modules/.bin/mocha test/helper/Playwright_test.js --timeout 5000
25+
- uses: actions/checkout@v4
26+
- name: Use Node.js ${{ matrix.node-version }}
27+
uses: actions/setup-node@v4
28+
with:
29+
node-version: ${{ matrix.node-version }}
30+
- uses: shivammathur/setup-php@v2
31+
with:
32+
php-version: 7.4
33+
- name: npm install
34+
run: |
35+
npm i --force
36+
env:
37+
PUPPETEER_SKIP_CHROMIUM_DOWNLOAD: true
38+
- name: Install browsers and deps
39+
run: npx playwright install && npx playwright install-deps
40+
- name: check
41+
run: './bin/codecept.js check -c test/acceptance/codecept.Playwright.js'
42+
- name: start a server
43+
run: 'php -S 127.0.0.1:8000 -t test/data/app &'
44+
- name: run chromium tests
45+
run: './bin/codecept.js run -c test/acceptance/codecept.Playwright.js --grep @Playwright --debug'
46+
- name: run chromium with restart==browser tests
47+
run: 'BROWSER_RESTART=browser ./bin/codecept.js run -c test/acceptance/codecept.Playwright.js --grep @Playwright --debug'
48+
- name: run chromium with restart==session tests
49+
run: 'BROWSER_RESTART=session ./bin/codecept.js run -c test/acceptance/codecept.Playwright.js --grep @Playwright --debug'
50+
- name: run firefox tests
51+
run: 'BROWSER=firefox node ./bin/codecept.js run -c test/acceptance/codecept.Playwright.js --grep @Playwright --debug'
52+
- name: run webkit tests
53+
run: 'BROWSER=webkit node ./bin/codecept.js run -c test/acceptance/codecept.Playwright.js --grep @Playwright --debug'
54+
- name: run chromium unit tests
55+
run: ./node_modules/.bin/mocha test/helper/Playwright_test.js --timeout 5000

.github/workflows/test.yml

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,42 @@ on:
99
- '**'
1010

1111
jobs:
12-
build:
12+
unit-tests:
13+
name: Unit tests
14+
runs-on: ubuntu-22.04
15+
16+
strategy:
17+
matrix:
18+
node-version: [20.x, 22.x]
19+
20+
steps:
21+
- uses: actions/checkout@v4
22+
- name: Use Node.js ${{ matrix.node-version }}
23+
uses: actions/setup-node@v4
24+
with:
25+
node-version: ${{ matrix.node-version }}
26+
- run: npm i
27+
env:
28+
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: true
29+
PUPPETEER_SKIP_CHROMIUM_DOWNLOAD: true
30+
- run: npm run test:unit
1331

32+
runner-tests:
33+
name: Runner tests
1434
runs-on: ubuntu-22.04
1535

1636
strategy:
1737
matrix:
18-
node-version: [20.x]
38+
node-version: [20.x, 22.x]
1939

2040
steps:
21-
- uses: actions/checkout@v4
22-
- name: Use Node.js ${{ matrix.node-version }}
23-
uses: actions/setup-node@v4
24-
with:
25-
node-version: ${{ matrix.node-version }}
26-
- run: npm i --force
27-
env:
28-
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: true
29-
PUPPETEER_SKIP_CHROMIUM_DOWNLOAD: true
30-
- uses: nick-fields/retry@v3
31-
with:
32-
timeout_minutes: 6
33-
max_attempts: 3
34-
retry_on: error
35-
command: npm test
41+
- uses: actions/checkout@v4
42+
- name: Use Node.js ${{ matrix.node-version }}
43+
uses: actions/setup-node@v4
44+
with:
45+
node-version: ${{ matrix.node-version }}
46+
- run: npm i
47+
env:
48+
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: true
49+
PUPPETEER_SKIP_CHROMIUM_DOWNLOAD: true
50+
- run: npm run test:runner

.github/workflows/webdriver.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ jobs:
3838
PUPPETEER_SKIP_CHROMIUM_DOWNLOAD: true
3939
- name: start a server
4040
run: 'php -S 127.0.0.1:8000 -t test/data/app &'
41+
- name: Check CodeceptJS can be started
42+
run: './bin/codecept.js check -c test/acceptance/codecept.WebDriver.js'
4143
- name: run unit tests
4244
run: ./node_modules/.bin/mocha test/helper/WebDriver_test.js --exit
4345
- name: run tests

bin/codecept.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@ program
5858
.description('Creates dummy config in current dir or [path]')
5959
.action(errorHandler(require('../lib/command/init')))
6060

61+
program
62+
.command('check')
63+
.option(commandFlags.config.flag, commandFlags.config.description)
64+
.description('Checks configuration and environment before running tests')
65+
.option('-t, --timeout [ms]', 'timeout for checks in ms, 20000 by default')
66+
.action(errorHandler(require('../lib/command/check')))
67+
6168
program
6269
.command('migrate [path]')
6370
.description('Migrate json config to js config in current dir or [path]')

lib/codecept.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ class Codecept {
111111
runHook(require('./listener/globalTimeout'))
112112
runHook(require('./listener/globalRetry'))
113113
runHook(require('./listener/exit'))
114+
runHook(require('./listener/emptyRun'))
114115

115116
// custom hooks (previous iteration of plugins)
116117
this.config.hooks.forEach(hook => runHook(hook))

lib/command/check.js

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

lib/command/definitions.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,8 @@ module.exports = function (genPath, options) {
185185
definitionsFileContent += `\n${translationAliases.join('\n')}`
186186
}
187187

188+
if (options.dryRun) return
189+
188190
fs.writeFileSync(path.join(targetFolderPath, 'steps.d.ts'), definitionsFileContent)
189191
output.print('TypeScript Definitions provide autocompletion in Visual Studio Code and other IDEs')
190192
output.print('Definitions were generated in steps.d.ts')

0 commit comments

Comments
 (0)