codeceptjs 4.1.0-beta.1-esm-mocha → 4.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -63,6 +63,25 @@ Make sure `Playwright` helper is enabled in `codecept.conf.js` config:
63
63
  > Turn off the `show` option if you want to run test in headless mode.
64
64
  > If you don't specify the browser here, `chromium` will be used. Possible browsers are: `chromium`, `firefox` and `webkit`
65
65
 
66
+ To point `firefox` at a custom build instead of the bundled one, pass `executablePath` under the
67
+ `firefox` key:
68
+
69
+ ```js
70
+ helpers: {
71
+ Playwright: {
72
+ url: "http://localhost",
73
+ browser: 'firefox',
74
+ firefox: {
75
+ executablePath: '/path/to/firefox'
76
+ }
77
+ }
78
+ }
79
+ ```
80
+
81
+ Useful with a build like [invisible_playwright](https://github.com/feder-cr/invisible_playwright),
82
+ patched at the source level for a realistic fingerprint, for sites that detect the default Chromium
83
+ path.
84
+
66
85
  Playwright uses different strategies to detect if a page is loaded. In configuration use `waitForNavigation` option for that:
67
86
 
68
87
  When to consider navigation succeeded, defaults to `load`. Given an array of event strings, navigation is considered to be successful after all events have been fired. Events can be either:
@@ -82,8 +82,13 @@ function isTableDataRow(row) {
82
82
  return has.call(row, 'data') && has.call(row, 'skip')
83
83
  }
84
84
 
85
+ function isDataTable(dataTable) {
86
+ if (dataTable instanceof DataTable) return true
87
+ return Boolean(dataTable) && Array.isArray(dataTable.array) && Array.isArray(dataTable.rows) && typeof dataTable.add === 'function'
88
+ }
89
+
85
90
  function detectDataType(dataTable) {
86
- if (dataTable instanceof DataTable) {
91
+ if (isDataTable(dataTable)) {
87
92
  return dataTable.rows
88
93
  }
89
94
 
package/lib/globals.js CHANGED
@@ -30,10 +30,8 @@ export async function initCodeceptGlobals(dir, config, container) {
30
30
  // pause/inject/share stay global even under noGlobals — they're the everyday
31
31
  // debugging/wiring entry points and have no useful import alternative for
32
32
  // page-object code that runs before the container is available.
33
- global.pause = async (...args) => {
34
- const pauseModule = await import('./pause.js')
35
- return (pauseModule.default || pauseModule)(...args)
36
- }
33
+ const pauseModule = await import('./pause.js')
34
+ global.pause = pauseModule.default || pauseModule
37
35
  global.inject = () => container.support()
38
36
  global.share = container.share
39
37
 
@@ -832,12 +832,12 @@ class Appium extends Webdriver {
832
832
  */
833
833
  async grabNetworkConnection() {
834
834
  onlyForApps.call(this, supportedPlatform.android)
835
- const res = await this.browser.getNetworkConnection()
835
+ const res = await this.browser.execute('mobile: getConnectivity')
836
836
  return {
837
- value: res,
838
- inAirplaneMode: res.inAirplaneMode,
839
- hasWifi: res.hasWifi,
840
- hasData: res.hasData,
837
+ value: (res.airplaneMode ? 1 : 0) | (res.wifi ? 2 : 0) | (res.data ? 4 : 0),
838
+ inAirplaneMode: res.airplaneMode,
839
+ hasWifi: res.wifi,
840
+ hasData: res.data,
841
841
  }
842
842
  }
843
843
 
@@ -978,7 +978,11 @@ class Appium extends Webdriver {
978
978
  */
979
979
  async setNetworkConnection(value) {
980
980
  onlyForApps.call(this, supportedPlatform.android)
981
- return this.browser.setNetworkConnection(value)
981
+ return this.browser.execute('mobile: setConnectivity', {
982
+ airplaneMode: !!(value & 1),
983
+ wifi: !!(value & 2),
984
+ data: !!(value & 4),
985
+ })
982
986
  }
983
987
 
984
988
  /**
@@ -53,14 +53,6 @@ class GraphQL extends Helper {
53
53
  this.axios.defaults.headers = this.options.defaultHeaders
54
54
  }
55
55
 
56
- static _checkRequirements() {
57
- try {
58
- require('axios')
59
- } catch (e) {
60
- return ['axios']
61
- }
62
- }
63
-
64
56
  static _config() {
65
57
  return [
66
58
  {
@@ -174,15 +174,6 @@ class GraphQLDataFactory extends Helper {
174
174
  Object.keys(this.factories).forEach(f => (this.created[f] = []))
175
175
  }
176
176
 
177
- static _checkRequirements() {
178
- try {
179
- require('axios')
180
- require('rosie')
181
- } catch (e) {
182
- return ['axios', 'rosie']
183
- }
184
- }
185
-
186
177
  _after() {
187
178
  if (!this.config.cleanup) {
188
179
  return Promise.resolve()
@@ -4,7 +4,9 @@ import gherkinParser, { loadTranslations } from './gherkin.js'
4
4
  import output from '../output.js'
5
5
  import { resolveImportModulePath } from '../utils.js'
6
6
 
7
- export default async function loadTests(mocha) {
7
+ let reloadId = 0
8
+
9
+ export default async function loadTests(mocha, options = {}) {
8
10
  mocha.lazyLoadFiles(true)
9
11
 
10
12
  const featureFiles = mocha.files.filter(file => file.match(/\.feature$/))
@@ -19,9 +21,14 @@ export default async function loadTests(mocha) {
19
21
 
20
22
  for (const file of testFiles) {
21
23
  const resolvedPath = resolveImportModulePath(fsPath.resolve(file))
24
+ const moduleUrl = new URL(resolvedPath)
25
+ if (options.reload) {
26
+ moduleUrl.searchParams.set('codeceptjsReload', String(++reloadId))
27
+ }
28
+
22
29
  mocha.suite.emit('pre-require', global, file, mocha)
23
30
  try {
24
- const module = await import(resolvedPath)
31
+ const module = await import(moduleUrl.href)
25
32
  mocha.suite.emit('require', module, file, mocha)
26
33
  } catch (err) {
27
34
  throw enrichLoaderError(err, file)
@@ -66,6 +66,26 @@ export default function (config = {}) {
66
66
  config = Object.assign({}, defaultConfig, config)
67
67
 
68
68
  let written = false
69
+ const hookFailures = []
70
+
71
+ event.dispatcher.on(event.hook.failed, hook => {
72
+ if (!hook || !['BeforeSuite', 'AfterSuite'].includes(hook.hookName)) return
73
+ const err = hook.err || hook.error
74
+ if (!err) return
75
+ const runnable = hook.ctx && hook.ctx.test
76
+ const suite = runnable && runnable.parent
77
+ hookFailures.push({
78
+ title: hook.title || `${hook.hookName} hook failed`,
79
+ state: 'failed',
80
+ err,
81
+ parent: suite,
82
+ file: (runnable && runnable.file) || (suite && suite.file),
83
+ tags: (suite && suite.tags) || [],
84
+ meta: {},
85
+ steps: [],
86
+ duration: (runnable && runnable.duration) || 0,
87
+ })
88
+ })
69
89
 
70
90
  const writeReport = result => {
71
91
  if (written) return
@@ -76,7 +96,7 @@ export default function (config = {}) {
76
96
  mkdirp.sync(dir)
77
97
  const file = path.join(dir, config.outputName)
78
98
 
79
- fs.writeFileSync(file, buildXml(result, config))
99
+ fs.writeFileSync(file, buildXml(result, config, hookFailures))
80
100
  output.plugin('junitReporter', `JUnit report saved to ${file}`)
81
101
  }
82
102
 
@@ -84,17 +104,18 @@ export default function (config = {}) {
84
104
  event.dispatcher.on(event.workers.result, writeReport)
85
105
  }
86
106
 
87
- function buildXml(result, config) {
107
+ function buildXml(result, config, hookFailures = []) {
88
108
  const doc = new DOMImplementation().createDocument(null, null, null)
89
- const suites = groupBySuite(result.tests)
109
+ const allTests = result.tests.concat(hookFailures)
110
+ const suites = groupBySuite(allTests)
90
111
 
91
112
  const root = doc.createElement('testsuites')
92
113
  setAttr(root, 'name', config.testGroupName)
93
- setAttr(root, 'tests', result.tests.length)
94
- setAttr(root, 'failures', countState(result.tests, 'failed'))
95
- setAttr(root, 'skipped', countSkipped(result.tests))
114
+ setAttr(root, 'tests', allTests.length)
115
+ setAttr(root, 'failures', countState(allTests, 'failed'))
116
+ setAttr(root, 'skipped', countSkipped(allTests))
96
117
  setAttr(root, 'errors', 0)
97
- setAttr(root, 'time', toSeconds(sumDuration(result.tests)))
118
+ setAttr(root, 'time', toSeconds(sumDuration(allTests)))
98
119
  setAttr(root, 'timestamp', toIso(result.stats && result.stats.start))
99
120
  doc.appendChild(root)
100
121
 
package/lib/rerun.js CHANGED
@@ -30,7 +30,7 @@ class CodeceptRerunner extends BaseCodecept {
30
30
  mocha.suite.tests = []
31
31
 
32
32
  mocha.files = filesToRun
33
- await loadTests(mocha)
33
+ await loadTests(mocha, { reload: true })
34
34
 
35
35
  const done = () => {
36
36
  event.emit(event.all.result, container.result())
@@ -385,7 +385,9 @@ const __dirname = __dirname_fn(__filename);
385
385
  )
386
386
 
387
387
  // Write the transpiled file with updated imports
388
- const tempFile = filePath.replace(/\.ts$/, '.temp.mjs')
388
+ // Include process.pid + a random suffix so concurrent run-multiple workers
389
+ // don't write to and delete each other's temp files (see issue #5642).
390
+ const tempFile = filePath.replace(/\.ts$/, `.${process.pid}.${Math.random().toString(36).slice(2, 10)}.temp.mjs`)
389
391
  fs.writeFileSync(tempFile, jsContent)
390
392
  transpiledFiles.set(filePath, tempFile)
391
393
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codeceptjs",
3
- "version": "4.1.0-beta.1-esm-mocha",
3
+ "version": "4.1.0",
4
4
  "type": "module",
5
5
  "description": "Supercharged End 2 End Testing Framework for NodeJS",
6
6
  "keywords": [
@@ -97,7 +97,7 @@
97
97
  "@cucumber/gherkin": "38.0.0",
98
98
  "@cucumber/messages": "32.3.1",
99
99
  "@modelcontextprotocol/sdk": "^1.26.0",
100
- "@xmldom/xmldom": "0.9.8",
100
+ "@xmldom/xmldom": "0.9.10",
101
101
  "acorn": "8.15.0",
102
102
  "ai": "^6.0.43",
103
103
  "arrify": "3.0.0",
@@ -125,7 +125,7 @@
125
125
  "lodash.shuffle": "4.2.0",
126
126
  "mkdirp": "3.0.1",
127
127
  "mocha": "11.7.5",
128
- "monocart-coverage-reports": "2.12.9",
128
+ "monocart-coverage-reports": "2.12.12",
129
129
  "ms": "2.1.3",
130
130
  "multer": "^2.0.2",
131
131
  "ora-classic": "5.4.2",
@@ -155,7 +155,7 @@
155
155
  "@wdio/sauce-service": "9.12.5",
156
156
  "@wdio/selenium-standalone-service": "8.15.0",
157
157
  "@wdio/utils": "9.23.3",
158
- "@xmldom/xmldom": "0.9.8",
158
+ "@xmldom/xmldom": "0.9.10",
159
159
  "bunosh": "latest",
160
160
  "chai": "^6.2.1",
161
161
  "chai-as-promised": "^8.0.2",
@@ -164,11 +164,11 @@
164
164
  "electron": "40.2.1",
165
165
  "eslint": "^9.36.0",
166
166
  "eslint-plugin-import": "2.32.0",
167
- "eslint-plugin-mocha": "11.2.0",
167
+ "eslint-plugin-mocha": "11.3.0",
168
168
  "expect": "30.2.0",
169
169
  "express": "^5.1.0",
170
170
  "globals": "17.3.0",
171
- "graphql": "16.12.0",
171
+ "graphql": "16.14.2",
172
172
  "graphql-tag": "^2.12.6",
173
173
  "husky": "9.1.7",
174
174
  "jsdoc": "^3.6.11",
@@ -464,6 +464,7 @@ declare namespace CodeceptJS {
464
464
  | { shadow: string[] }
465
465
  | { custom: string }
466
466
  | { pw: string }
467
+ | { role: string; name?: string; text?: string; exact?: boolean }
467
468
  interface CustomLocators {}
468
469
  interface OtherLocators {
469
470
  props?: object