codeceptjs 4.2.2 → 4.2.3

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.
Files changed (62) hide show
  1. package/README.md +4 -4
  2. package/docs/ai.md +1 -1
  3. package/docs/alternative-browsers.md +4 -4
  4. package/docs/api.md +13 -13
  5. package/docs/assertions.md +6 -6
  6. package/docs/best.md +1 -1
  7. package/docs/bootstrap.md +1 -1
  8. package/docs/data.md +8 -8
  9. package/docs/helpers/ApiDataFactory.md +2 -2
  10. package/docs/helpers/Appium.md +2 -2
  11. package/docs/helpers/Decision.md +1 -1
  12. package/docs/helpers/Detox.md +1 -1
  13. package/docs/helpers/ExpectHelper.md +1 -1
  14. package/docs/helpers/FileSystem.md +1 -1
  15. package/docs/helpers/GraphQL.md +1 -1
  16. package/docs/helpers/GraphQLDataFactory.md +2 -2
  17. package/docs/helpers/JSONResponse.md +1 -1
  18. package/docs/helpers/Kitesurf.md +1 -1
  19. package/docs/helpers/Lightpanda.md +1 -1
  20. package/docs/helpers/MockRequest.md +1 -1
  21. package/docs/helpers/Moli.md +1 -1
  22. package/docs/helpers/Obscura.md +1 -1
  23. package/docs/helpers/Playwright.md +2 -2
  24. package/docs/helpers/Puppeteer.md +3 -3
  25. package/docs/helpers/REST.md +1 -1
  26. package/docs/helpers/WebDriver.md +1 -1
  27. package/docs/installation.md +1 -1
  28. package/docs/mobile.md +2 -2
  29. package/docs/parallel.md +1 -1
  30. package/docs/playwright.md +5 -5
  31. package/docs/plugins/aiTrace.md +1 -1
  32. package/docs/plugins/autoDelay.md +1 -1
  33. package/docs/plugins/customLocator.md +1 -1
  34. package/docs/plugins/customReporter.md +1 -1
  35. package/docs/plugins/junitReporter.md +2 -2
  36. package/docs/plugins/pageInfo.md +1 -1
  37. package/docs/plugins/pauseOnFail.md +1 -1
  38. package/docs/plugins/retryFailedStep.md +1 -1
  39. package/docs/plugins/screenshotOnFail.md +1 -1
  40. package/docs/plugins/stepTimeout.md +1 -1
  41. package/docs/plugins.md +10 -10
  42. package/docs/puppeteer.md +4 -4
  43. package/docs/timeouts.md +5 -5
  44. package/docs/webdriver.md +8 -8
  45. package/lib/aria.js +1 -0
  46. package/lib/codecept.js +1 -1
  47. package/lib/helper/ApiDataFactory.js +1 -1
  48. package/lib/helper/Appium.js +1 -1
  49. package/lib/helper/GraphQLDataFactory.js +1 -1
  50. package/lib/helper/Playwright.js +1 -1
  51. package/lib/helper/Puppeteer.js +3 -3
  52. package/lib/mocha/asyncWrapper.js +14 -3
  53. package/lib/mocha/test.js +1 -0
  54. package/lib/plugin/auth.js +3 -0
  55. package/lib/plugin/junitReporter.js +21 -12
  56. package/lib/recorder.js +20 -2
  57. package/lib/step/func.js +1 -1
  58. package/lib/step/helper.js +1 -1
  59. package/lib/workers.js +15 -0
  60. package/package.json +1 -1
  61. package/typings/promiseBasedTypes.d.ts +6 -6
  62. package/typings/types.d.ts +6 -6
package/docs/plugins.md CHANGED
@@ -9,7 +9,7 @@ title: Plugins
9
9
 
10
10
  CodeceptJS bundles the following plugins. Each plugin has its own page with full configuration reference.
11
11
 
12
- ## [aiTrace](/plugins/aiTrace)
12
+ ## [aiTrace](/plugins/ai-trace)
13
13
 
14
14
  Generates AI-friendly trace files for debugging with AI agents. This plugin creates a markdown file with test execution logs and links to all artifacts (screenshots, HTML, ARIA snapshots, browser logs, HTTP requests) for each step.
15
15
 
@@ -21,7 +21,7 @@ Uses AI to analyze test failures and provide insights
21
21
 
22
22
  Logs user in for the first test and reuses session for next tests. Works by saving cookies into memory or file. If a session expires automatically logs in again.
23
23
 
24
- ## [autoDelay](/plugins/autoDelay)
24
+ ## [autoDelay](/plugins/auto-delay)
25
25
 
26
26
  Sometimes it takes some time for a page to respond to user's actions. Depending on app's performance this can be either slow or fast.
27
27
 
@@ -33,11 +33,11 @@ Overrides browser helper config from the command line. Works for all browser hel
33
33
 
34
34
  Dumps code coverage from Playwright/Puppeteer after every test.
35
35
 
36
- ## [customLocator](/plugins/customLocator)
36
+ ## [customLocator](/plugins/custom-locator)
37
37
 
38
38
  Creates a [custom locator][1] by using special attributes in HTML.
39
39
 
40
- ## [customReporter](/plugins/customReporter)
40
+ ## [customReporter](/plugins/custom-reporter)
41
41
 
42
42
  Sample custom reporter for CodeceptJS.
43
43
 
@@ -49,11 +49,11 @@ Exposes properties from helper instances as injectable test arguments. Use it to
49
49
 
50
50
  Self-healing tests with AI.
51
51
 
52
- ## [junitReporter](/plugins/junitReporter)
52
+ ## [junitReporter](/plugins/junit-reporter)
53
53
 
54
54
  Generates a JUnit-compatible XML report after a test run.
55
55
 
56
- ## [pageInfo](/plugins/pageInfo)
56
+ ## [pageInfo](/plugins/page-info)
57
57
 
58
58
  Collects information from web page after each failed test and adds it to the test as an artifact. It is suggested to enable this plugin if you run tests on CI and you need to debug failed tests. This plugin can be paired with `analyze` plugin to provide more context.
59
59
 
@@ -61,11 +61,11 @@ Collects information from web page after each failed test and adds it to the tes
61
61
 
62
62
  Pauses test execution interactively. Replaces the legacy `pauseOnFail` plugin. The default `on=fail` matches the old `pauseOnFail` behavior.
63
63
 
64
- ## [pauseOnFail](/plugins/pauseOnFail)
64
+ ## [pauseOnFail](/plugins/pause-on-fail)
65
65
 
66
66
  Starts an interactive pause when a test fails.
67
67
 
68
- ## [retryFailedStep](/plugins/retryFailedStep)
68
+ ## [retryFailedStep](/plugins/retry-failed-step)
69
69
 
70
70
  Retries each failed step in a test.
71
71
 
@@ -77,7 +77,7 @@ Records a video of tests. Uses Playwright's `page.screencast` API (WebM) when th
77
77
 
78
78
  Saves screenshots from the browser at points triggered by `on=`.
79
79
 
80
- ## [screenshotOnFail](/plugins/screenshotOnFail)
80
+ ## [screenshotOnFail](/plugins/screenshot-on-fail)
81
81
 
82
82
  Saves a screenshot when a test fails.
83
83
 
@@ -85,7 +85,7 @@ Saves a screenshot when a test fails.
85
85
 
86
86
  Collects all pages visited while tests are running and saves them as a [sitemap][1] XML file.
87
87
 
88
- ## [stepTimeout](/plugins/stepTimeout)
88
+ ## [stepTimeout](/plugins/step-timeout)
89
89
 
90
90
  Set timeout for test steps globally.
91
91
 
package/docs/puppeteer.md CHANGED
@@ -43,7 +43,7 @@ npx codeceptjs init
43
43
 
44
44
  You will be asked for a Helper to use, you should select Puppeteer and provide url of a website you are testing.
45
45
 
46
- > Puppeteer can also work with Firefox. [Learn how to set it up](/helpers/Puppeteer-firefox)
46
+ > Puppeteer can also work with Firefox. [Learn how to set it up](/helpers/puppeteer-firefox)
47
47
 
48
48
  ## Configuring
49
49
 
@@ -80,7 +80,7 @@ By default it is set to `domcontentloaded` which waits for `DOMContentLoaded` ev
80
80
  When a test runs faster than application it is recommended to increase `waitForAction` config value.
81
81
  It will wait for a small amount of time (100ms) by default after each user action is taken.
82
82
 
83
- > ▶ More options are listed in [helper reference](https://codecept.io/helpers/Puppeteer/).
83
+ > ▶ More options are listed in [helper reference](https://codecept.io/helpers/puppeteer/).
84
84
 
85
85
  ## Writing Tests
86
86
 
@@ -105,7 +105,7 @@ Tests consist with a scenario of user's action taken on a page. The most widely
105
105
  - `see`, `dontSee` - to check for a text on a page
106
106
  - `seeElement`, `dontSeeElement` - to check for elements on a page
107
107
 
108
- > ℹ All actions are listed in [Puppeteer helper reference](https://codecept.io/helpers/Puppeteer/).\*
108
+ > ℹ All actions are listed in [Puppeteer helper reference](https://codecept.io/helpers/puppeteer/).\*
109
109
 
110
110
  All actions which interact with elements **support CSS and XPath locators**. Actions like `click` or `fillField` by locate elements by their name or value on a page:
111
111
 
@@ -241,7 +241,7 @@ To master request intercepting [use `HTTPRequest` object](https://pptr.dev/next/
241
241
 
242
242
  ## Accessing Puppeteer API
243
243
 
244
- To get Puppeteer API inside a test use [`I.usePupepteerTo`](/helpers/Puppeteer/#usepuppeteerto) method with a callback.
244
+ To get Puppeteer API inside a test use [`I.usePupepteerTo`](/helpers/puppeteer/#usepuppeteerto) method with a callback.
245
245
  To keep test readable provide a description of a callback inside the first parameter.
246
246
 
247
247
  ```js
package/docs/timeouts.md CHANGED
@@ -85,11 +85,11 @@ Each helper (Playwright, Puppeteer, WebDriver, Appium, REST) has its own timeout
85
85
 
86
86
  Refer to helper-specific documentation for timeout configuration:
87
87
 
88
- - [Playwright Helper](/helpers/Playwright) — `timeout`, `waitForTimeout`, `getPageTimeout`
89
- - [Puppeteer Helper](/helpers/Puppeteer) — `waitForTimeout`, `getPageTimeout`
90
- - [WebDriver Helper](/helpers/WebDriver) — `waitForTimeout`, `smartWait`, `timeouts` object
91
- - [Appium Helper](/helpers/Appium) — `timeouts` object
92
- - [REST Helper](/helpers/REST) — `timeout`
88
+ - [Playwright Helper](/helpers/playwright) — `timeout`, `waitForTimeout`, `getPageTimeout`
89
+ - [Puppeteer Helper](/helpers/puppeteer) — `waitForTimeout`, `getPageTimeout`
90
+ - [WebDriver Helper](/helpers/web-driver) — `waitForTimeout`, `smartWait`, `timeouts` object
91
+ - [Appium Helper](/helpers/appium) — `timeouts` object
92
+ - [REST Helper](/helpers/rest) — `timeout`
93
93
 
94
94
  ## stepTimeout Plugin
95
95
 
package/docs/webdriver.md CHANGED
@@ -91,7 +91,7 @@ keepBrowserState: true,
91
91
  keepCookies: true,
92
92
  ```
93
93
 
94
- > ▶ More config options available on [WebDriver helper reference](/helpers/WebDriver#configuration)
94
+ > ▶ More config options available on [WebDriver helper reference](/helpers/web-driver#configuration)
95
95
 
96
96
  ### Headless Mode
97
97
 
@@ -138,7 +138,7 @@ desiredCapabilities: {
138
138
 
139
139
  ### Cloud Providers
140
140
 
141
- By default, WebdriverIO starts a local driver automatically, so no connection parameters are needed. To run tests via [Cloud Providers](/helpers/WebDriver#cloud-providers) instead, specify `host`, `port`, `protocol`, and `path` parameters pointing to the service. You may also need `user` and `key` parameters to authenticate on the cloud service.
141
+ By default, WebdriverIO starts a local driver automatically, so no connection parameters are needed. To run tests via [Cloud Providers](/helpers/web-driver#cloud-providers) instead, specify `host`, `port`, `protocol`, and `path` parameters pointing to the service. You may also need `user` and `key` parameters to authenticate on the cloud service.
142
142
 
143
143
  There are also [browser and platform specific capabilities](https://github.com/SeleniumHQ/selenium/wiki/DesiredCapabilities). Services like SauceLabs, BrowserStack or browser vendors can provide their own specific capabilities for more tuning.
144
144
 
@@ -208,7 +208,7 @@ Tests consist with a scenario of user's action taken on a page. The most widely
208
208
  * `see`, `dontSee` - to check for a text on a page
209
209
  * `seeElement`, `dontSeeElement` - to check for elements on a page
210
210
 
211
- > ℹ All actions are listed in [WebDriver helper reference](https://codecept.io/helpers/WebDriver/).*
211
+ > ℹ All actions are listed in [WebDriver helper reference](https://codecept.io/helpers/web-driver/).*
212
212
 
213
213
  All actions which interact with elements **support CSS and XPath locators**. Actions like `click` or `fillField` by locate elements by their name or value on a page:
214
214
 
@@ -252,7 +252,7 @@ npx codeceptjs run --steps
252
252
 
253
253
  After a page is opened a full control of a browser is given to a terminal. Type in different commands such as `click`, `see`, `fillField` to write the test. A successful commands will be saved to `./output/cli-history` file and can be copied into a test.
254
254
 
255
- > ℹ All actions are listed in [WebDriver helper reference](/helpers/WebDriver).
255
+ > ℹ All actions are listed in [WebDriver helper reference](/helpers/web-driver).
256
256
 
257
257
  An interactive shell output may look like this:
258
258
 
@@ -420,7 +420,7 @@ There are following options available:
420
420
 
421
421
  * Use headless Chrome or Firefox.
422
422
  * Use [Selenoid](/plugins/selenoid) to run browsers inside Docker containers.
423
- * Use paid [cloud services (SauceLabs, BrowserStack, TestingBot)](/helpers/WebDriver#cloud-providers).
423
+ * Use paid [cloud services (SauceLabs, BrowserStack, TestingBot)](/helpers/web-driver#cloud-providers).
424
424
 
425
425
  ## Video Recording
426
426
 
@@ -494,7 +494,7 @@ This is useful when you want to isolate application testing from a backend. For
494
494
 
495
495
  > **WebDriver has limited ability to mock requests**, so you can only mock only requests performed after page is loaded. This means that you can't block Google Analytics, or CDN calls, but you can mock API requests performed on user action.
496
496
 
497
- To mock requests enable additional helper [MockRequest](/helpers/MockRequest) (which is based on Polly.js).
497
+ To mock requests enable additional helper [MockRequest](/helpers/mock-request) (which is based on Polly.js).
498
498
 
499
499
  ```js
500
500
  helpers: {
@@ -529,7 +529,7 @@ I.click('Go to Next Page');
529
529
  // in WebDriver as we can't detect that the page was reloaded, so no mocking :(
530
530
  ```
531
531
 
532
- > See [`mockRequest` API](/helpers/MockRequest#mockrequest)
532
+ > See [`mockRequest` API](/helpers/mock-request#mockrequest)
533
533
 
534
534
  To see `mockRequest` method in intellisense auto completion don't forget to run `codeceptjs def` command:
535
535
 
@@ -542,7 +542,7 @@ Mocking rules will be kept while a test is running. To stop mocking use `I.stopM
542
542
 
543
543
  ## Accessing webdriverio API
544
544
 
545
- To get [webdriverio browser API](https://webdriver.io/docs/api.html) inside a test use [`I.useWebDriverTo`](/helpers/WebDriver/#usewebdriverto) method with a callback.
545
+ To get [webdriverio browser API](https://webdriver.io/docs/api.html) inside a test use [`I.useWebDriverTo`](/helpers/web-driver/#usewebdriverto) method with a callback.
546
546
  To keep test readable provide a description of a callback inside the first parameter.
547
547
 
548
548
  ```js
package/lib/aria.js CHANGED
@@ -121,6 +121,7 @@ function dropEmpty(nodes) {
121
121
  const children = dropEmpty(node.children)
122
122
  if (INTERACTIVE_ROLES.has(node.role)) return [{ ...node, children }]
123
123
  if (children.length > 0) return [{ ...node, children }]
124
+ if (node.value !== undefined && node.value !== null && String(node.value).trim()) return [{ ...node, children }]
124
125
  return []
125
126
  })
126
127
  }
package/lib/codecept.js CHANGED
@@ -279,7 +279,7 @@ class Codecept {
279
279
  */
280
280
  filterLastFailedTests(mocha) {
281
281
  if (!this.opts.lastFailed) return
282
- const failedTestUids = new Set(Result.loadFailedTests().map(test => test.uid))
282
+ const failedTestUids = new Set(Result.loadFailedTests().map(test => test.uid?.split('@')[0]))
283
283
  const filterSuite = suite => {
284
284
  suite.tests = suite.tests.filter(test => failedTestUids.has(test.uid))
285
285
  suite.suites.forEach(filterSuite)
@@ -99,7 +99,7 @@ import { resolveImportModulePath } from '../utils.js'
99
99
  * It is required to set REST API `endpoint` which is the baseURL for all API requests.
100
100
  * Factory file is expected to be passed via `factory` option.
101
101
  *
102
- * This Helper uses [REST](http://codecept.io/helpers/REST/) helper and accepts its configuration in "REST" section.
102
+ * This Helper uses [REST](http://codecept.io/helpers/rest/) helper and accepts its configuration in "REST" section.
103
103
  * For instance, to set timeout you should add:
104
104
  *
105
105
  * ```js
@@ -24,7 +24,7 @@ const vendorPrefix = {
24
24
  }
25
25
 
26
26
  /**
27
- * Appium helper extends [Webdriver](http://codecept.io/helpers/WebDriver/) helper.
27
+ * Appium helper extends [Webdriver](http://codecept.io/helpers/web-driver/) helper.
28
28
  * It supports all browser methods and also includes special methods for mobile apps testing.
29
29
  * You can use this helper to test Web on desktop and mobile devices and mobile apps.
30
30
  *
@@ -100,7 +100,7 @@ import store from '../store.js'
100
100
  * It is required to set GraphQL `endpoint` which is the URL to which all the queries go to.
101
101
  * Factory file is expected to be passed via `factory` option.
102
102
  *
103
- * This Helper uses [GraphQL](http://codecept.io/helpers/GraphQL/) helper and accepts its configuration in "GraphQL" section.
103
+ * This Helper uses [GraphQL](http://codecept.io/helpers/graph-ql/) helper and accepts its configuration in "GraphQL" section.
104
104
  * For instance, to set timeout you should add:
105
105
  *
106
106
  * ```js
@@ -2054,7 +2054,7 @@ class Playwright extends Helper {
2054
2054
  * Handles a file download. A file name is required to save the file on disk.
2055
2055
  * Files are saved to "output" directory.
2056
2056
  *
2057
- * Should be used with [FileSystem helper](https://codecept.io/helpers/FileSystem) to check that file were downloaded correctly.
2057
+ * Should be used with [FileSystem helper](https://codecept.io/helpers/file-system) to check that file were downloaded correctly.
2058
2058
  *
2059
2059
  * ```js
2060
2060
  * I.handleDownloads('downloads/avatar.jpg');
@@ -94,7 +94,7 @@ const consoleLogStore = new Console()
94
94
  * @prop {string} [windowSize] - default window size. Set a dimension in format WIDTHxHEIGHT like `640x480`.
95
95
  * @prop {string} [userAgent] - user-agent string.
96
96
  * @prop {boolean} [manualStart=false] - do not start browser before a test, start it manually inside a helper with `this.helpers["Puppeteer"]._startBrowser()`.
97
- * @prop {string} [browser=chrome] - can be changed to `firefox` when using [puppeteer-firefox](https://codecept.io/helpers/Puppeteer-firefox).
97
+ * @prop {string} [browser=chrome] - can be changed to `firefox` when using [puppeteer-firefox](https://codecept.io/helpers/puppeteer-firefox).
98
98
  * @prop {object} [chrome] - pass additional [Puppeteer run options](https://github.com/puppeteer/puppeteer/blob/main/docs/api/puppeteer.launchoptions.md).
99
99
  * @prop {boolean} [highlightElement] - highlight the interacting elements. Default: false. Note: only activate under verbose mode (--verbose).
100
100
  */
@@ -115,7 +115,7 @@ const config = {}
115
115
  * ```
116
116
  * Using `puppeteer-core` package, will prevent the download of browser binaries and allow connecting to an existing browser installation or for connecting to a remote one.
117
117
  *
118
- * > Experimental Firefox support [can be activated](https://codecept.io/helpers/Puppeteer-firefox).
118
+ * > Experimental Firefox support [can be activated](https://codecept.io/helpers/puppeteer-firefox).
119
119
  *
120
120
  * <!-- configuration -->
121
121
  *
@@ -1320,7 +1320,7 @@ class Puppeteer extends Helper {
1320
1320
 
1321
1321
  /**
1322
1322
  * Sets a directory to where save files. Allows to test file downloads.
1323
- * Should be used with [FileSystem helper](https://codecept.io/helpers/FileSystem) to check that file were downloaded correctly.
1323
+ * Should be used with [FileSystem helper](https://codecept.io/helpers/file-system) to check that file were downloaded correctly.
1324
1324
  *
1325
1325
  * By default, files are saved to `output/downloads`.
1326
1326
  * This directory is cleaned on every `handleDownloads` call, to ensure no old files are kept.
@@ -54,7 +54,10 @@ export function test(test) {
54
54
 
55
55
  test.fn = function (done) {
56
56
  const doneFn = makeDoneCallableOnce(done)
57
+ let recoveryStarted = false
57
58
  recorder.errHandler(err => {
59
+ if (recoveryStarted) return
60
+ recoveryStarted = true
58
61
  recorder.session.start('teardown')
59
62
  recorder.cleanAsyncErr()
60
63
  if (test.throws) {
@@ -114,7 +117,13 @@ export function test(test) {
114
117
  export function injected(fn, suite, hookName) {
115
118
  return function (done) {
116
119
  const doneFn = makeDoneCallableOnce(done)
120
+ const opts = suite.opts || {}
121
+ const retries = opts[`retry${ucfirst(hookName)}`] || 0
122
+ let retryPending = retries > 0
123
+ let recoveryStarted = false
117
124
  const errHandler = err => {
125
+ if (retryPending || recoveryStarted) return
126
+ recoveryStarted = true
118
127
  recorder.session.start('teardown')
119
128
  recorder.cleanAsyncErr()
120
129
  if (['before', 'beforeSuite'].includes(hookName)) {
@@ -149,9 +158,6 @@ export function injected(fn, suite, hookName) {
149
158
  })
150
159
  }
151
160
 
152
- const opts = suite.opts || {}
153
- const retries = opts[`retry${ucfirst(hookName)}`] || 0
154
-
155
161
  const currentTest = hookName === 'before' || hookName === 'after' ? suite?.ctx?.currentTest : null
156
162
 
157
163
  promiseRetry(
@@ -165,8 +171,13 @@ export function injected(fn, suite, hookName) {
165
171
  retry(err)
166
172
  } finally {
167
173
  if (number < retries) {
174
+ // drain the failed chain so in-flight steps (sessions, listeners)
175
+ // finish before the next attempt starts queueing new ones
176
+ await recorder.promise().catch(() => {})
168
177
  recorder.stop()
169
178
  recorder.start()
179
+ } else {
180
+ retryPending = false
170
181
  }
171
182
  }
172
183
  },
package/lib/mocha/test.js CHANGED
@@ -106,6 +106,7 @@ function serializeTest(test, error = null) {
106
106
  const parent = {}
107
107
  if (test.parent) {
108
108
  parent.title = test.parent.title
109
+ parent.file = test.parent.file
109
110
  }
110
111
 
111
112
  if (test.opts) {
@@ -303,6 +303,7 @@ export default function (config) {
303
303
 
304
304
  section.start()
305
305
 
306
+ const queueId = recorder.getQueueId()
306
307
  const cookies = store[`${name}_session`]
307
308
  const shouldAwait = isAsyncFunction(userSession.login) || isAsyncFunction(userSession.restore) || isAsyncFunction(userSession.check)
308
309
 
@@ -338,6 +339,7 @@ export default function (config) {
338
339
  }
339
340
  section.end()
340
341
  recorder.session.catch(err => {
342
+ if (recorder.getQueueId() !== queueId) return
341
343
  output.debug(`Failed auto login for ${name} due to ${err}`)
342
344
  output.debug('Logging in again')
343
345
  recorder.session.start('auto login')
@@ -355,6 +357,7 @@ export default function (config) {
355
357
  })
356
358
  })
357
359
  recorder.add(() => {
360
+ if (recorder.getQueueId() !== queueId) return
358
361
  recorder.session.restore('check login')
359
362
  })
360
363
 
@@ -1,6 +1,7 @@
1
1
  import fs from 'fs'
2
2
  import path from 'path'
3
3
  import os from 'os'
4
+ import { isMainThread } from 'worker_threads'
4
5
  import { mkdirp } from 'mkdirp'
5
6
  import { DOMImplementation, XMLSerializer } from '@xmldom/xmldom'
6
7
 
@@ -45,7 +46,7 @@ const INVALID_XML_CHARS = new RegExp('[\\u0000-\\u0008\\u000B\\u000C\\u000E-\\u0
45
46
  * Possible config options:
46
47
  *
47
48
  * * `outputName`: file name for the report. Default: `report.xml`.
48
- * * `output`: directory where the report is stored, relative to the project root. Default: the `output` directory.
49
+ * * `output`: directory where the report is stored, relative to the project root. Default: the `output` directory. With `run-workers` and `multiple` runs, each run writes its own report into its run folder (e.g. `output/dev_chromium1`) and this option is ignored.
49
50
  * * `testGroupName`: value of the `name` attribute on the root `<testsuites>` element. Default: `CodeceptJS`.
50
51
  * * `attachMeta`: add the test's meta information (`meta` keys, `tags`, `retries`) as `<properties>`. Default: true.
51
52
  * * `attachSteps`: add the step/substep log as `<system-out>`. Default: true.
@@ -67,10 +68,6 @@ export default function (config = {}) {
67
68
 
68
69
  let written = false
69
70
  const hookFailures = []
70
- // groupBySuite() (below) groups by object identity, not by value — reused
71
- // across BeforeSuite/AfterSuite failures from the same worker-forwarded
72
- // suite so they land in one <testsuite>, not one per failure.
73
- const workerSuiteByKey = new Map()
74
71
 
75
72
  event.dispatcher.on(event.hook.failed, hook => {
76
73
  if (!hook || !['BeforeSuite', 'AfterSuite'].includes(hook.hookName)) return
@@ -84,11 +81,7 @@ export default function (config = {}) {
84
81
  // groups under its real suite instead of the "Tests" fallback.
85
82
  let suite = runnable && runnable.parent
86
83
  if (!suite && hook.suiteTitle) {
87
- const key = `${hook.suiteTitle} ${hook.suiteFile || ''}`
88
- if (!workerSuiteByKey.has(key)) {
89
- workerSuiteByKey.set(key, { title: hook.suiteTitle, file: hook.suiteFile, tags: hook.suiteTags })
90
- }
91
- suite = workerSuiteByKey.get(key)
84
+ suite = { title: hook.suiteTitle, file: hook.suiteFile, tags: hook.suiteTags }
92
85
  }
93
86
  hookFailures.push({
94
87
  title: hook.title || `${hook.hookName} hook failed`,
@@ -100,19 +93,35 @@ export default function (config = {}) {
100
93
  meta: {},
101
94
  steps: [],
102
95
  duration: (runnable && runnable.duration) || 0,
96
+ outputDir: hook.outputDir,
103
97
  })
104
98
  })
105
99
 
106
100
  const writeReport = result => {
107
101
  if (written) return
108
102
  if (!result || !Array.isArray(result.tests)) return
103
+ if (!isMainThread) return
109
104
  written = true
110
105
 
106
+ const runDirs = [...new Set(result.tests.map(test => test.outputDir).filter(Boolean))]
107
+ if (runDirs.length) {
108
+ for (const dir of runDirs) {
109
+ const runResult = { tests: result.tests.filter(test => test.outputDir === dir), stats: result.stats }
110
+ const runHookFailures = hookFailures.filter(hf => hf.outputDir === dir)
111
+ saveXml(dir, buildXml(runResult, config, runHookFailures))
112
+ }
113
+ return
114
+ }
115
+
111
116
  const dir = config.output ? path.resolve(store.codeceptDir || process.cwd(), config.output) : store.outputDir || process.cwd()
117
+ saveXml(dir, buildXml(result, config, hookFailures))
118
+ }
119
+
120
+ const saveXml = (dir, xml) => {
112
121
  mkdirp.sync(dir)
113
122
  const file = path.join(dir, config.outputName)
114
123
 
115
- fs.writeFileSync(file, buildXml(result, config, hookFailures))
124
+ fs.writeFileSync(file, xml)
116
125
  output.plugin('junitReporter', `JUnit report saved to ${file}`)
117
126
  }
118
127
 
@@ -296,7 +305,7 @@ function groupBySuite(tests) {
296
305
  const groups = []
297
306
  const byKey = new Map()
298
307
  for (const test of tests) {
299
- const key = test.parent || test
308
+ const key = test.parent ? `${test.parent.title}\0${test.parent.file || test.file || ''}` : test
300
309
  if (!byKey.has(key)) {
301
310
  const list = []
302
311
  byKey.set(key, list)
package/lib/recorder.js CHANGED
@@ -89,6 +89,8 @@ export default {
89
89
  */
90
90
  reset() {
91
91
  if (promise && running) this.catch()
92
+ else swallow(promise)
93
+ oldPromises.forEach(swallow)
92
94
  queueId++
93
95
  sessionId = null
94
96
  sessionStack = [] // Clear the session stack
@@ -125,6 +127,16 @@ export default {
125
127
  * @inner
126
128
  */
127
129
  start(name) {
130
+ if (sessionId === name) {
131
+ // re-starting the same session abandons the current (broken) chain
132
+ // without polluting the session stack
133
+ debug(`${currentQueue()}Session <${name}> already started, abandoning its chain`)
134
+ tasks.push('--->')
135
+ this.running = true
136
+ swallow(promise)
137
+ promise = Promise.resolve()
138
+ return
139
+ }
128
140
  if (sessionId) {
129
141
  debug(`${currentQueue()}Session already started as ${sessionId}, nesting session ${name}`)
130
142
  // Push current session to stack instead of restoring it
@@ -136,7 +148,7 @@ export default {
136
148
  }
137
149
  debug(`${currentQueue()}Starting <${name}> session`)
138
150
  tasks.push('--->')
139
- oldPromises.push(promise)
151
+ oldPromises.push(swallow(promise))
140
152
  this.running = true
141
153
  sessionId = name
142
154
  promise = Promise.resolve()
@@ -151,7 +163,8 @@ export default {
151
163
  debug(`${currentQueue()}Finalize <${name}> session`)
152
164
  this.running = false
153
165
  this.catch(errFn)
154
- promise = promise.then(() => oldPromises.pop())
166
+ const restored = oldPromises.pop()
167
+ if (restored && restored !== promise) promise = promise.then(() => restored)
155
168
 
156
169
  // Restore parent session from stack if available
157
170
  if (sessionStack.length > 0) {
@@ -426,6 +439,11 @@ export default {
426
439
  },
427
440
  }
428
441
 
442
+ function swallow(p) {
443
+ if (p) p.catch(() => {})
444
+ return p
445
+ }
446
+
429
447
  function getTimeoutPromise(timeoutMs, taskName) {
430
448
  let timer
431
449
  if (timeoutMs) debug(`Timing out in ${timeoutMs}ms`)
package/lib/step/func.js CHANGED
@@ -21,7 +21,7 @@ class FuncStep extends BaseStep {
21
21
  // we wrap that function to track time and status
22
22
  // and disable it in dry run mode
23
23
  this.args = Array.prototype.slice.call(arguments)
24
- this.startTime = +Date.now()
24
+ if (!this.startTime) this.startTime = +Date.now()
25
25
 
26
26
  if (store.dryRun) {
27
27
  this.setStatus('success')
@@ -16,7 +16,7 @@ class HelperStep extends Step {
16
16
  */
17
17
  run() {
18
18
  this.args = Array.prototype.slice.call(arguments)
19
- this.startTime = +Date.now()
19
+ if (!this.startTime) this.startTime = +Date.now()
20
20
 
21
21
  if (store.dryRun) {
22
22
  this.setStatus('success')
package/lib/workers.js CHANGED
@@ -104,9 +104,22 @@ const createWorker = (workerObject, isPoolMode = false, skipTests = []) => {
104
104
  })
105
105
 
106
106
  WorkerStorage.addWorker(worker)
107
+ worker.runOutputDir = workerObject.runOutputDir
107
108
  return worker
108
109
  }
109
110
 
111
+ const tagWithRun = (message, runOutputDir) => {
112
+ if (!message.event || !message.data || typeof message.data !== 'object') return
113
+ const runName = path.basename(runOutputDir)
114
+ const tag = obj => {
115
+ if (!obj || typeof obj !== 'object' || obj.outputDir) return
116
+ obj.outputDir = runOutputDir
117
+ if (obj.uid) obj.uid = `${obj.uid}@${runName}`
118
+ }
119
+ tag(message.data)
120
+ if (Array.isArray(message.data.tests)) message.data.tests.forEach(tag)
121
+ }
122
+
110
123
  const simplifyObject = object => {
111
124
  return Object.keys(object)
112
125
  .filter(k => k.indexOf('_') !== 0)
@@ -169,6 +182,7 @@ const createWorkerObjects = (testGroups, config, testRoot, options, selectedRuns
169
182
  workerObj.addTests(tests)
170
183
  workerObj.setTestRoot(testRoot)
171
184
  workerObj.addOptions(options)
185
+ workerObj.runOutputDir = path.resolve(testRoot, finalConfig.output)
172
186
  testWorkerArray.push(workerObj)
173
187
  })
174
188
  workers.push(...testWorkerArray)
@@ -659,6 +673,7 @@ class Workers extends EventEmitter {
659
673
 
660
674
  worker.on('message', message => {
661
675
  lastActivity = Date.now() // Update activity timestamp
676
+ if (worker.runOutputDir) tagWithRun(message, worker.runOutputDir)
662
677
 
663
678
  // Track current test
664
679
  if (message.event === event.test.started && message.data) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codeceptjs",
3
- "version": "4.2.2",
3
+ "version": "4.2.3",
4
4
  "type": "module",
5
5
  "description": "Supercharged End 2 End Testing Framework for NodeJS",
6
6
  "keywords": [
@@ -92,7 +92,7 @@ declare namespace CodeceptJS {
92
92
  * It is required to set REST API `endpoint` which is the baseURL for all API requests.
93
93
  * Factory file is expected to be passed via `factory` option.
94
94
  *
95
- * This Helper uses [REST](http://codecept.io/helpers/REST/) helper and accepts its configuration in "REST" section.
95
+ * This Helper uses [REST](http://codecept.io/helpers/rest/) helper and accepts its configuration in "REST" section.
96
96
  * For instance, to set timeout you should add:
97
97
  *
98
98
  * ```js
@@ -3016,7 +3016,7 @@ declare namespace CodeceptJS {
3016
3016
  * It is required to set GraphQL `endpoint` which is the URL to which all the queries go to.
3017
3017
  * Factory file is expected to be passed via `factory` option.
3018
3018
  *
3019
- * This Helper uses [GraphQL](http://codecept.io/helpers/GraphQL/) helper and accepts its configuration in "GraphQL" section.
3019
+ * This Helper uses [GraphQL](http://codecept.io/helpers/graph-ql/) helper and accepts its configuration in "GraphQL" section.
3020
3020
  * For instance, to set timeout you should add:
3021
3021
  *
3022
3022
  * ```js
@@ -4529,7 +4529,7 @@ declare namespace CodeceptJS {
4529
4529
  * Handles a file download. A file name is required to save the file on disk.
4530
4530
  * Files are saved to "output" directory.
4531
4531
  *
4532
- * Should be used with [FileSystem helper](https://codecept.io/helpers/FileSystem) to check that file were downloaded correctly.
4532
+ * Should be used with [FileSystem helper](https://codecept.io/helpers/file-system) to check that file were downloaded correctly.
4533
4533
  *
4534
4534
  * ```js
4535
4535
  * I.handleDownloads('downloads/avatar.jpg');
@@ -6093,7 +6093,7 @@ declare namespace CodeceptJS {
6093
6093
  * @property [windowSize] - default window size. Set a dimension in format WIDTHxHEIGHT like `640x480`.
6094
6094
  * @property [userAgent] - user-agent string.
6095
6095
  * @property [manualStart = false] - do not start browser before a test, start it manually inside a helper with `this.helpers["Puppeteer"]._startBrowser()`.
6096
- * @property [browser = chrome] - can be changed to `firefox` when using [puppeteer-firefox](https://codecept.io/helpers/Puppeteer-firefox).
6096
+ * @property [browser = chrome] - can be changed to `firefox` when using [puppeteer-firefox](https://codecept.io/helpers/puppeteer-firefox).
6097
6097
  * @property [chrome] - pass additional [Puppeteer run options](https://github.com/puppeteer/puppeteer/blob/main/docs/api/puppeteer.launchoptions.md).
6098
6098
  * @property [highlightElement] - highlight the interacting elements. Default: false. Note: only activate under verbose mode (--verbose).
6099
6099
  */
@@ -6136,7 +6136,7 @@ declare namespace CodeceptJS {
6136
6136
  * ```
6137
6137
  * Using `puppeteer-core` package, will prevent the download of browser binaries and allow connecting to an existing browser installation or for connecting to a remote one.
6138
6138
  *
6139
- * > Experimental Firefox support [can be activated](https://codecept.io/helpers/Puppeteer-firefox).
6139
+ * > Experimental Firefox support [can be activated](https://codecept.io/helpers/puppeteer-firefox).
6140
6140
  *
6141
6141
  * <!-- configuration -->
6142
6142
  *
@@ -6756,7 +6756,7 @@ declare namespace CodeceptJS {
6756
6756
  clickLink(locator: CodeceptJS.LocatorOrString, context?: CodeceptJS.LocatorOrString): Promise<any>;
6757
6757
  /**
6758
6758
  * Sets a directory to where save files. Allows to test file downloads.
6759
- * Should be used with [FileSystem helper](https://codecept.io/helpers/FileSystem) to check that file were downloaded correctly.
6759
+ * Should be used with [FileSystem helper](https://codecept.io/helpers/file-system) to check that file were downloaded correctly.
6760
6760
  *
6761
6761
  * By default, files are saved to `output/downloads`.
6762
6762
  * This directory is cleaned on every `handleDownloads` call, to ensure no old files are kept.