codeceptjs 3.7.0-beta.3 → 3.7.0-beta.5

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 (45) hide show
  1. package/README.md +9 -10
  2. package/bin/codecept.js +7 -0
  3. package/lib/actor.js +47 -92
  4. package/lib/command/check.js +173 -0
  5. package/lib/command/definitions.js +2 -0
  6. package/lib/command/run-workers.js +1 -1
  7. package/lib/command/workers/runTests.js +112 -109
  8. package/lib/container.js +9 -0
  9. package/lib/effects.js +123 -0
  10. package/lib/heal.js +10 -0
  11. package/lib/helper/Appium.js +27 -16
  12. package/lib/helper/Playwright.js +15 -0
  13. package/lib/helper/Puppeteer.js +5 -0
  14. package/lib/helper/WebDriver.js +9 -1
  15. package/lib/listener/emptyRun.js +2 -5
  16. package/lib/listener/globalTimeout.js +41 -11
  17. package/lib/listener/steps.js +3 -0
  18. package/lib/mocha/cli.js +22 -5
  19. package/lib/mocha/featureConfig.js +13 -0
  20. package/lib/mocha/scenarioConfig.js +11 -0
  21. package/lib/mocha/test.js +15 -0
  22. package/lib/mocha/types.d.ts +6 -0
  23. package/lib/output.js +74 -73
  24. package/lib/pause.js +3 -7
  25. package/lib/plugin/heal.js +30 -0
  26. package/lib/plugin/stepTimeout.js +1 -1
  27. package/lib/recorder.js +1 -1
  28. package/lib/step/base.js +180 -0
  29. package/lib/step/config.js +50 -0
  30. package/lib/step/helper.js +47 -0
  31. package/lib/step/meta.js +91 -0
  32. package/lib/step/record.js +74 -0
  33. package/lib/step/retry.js +11 -0
  34. package/lib/step/section.js +25 -0
  35. package/lib/step/timeout.js +42 -0
  36. package/lib/step.js +15 -348
  37. package/lib/steps.js +23 -0
  38. package/lib/store.js +2 -0
  39. package/lib/utils.js +58 -0
  40. package/lib/within.js +2 -2
  41. package/lib/workers.js +2 -12
  42. package/package.json +7 -5
  43. package/typings/index.d.ts +5 -4
  44. package/typings/promiseBasedTypes.d.ts +1 -37
  45. package/typings/types.d.ts +39 -64
package/lib/utils.js CHANGED
@@ -4,6 +4,7 @@ const path = require('path')
4
4
  const getFunctionArguments = require('fn-args')
5
5
  const deepClone = require('lodash.clonedeep')
6
6
  const { convertColorToRGBA, isColorProperty } = require('./colorUtils')
7
+ const Fuse = require('fuse.js')
7
8
 
8
9
  function deepMerge(target, source) {
9
10
  const merge = require('lodash.merge')
@@ -484,3 +485,60 @@ module.exports.humanizeFunction = function (fn) {
484
485
 
485
486
  return simplified
486
487
  }
488
+
489
+ /**
490
+ * Searches through a given data source using the Fuse.js library for fuzzy searching.
491
+ *
492
+ * @function searchWithFusejs
493
+ * @param {Array|Object} source - The data source to search through. This can be an array of objects or strings.
494
+ * @param {string} searchString - The search query string to match against the source.
495
+ * @param {Object} [opts] - Optional configuration object for Fuse.js.
496
+ * @param {boolean} [opts.includeScore=true] - Whether to include the score of the match in the results.
497
+ * @param {number} [opts.threshold=0.6] - Determines the match threshold; lower values mean stricter matching.
498
+ * @param {boolean} [opts.caseSensitive=false] - Whether the search should be case-sensitive.
499
+ * @param {number} [opts.distance=100] - Determines how far apart the search term is allowed to be from the target.
500
+ * @param {number} [opts.maxPatternLength=32] - The maximum length of the search pattern. Patterns longer than this are ignored.
501
+ * @param {boolean} [opts.ignoreLocation=false] - Whether the location of the match is ignored when scoring.
502
+ * @param {boolean} [opts.ignoreFieldNorm=false] - When true, the field's length is not considered when scoring.
503
+ * @param {Array<string>} [opts.keys=[]] - List of keys to search in the objects of the source array.
504
+ * @param {boolean} [opts.shouldSort=true] - Whether the results should be sorted by score.
505
+ * @param {string} [opts.sortFn] - A custom sorting function for sorting results.
506
+ * @param {number} [opts.minMatchCharLength=1] - The minimum number of characters that must match.
507
+ * @param {boolean} [opts.useExtendedSearch=false] - Enables extended search capabilities.
508
+ *
509
+ * @returns {Array<Object>} - An array of search results. Each result contains an item and, if `includeScore` is true, a score.
510
+ *
511
+ * @example
512
+ * const data = [
513
+ * { title: "Old Man's War", author: "John Scalzi" },
514
+ * { title: "The Lock Artist", author: "Steve Hamilton" },
515
+ * ];
516
+ *
517
+ * const options = {
518
+ * keys: ['title', 'author'],
519
+ * includeScore: true,
520
+ * threshold: 0.4,
521
+ * caseSensitive: false,
522
+ * distance: 50,
523
+ * ignoreLocation: true,
524
+ * };
525
+ *
526
+ * const results = searchWithFusejs(data, 'lock', options);
527
+ * console.log(results);
528
+ */
529
+ module.exports.searchWithFusejs = function (source, searchString, opts) {
530
+ const fuse = new Fuse(source, opts)
531
+
532
+ return fuse.search(searchString)
533
+ }
534
+
535
+ module.exports.humanizeString = function (string) {
536
+ // split strings by words, then make them all lowercase
537
+ const _result = string
538
+ .replace(/([a-z](?=[A-Z]))/g, '$1 ')
539
+ .split(' ')
540
+ .map(word => word.toLowerCase())
541
+
542
+ _result[0] = _result[0] === 'i' ? this.ucfirst(_result[0]) : _result[0]
543
+ return _result.join(' ').trim()
544
+ }
package/lib/within.js CHANGED
@@ -3,7 +3,7 @@ const store = require('./store')
3
3
  const recorder = require('./recorder')
4
4
  const container = require('./container')
5
5
  const event = require('./event')
6
- const Step = require('./step')
6
+ const MetaStep = require('./step/meta')
7
7
  const { isAsyncFunction } = require('./utils')
8
8
 
9
9
  /**
@@ -76,7 +76,7 @@ function within(context, fn) {
76
76
 
77
77
  module.exports = within
78
78
 
79
- class WithinStep extends Step.MetaStep {
79
+ class WithinStep extends MetaStep {
80
80
  constructor(locator, fn) {
81
81
  super('Within')
82
82
  this.args = [locator]
package/lib/workers.js CHANGED
@@ -1,11 +1,6 @@
1
1
  const path = require('path')
2
2
  const mkdirp = require('mkdirp')
3
3
  const { Worker } = require('worker_threads')
4
- const {
5
- Suite,
6
- Test,
7
- reporters: { Base },
8
- } = require('mocha')
9
4
  const { EventEmitter } = require('events')
10
5
  const ms = require('ms')
11
6
  const Codecept = require('./codecept')
@@ -17,6 +12,7 @@ const { replaceValueDeep, deepClone } = require('./utils')
17
12
  const mainConfig = require('./config')
18
13
  const output = require('./output')
19
14
  const event = require('./event')
15
+ const { repackTestForWorkersTransport: repackTest } = require('./mocha/test')
20
16
  const recorder = require('./recorder')
21
17
  const runHook = require('./hooks')
22
18
  const WorkerStorage = require('./workerStorage')
@@ -78,12 +74,6 @@ const simplifyObject = object => {
78
74
  }, {})
79
75
  }
80
76
 
81
- const repackTest = test => {
82
- test = Object.assign(new Test(test.title || '', () => {}), test)
83
- test.parent = Object.assign(new Suite(test.parent.title), test.parent)
84
- return test
85
- }
86
-
87
77
  const createWorkerObjects = (testGroups, config, testRoot, options, selectedRuns) => {
88
78
  selectedRuns = options && options.all && config.multiple ? Object.keys(config.multiple) : selectedRuns
89
79
  if (selectedRuns === undefined || !selectedRuns.length || config.multiple === undefined) {
@@ -459,7 +449,7 @@ class Workers extends EventEmitter {
459
449
  }
460
450
 
461
451
  _finishRun() {
462
- event.dispatcher.emit(event.workers.after)
452
+ event.dispatcher.emit(event.workers.after, { tests: this.workers.map(worker => worker.tests) })
463
453
  if (this.isFailed()) {
464
454
  process.exitCode = 1
465
455
  } else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codeceptjs",
3
- "version": "3.7.0-beta.3",
3
+ "version": "3.7.0-beta.5",
4
4
  "description": "Supercharged End 2 End Testing Framework for NodeJS",
5
5
  "keywords": [
6
6
  "acceptance",
@@ -31,7 +31,9 @@
31
31
  "main": "lib/index.js",
32
32
  "exports": {
33
33
  ".": "./lib/index.js",
34
- "./els": "./lib/els.js"
34
+ "./els": "./lib/els.js",
35
+ "./effects": "./lib/effects.js",
36
+ "./steps": "./lib/steps.js"
35
37
  },
36
38
  "types": "typings/index.d.ts",
37
39
  "bin": {
@@ -114,14 +116,14 @@
114
116
  "uuid": "11.0.4"
115
117
  },
116
118
  "optionalDependencies": {
117
- "@codeceptjs/detox-helper": "1.1.4"
119
+ "@codeceptjs/detox-helper": "1.1.5"
118
120
  },
119
121
  "devDependencies": {
120
122
  "@apollo/server": "^4",
121
123
  "@codeceptjs/expect-helper": "^0.2.2",
122
124
  "@codeceptjs/mock-request": "0.3.1",
123
125
  "@eslint/eslintrc": "3.2.0",
124
- "@eslint/js": "9.17.0",
126
+ "@eslint/js": "9.18.0",
125
127
  "@faker-js/faker": "9.3.0",
126
128
  "@pollyjs/adapter-puppeteer": "6.0.6",
127
129
  "@pollyjs/core": "5.1.0",
@@ -166,7 +168,7 @@
166
168
  "tsd-jsdoc": "2.5.0",
167
169
  "typedoc": "0.27.6",
168
170
  "typedoc-plugin-markdown": "4.4.1",
169
- "typescript": "5.7.2",
171
+ "typescript": "5.7.3",
170
172
  "wdio-docker-service": "1.5.0",
171
173
  "webdriverio": "^9.5.1",
172
174
  "xml2js": "0.6.2",
@@ -451,9 +451,6 @@ declare namespace CodeceptJS {
451
451
  }
452
452
 
453
453
  // Extending JSDoc generated typings
454
- interface Step {
455
- isMetaStep(): this is MetaStep
456
- }
457
454
 
458
455
  // Types who are not be defined by JSDoc
459
456
  type actor = <T extends { [action: string]: (...args: any[]) => void }>(customSteps?: T & ThisType<WithTranslation<Methods & T>>) => WithTranslation<Methods & T>
@@ -502,7 +499,7 @@ declare namespace CodeceptJS {
502
499
  (title: string, opts: { [key: string]: any }, callback: HookCallback): ScenarioConfig
503
500
  }
504
501
  interface IHook {
505
- (callback: HookCallback): void
502
+ (callback: HookCallback): HookConfig
506
503
  }
507
504
 
508
505
  interface Globals {
@@ -516,6 +513,10 @@ declare namespace CodeceptJS {
516
513
  useForSnippets?: boolean
517
514
  preferForRegexpMatch?: boolean
518
515
  }
516
+
517
+ interface HookConfig {
518
+ retry(retries?: number): HookConfig
519
+ }
519
520
  }
520
521
 
521
522
  // Globals
@@ -608,17 +608,11 @@ declare namespace CodeceptJS {
608
608
  * ```js
609
609
  * // taps outside to hide keyboard per default
610
610
  * I.hideDeviceKeyboard();
611
- * I.hideDeviceKeyboard('tapOutside');
612
- *
613
- * // or by pressing key
614
- * I.hideDeviceKeyboard('pressKey', 'Done');
615
611
  * ```
616
612
  *
617
613
  * Appium: support Android and iOS
618
- * @param [strategy] - Desired strategy to close keyboard (‘tapOutside’ or ‘pressKey’)
619
- * @param [key] - Optional key
620
614
  */
621
- hideDeviceKeyboard(strategy?: 'tapOutside' | 'pressKey', key?: string): Promise<any>;
615
+ hideDeviceKeyboard(): Promise<any>;
622
616
  /**
623
617
  * Send a key event to the device.
624
618
  * List of keys: https://developer.android.com/reference/android/view/KeyEvent.html
@@ -1775,11 +1769,6 @@ declare namespace CodeceptJS {
1775
1769
  // @ts-ignore
1776
1770
  // @ts-ignore
1777
1771
  // @ts-ignore
1778
- // @ts-ignore
1779
- // @ts-ignore
1780
- // @ts-ignore
1781
- // @ts-ignore
1782
- // @ts-ignore
1783
1772
  type MockServerConfig = {
1784
1773
  port?: number;
1785
1774
  host?: string;
@@ -1914,11 +1903,6 @@ declare namespace CodeceptJS {
1914
1903
  // @ts-ignore
1915
1904
  // @ts-ignore
1916
1905
  // @ts-ignore
1917
- // @ts-ignore
1918
- // @ts-ignore
1919
- // @ts-ignore
1920
- // @ts-ignore
1921
- // @ts-ignore
1922
1906
  class MockServer {
1923
1907
  /**
1924
1908
  * Start the mock server
@@ -2962,11 +2946,6 @@ declare namespace CodeceptJS {
2962
2946
  // @ts-ignore
2963
2947
  // @ts-ignore
2964
2948
  // @ts-ignore
2965
- // @ts-ignore
2966
- // @ts-ignore
2967
- // @ts-ignore
2968
- // @ts-ignore
2969
- // @ts-ignore
2970
2949
  type PlaywrightConfig = {
2971
2950
  url?: string;
2972
2951
  browser?: 'chromium' | 'firefox' | 'webkit' | 'electron';
@@ -6353,11 +6332,6 @@ declare namespace CodeceptJS {
6353
6332
  // @ts-ignore
6354
6333
  // @ts-ignore
6355
6334
  // @ts-ignore
6356
- // @ts-ignore
6357
- // @ts-ignore
6358
- // @ts-ignore
6359
- // @ts-ignore
6360
- // @ts-ignore
6361
6335
  type PuppeteerConfig = {
6362
6336
  url: string;
6363
6337
  basicAuth?: any;
@@ -8174,11 +8148,6 @@ declare namespace CodeceptJS {
8174
8148
  // @ts-ignore
8175
8149
  // @ts-ignore
8176
8150
  // @ts-ignore
8177
- // @ts-ignore
8178
- // @ts-ignore
8179
- // @ts-ignore
8180
- // @ts-ignore
8181
- // @ts-ignore
8182
8151
  type RESTConfig = {
8183
8152
  endpoint?: string;
8184
8153
  prettyPrintJson?: boolean;
@@ -9333,11 +9302,6 @@ declare namespace CodeceptJS {
9333
9302
  // @ts-ignore
9334
9303
  // @ts-ignore
9335
9304
  // @ts-ignore
9336
- // @ts-ignore
9337
- // @ts-ignore
9338
- // @ts-ignore
9339
- // @ts-ignore
9340
- // @ts-ignore
9341
9305
  type WebDriverConfig = {
9342
9306
  url: string;
9343
9307
  browser: string;
@@ -608,17 +608,11 @@ declare namespace CodeceptJS {
608
608
  * ```js
609
609
  * // taps outside to hide keyboard per default
610
610
  * I.hideDeviceKeyboard();
611
- * I.hideDeviceKeyboard('tapOutside');
612
- *
613
- * // or by pressing key
614
- * I.hideDeviceKeyboard('pressKey', 'Done');
615
611
  * ```
616
612
  *
617
613
  * Appium: support Android and iOS
618
- * @param [strategy] - Desired strategy to close keyboard (‘tapOutside’ or ‘pressKey’)
619
- * @param [key] - Optional key
620
614
  */
621
- hideDeviceKeyboard(strategy?: 'tapOutside' | 'pressKey', key?: string): void;
615
+ hideDeviceKeyboard(): void;
622
616
  /**
623
617
  * Send a key event to the device.
624
618
  * List of keys: https://developer.android.com/reference/android/view/KeyEvent.html
@@ -1802,11 +1796,6 @@ declare namespace CodeceptJS {
1802
1796
  // @ts-ignore
1803
1797
  // @ts-ignore
1804
1798
  // @ts-ignore
1805
- // @ts-ignore
1806
- // @ts-ignore
1807
- // @ts-ignore
1808
- // @ts-ignore
1809
- // @ts-ignore
1810
1799
  type MockServerConfig = {
1811
1800
  port?: number;
1812
1801
  host?: string;
@@ -1941,11 +1930,6 @@ declare namespace CodeceptJS {
1941
1930
  // @ts-ignore
1942
1931
  // @ts-ignore
1943
1932
  // @ts-ignore
1944
- // @ts-ignore
1945
- // @ts-ignore
1946
- // @ts-ignore
1947
- // @ts-ignore
1948
- // @ts-ignore
1949
1933
  class MockServer {
1950
1934
  /**
1951
1935
  * Start the mock server
@@ -3055,11 +3039,6 @@ declare namespace CodeceptJS {
3055
3039
  // @ts-ignore
3056
3040
  // @ts-ignore
3057
3041
  // @ts-ignore
3058
- // @ts-ignore
3059
- // @ts-ignore
3060
- // @ts-ignore
3061
- // @ts-ignore
3062
- // @ts-ignore
3063
3042
  type PlaywrightConfig = {
3064
3043
  url?: string;
3065
3044
  browser?: 'chromium' | 'firefox' | 'webkit' | 'electron';
@@ -6597,11 +6576,6 @@ declare namespace CodeceptJS {
6597
6576
  // @ts-ignore
6598
6577
  // @ts-ignore
6599
6578
  // @ts-ignore
6600
- // @ts-ignore
6601
- // @ts-ignore
6602
- // @ts-ignore
6603
- // @ts-ignore
6604
- // @ts-ignore
6605
6579
  type PuppeteerConfig = {
6606
6580
  url: string;
6607
6581
  basicAuth?: any;
@@ -8554,11 +8528,6 @@ declare namespace CodeceptJS {
8554
8528
  // @ts-ignore
8555
8529
  // @ts-ignore
8556
8530
  // @ts-ignore
8557
- // @ts-ignore
8558
- // @ts-ignore
8559
- // @ts-ignore
8560
- // @ts-ignore
8561
- // @ts-ignore
8562
8531
  type RESTConfig = {
8563
8532
  endpoint?: string;
8564
8533
  prettyPrintJson?: boolean;
@@ -9773,11 +9742,6 @@ declare namespace CodeceptJS {
9773
9742
  // @ts-ignore
9774
9743
  // @ts-ignore
9775
9744
  // @ts-ignore
9776
- // @ts-ignore
9777
- // @ts-ignore
9778
- // @ts-ignore
9779
- // @ts-ignore
9780
- // @ts-ignore
9781
9745
  type WebDriverConfig = {
9782
9746
  url: string;
9783
9747
  browser: string;
@@ -12213,24 +12177,49 @@ declare namespace CodeceptJS {
12213
12177
  function session(sessionName: CodeceptJS.LocatorOrString, config: ((...params: any[]) => any) | {
12214
12178
  [key: string]: any;
12215
12179
  }, fn?: (...params: any[]) => any): any;
12180
+ /**
12181
+ * StepConfig is a configuration object for a step.
12182
+ * It is used to create a new step that is a combination of other steps.
12183
+ */
12184
+ class StepConfig {
12185
+ config: any;
12186
+ /**
12187
+ * Set the options for the step.
12188
+ * @param opts - The options for the step.
12189
+ * @returns - The step configuration object.
12190
+ */
12191
+ opts(opts: any): StepConfig;
12192
+ /**
12193
+ * Set the timeout for the step.
12194
+ * @param timeout - The timeout for the step.
12195
+ * @returns - The step configuration object.
12196
+ */
12197
+ timeout(timeout: number): StepConfig;
12198
+ /**
12199
+ * Set the retry for the step.
12200
+ * @param retry - The retry for the step.
12201
+ * @returns - The step configuration object.
12202
+ */
12203
+ retry(retry: number): StepConfig;
12204
+ }
12216
12205
  /**
12217
12206
  * Each command in test executed through `I.` object is wrapped in Step.
12218
12207
  * Step allows logging executed commands and triggers hook before and after step execution.
12219
12208
  */
12220
12209
  class Step {
12221
- constructor(helper: CodeceptJS.Helper, name: string);
12222
- actor: string;
12223
- helper: CodeceptJS.Helper;
12210
+ constructor(name: string);
12224
12211
  name: string;
12212
+ timeouts: Map<number, number>;
12213
+ args: any[];
12214
+ opts: Record<string, any>;
12215
+ actor: string;
12225
12216
  helperMethod: string;
12226
12217
  status: string;
12227
- suffix: string;
12228
12218
  prefix: string;
12229
12219
  comment: string;
12230
- args: any[];
12231
- metaStep: MetaStep;
12220
+ metaStep: any;
12232
12221
  stack: string;
12233
- getTimeout(): number | undefined;
12222
+ timeout: any;
12234
12223
  /**
12235
12224
  * @param timeout - timeout in milliseconds or 0 if no timeout
12236
12225
  * @param order - order defines the priority of timeout, timeouts set with lower order override those set with higher order.
@@ -12239,7 +12228,6 @@ declare namespace CodeceptJS {
12239
12228
  setTimeout(timeout: number, order: number): void;
12240
12229
  setTrace(): void;
12241
12230
  setArguments(args: any[]): void;
12242
- run(...args: any[]): any;
12243
12231
  setStatus(status: string): void;
12244
12232
  humanize(): string;
12245
12233
  humanizeArgs(): string;
@@ -12248,11 +12236,6 @@ declare namespace CodeceptJS {
12248
12236
  toCliStyled(): string;
12249
12237
  toCode(): string;
12250
12238
  hasBDDAncestor(): boolean;
12251
- static MetaStep: typeof MetaStep;
12252
- }
12253
- class MetaStep extends Step {
12254
- isBDD(): boolean;
12255
- run(): any;
12256
12239
  }
12257
12240
  /**
12258
12241
  * global values for current session
@@ -12261,7 +12244,9 @@ declare namespace CodeceptJS {
12261
12244
  var debugMode: boolean;
12262
12245
  var timeouts: boolean;
12263
12246
  var dryRun: boolean;
12247
+ var onPause: boolean;
12264
12248
  var currentTest: CodeceptJS.Test | null;
12249
+ var currentStep: any;
12265
12250
  }
12266
12251
  /**
12267
12252
  * Describe a "suite" with the given `title`
@@ -12954,22 +12939,12 @@ declare namespace CodeceptJS {
12954
12939
  }
12955
12940
 
12956
12941
  /**
12957
- * timeouts set with order below zero only override timeouts of higher order if their value is smaller
12958
- */
12959
- declare var testOrSuite: any;
12960
-
12961
- /**
12962
- * 0-9 - designated for override of timeouts set from code, 5 is used by stepTimeout plugin when stepTimeout.config.overrideStepLimits=true
12963
- */
12964
- declare var stepTimeoutHard: any;
12965
-
12966
- /**
12967
- * 10-19 - designated for timeouts set from code, 15 is order of I.setTimeout(t) operation
12942
+ * corresponding helper
12968
12943
  */
12969
- declare var codeLimitTime: any;
12944
+ declare var helper: CodeceptJS.Helper;
12970
12945
 
12971
12946
  /**
12972
- * 20-29 - designated for timeout settings which could be overriden in tests code, 25 is used by stepTimeout plugin when stepTimeout.config.overrideStepLimits=false
12947
+ * name of method to be executed
12973
12948
  */
12974
- declare var stepTimeoutSoft: any;
12949
+ declare var helperMethod: string;
12975
12950