codeceptjs 4.0.0-beta.1 → 4.0.0-beta.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 (151) hide show
  1. package/bin/codecept.js +84 -81
  2. package/lib/actor.js +13 -13
  3. package/lib/ai.js +10 -13
  4. package/lib/assert/empty.js +20 -21
  5. package/lib/assert/equal.js +37 -39
  6. package/lib/assert/error.js +14 -14
  7. package/lib/assert/include.js +46 -47
  8. package/lib/assert/throws.js +13 -11
  9. package/lib/assert/truth.js +19 -22
  10. package/lib/assert.js +4 -2
  11. package/lib/cli.js +57 -49
  12. package/lib/codecept.js +142 -155
  13. package/lib/colorUtils.js +3 -3
  14. package/lib/command/configMigrate.js +58 -52
  15. package/lib/command/definitions.js +88 -89
  16. package/lib/command/dryRun.js +71 -68
  17. package/lib/command/generate.js +197 -188
  18. package/lib/command/gherkin/init.js +27 -16
  19. package/lib/command/gherkin/snippets.js +20 -20
  20. package/lib/command/gherkin/steps.js +8 -8
  21. package/lib/command/info.js +40 -38
  22. package/lib/command/init.js +290 -288
  23. package/lib/command/interactive.js +32 -32
  24. package/lib/command/list.js +26 -26
  25. package/lib/command/run-multiple/chunk.js +5 -5
  26. package/lib/command/run-multiple/collection.js +3 -3
  27. package/lib/command/run-multiple/run.js +6 -2
  28. package/lib/command/run-multiple.js +113 -93
  29. package/lib/command/run-rerun.js +20 -25
  30. package/lib/command/run-workers.js +64 -66
  31. package/lib/command/run.js +26 -29
  32. package/lib/command/utils.js +80 -65
  33. package/lib/command/workers/runTests.js +10 -10
  34. package/lib/config.js +10 -9
  35. package/lib/container.js +40 -48
  36. package/lib/data/context.js +60 -59
  37. package/lib/data/dataScenarioConfig.js +47 -47
  38. package/lib/data/dataTableArgument.js +29 -29
  39. package/lib/data/table.js +26 -20
  40. package/lib/event.js +163 -167
  41. package/lib/heal.js +13 -17
  42. package/lib/helper/AI.js +130 -41
  43. package/lib/helper/ApiDataFactory.js +73 -69
  44. package/lib/helper/Appium.js +413 -382
  45. package/lib/helper/ExpectHelper.js +40 -48
  46. package/lib/helper/FileSystem.js +80 -79
  47. package/lib/helper/GraphQL.js +44 -43
  48. package/lib/helper/GraphQLDataFactory.js +50 -50
  49. package/lib/helper/JSONResponse.js +65 -62
  50. package/lib/helper/Mochawesome.js +28 -28
  51. package/lib/helper/MockServer.js +12 -14
  52. package/lib/helper/Nightmare.js +662 -566
  53. package/lib/helper/Playwright.js +1361 -1216
  54. package/lib/helper/Protractor.js +663 -627
  55. package/lib/helper/Puppeteer.js +1231 -1128
  56. package/lib/helper/REST.js +159 -68
  57. package/lib/helper/SoftExpectHelper.js +2 -2
  58. package/lib/helper/TestCafe.js +490 -484
  59. package/lib/helper/WebDriver.js +1297 -1156
  60. package/lib/helper/clientscripts/PollyWebDriverExt.js +1 -1
  61. package/lib/helper/errors/ConnectionRefused.js +1 -1
  62. package/lib/helper/errors/ElementAssertion.js +2 -2
  63. package/lib/helper/errors/ElementNotFound.js +2 -2
  64. package/lib/helper/errors/RemoteBrowserConnectionRefused.js +1 -1
  65. package/lib/helper/extras/Console.js +1 -1
  66. package/lib/helper/extras/PlaywrightPropEngine.js +2 -2
  67. package/lib/helper/extras/PlaywrightReactVueLocator.js +1 -1
  68. package/lib/helper/extras/PlaywrightRestartOpts.js +21 -18
  69. package/lib/helper/extras/Popup.js +1 -1
  70. package/lib/helper/extras/React.js +3 -3
  71. package/lib/helper/network/actions.js +14 -7
  72. package/lib/helper/network/utils.js +3 -2
  73. package/lib/helper/scripts/blurElement.js +1 -1
  74. package/lib/helper/scripts/focusElement.js +1 -1
  75. package/lib/helper/scripts/highlightElement.js +1 -1
  76. package/lib/helper/scripts/isElementClickable.js +1 -1
  77. package/lib/helper/testcafe/testControllerHolder.js +1 -1
  78. package/lib/helper/testcafe/testcafe-utils.js +6 -7
  79. package/lib/helper.js +1 -3
  80. package/lib/history.js +6 -5
  81. package/lib/hooks.js +6 -6
  82. package/lib/html.js +7 -7
  83. package/lib/index.js +25 -41
  84. package/lib/interfaces/bdd.js +47 -64
  85. package/lib/interfaces/featureConfig.js +19 -19
  86. package/lib/interfaces/gherkin.js +124 -118
  87. package/lib/interfaces/scenarioConfig.js +29 -29
  88. package/lib/listener/artifacts.js +9 -9
  89. package/lib/listener/config.js +24 -24
  90. package/lib/listener/exit.js +12 -12
  91. package/lib/listener/helpers.js +42 -42
  92. package/lib/listener/mocha.js +11 -11
  93. package/lib/listener/retry.js +32 -30
  94. package/lib/listener/steps.js +50 -53
  95. package/lib/listener/timeout.js +54 -54
  96. package/lib/locator.js +6 -10
  97. package/lib/mochaFactory.js +18 -15
  98. package/lib/output.js +6 -10
  99. package/lib/parser.js +15 -12
  100. package/lib/pause.js +40 -33
  101. package/lib/plugin/allure.js +15 -15
  102. package/lib/plugin/autoDelay.js +29 -37
  103. package/lib/plugin/autoLogin.js +70 -65
  104. package/lib/plugin/commentStep.js +18 -18
  105. package/lib/plugin/coverage.js +115 -67
  106. package/lib/plugin/customLocator.js +21 -20
  107. package/lib/plugin/debugErrors.js +24 -24
  108. package/lib/plugin/eachElement.js +38 -38
  109. package/lib/plugin/fakerTransform.js +6 -6
  110. package/lib/plugin/heal.js +67 -108
  111. package/lib/plugin/pauseOnFail.js +11 -11
  112. package/lib/plugin/retryFailedStep.js +32 -39
  113. package/lib/plugin/retryTo.js +46 -40
  114. package/lib/plugin/screenshotOnFail.js +109 -87
  115. package/lib/plugin/selenoid.js +131 -118
  116. package/lib/plugin/standardActingHelpers.js +2 -8
  117. package/lib/plugin/stepByStepReport.js +110 -91
  118. package/lib/plugin/stepTimeout.js +24 -23
  119. package/lib/plugin/subtitles.js +34 -35
  120. package/lib/plugin/tryTo.js +40 -30
  121. package/lib/plugin/wdio.js +78 -75
  122. package/lib/recorder.js +14 -17
  123. package/lib/rerun.js +11 -10
  124. package/lib/scenario.js +25 -23
  125. package/lib/secret.js +4 -2
  126. package/lib/session.js +10 -10
  127. package/lib/step.js +12 -9
  128. package/lib/store.js +2 -3
  129. package/lib/transform.js +1 -1
  130. package/lib/translation.js +7 -8
  131. package/lib/ui.js +12 -14
  132. package/lib/utils.js +70 -72
  133. package/lib/within.js +10 -10
  134. package/lib/workerStorage.js +27 -25
  135. package/lib/workers.js +29 -32
  136. package/package.json +56 -57
  137. package/translations/de-DE.js +1 -1
  138. package/translations/fr-FR.js +1 -1
  139. package/translations/index.js +9 -13
  140. package/translations/it-IT.js +1 -1
  141. package/translations/ja-JP.js +1 -1
  142. package/translations/pl-PL.js +1 -1
  143. package/translations/pt-BR.js +1 -1
  144. package/translations/ru-RU.js +1 -1
  145. package/translations/zh-CN.js +1 -1
  146. package/translations/zh-TW.js +1 -1
  147. package/typings/index.d.ts +415 -65
  148. package/typings/promiseBasedTypes.d.ts +32 -0
  149. package/typings/types.d.ts +32 -0
  150. package/lib/dirname.js +0 -5
  151. package/lib/helper/Expect.js +0 -425
package/bin/codecept.js CHANGED
@@ -1,26 +1,8 @@
1
1
  #!/usr/bin/env node
2
- import { Command } from 'commander';
3
- import { version } from '../lib/codecept.js';
4
- import * as outputLib from '../lib/output.js';
5
- import { printError } from '../lib/command/utils.js';
6
- import * as init from '../lib/command/init.js';
7
- import * as configMigrate from '../lib/command/configMigrate.js';
8
- import * as interactive from '../lib/command/interactive.js';
9
- import * as definitions from '../lib/command/definitions.js';
10
- import * as list from '../lib/command/list.js';
11
- import * as gherkinInit from '../lib/command/gherkin/init.js';
12
- import * as gherkinSteps from '../lib/command/gherkin/steps.js';
13
- import * as gherkinSnippets from '../lib/command/gherkin/snippets.js';
14
- import * as generate from '../lib/command/generate.js';
15
- import * as run from '../lib/command/run.js';
16
- import * as runWorkers from '../lib/command/run-workers.js';
17
- import * as runMultiple from '../lib/command/run-multiple.js';
18
- import { runRerun } from '../lib/command/run-rerun.js';
19
- import * as dryRun from '../lib/command/dryRun.js';
20
- import * as info from '../lib/command/info.js';
21
- import { heal } from "../lib/command/generate.js";
22
-
23
- const program = new Command();
2
+ const program = require('commander')
3
+ const Codecept = require('../lib/codecept')
4
+ const { print, error } = require('../lib/output')
5
+ const { printError } = require('../lib/command/utils')
24
6
 
25
7
  const commandFlags = {
26
8
  ai: {
@@ -47,104 +29,120 @@ const commandFlags = {
47
29
  flag: '--steps',
48
30
  description: 'show step-by-step execution',
49
31
  },
50
- };
51
-
52
- const errorHandler = (fn) => async (...args) => {
53
- try {
54
- await fn.default(...args);
55
- } catch (e) {
56
- printError(e);
57
- process.exitCode = 1;
32
+ }
33
+
34
+ const errorHandler =
35
+ (fn) =>
36
+ async (...args) => {
37
+ try {
38
+ await fn(...args)
39
+ } catch (e) {
40
+ printError(e)
41
+ process.exitCode = 1
42
+ }
58
43
  }
59
- };
60
44
 
61
45
  if (process.versions.node && process.versions.node.split('.') && process.versions.node.split('.')[0] < 12) {
62
- outputLib.output.output.error('NodeJS >= 12 is required to run.');
63
- outputLib.print();
64
- outputLib.print('Please upgrade your NodeJS engine');
65
- outputLib.print(`Current NodeJS version: ${process.version}`);
66
- process.exit(1);
46
+ error('NodeJS >= 12 is required to run.')
47
+ print()
48
+ print('Please upgrade your NodeJS engine')
49
+ print(`Current NodeJS version: ${process.version}`)
50
+ process.exit(1)
67
51
  }
68
52
 
69
- program.usage('<command> [options]');
70
- program.version(version());
53
+ program.usage('<command> [options]')
54
+ program.version(Codecept.version())
71
55
 
72
- program.command('init [path]')
56
+ program
57
+ .command('init [path]')
73
58
  .description('Creates dummy config in current dir or [path]')
74
- .action(errorHandler(init));
59
+ .action(errorHandler(require('../lib/command/init')))
75
60
 
76
- program.command('migrate [path]')
61
+ program
62
+ .command('migrate [path]')
77
63
  .description('Migrate json config to js config in current dir or [path]')
78
- .action(errorHandler(configMigrate));
64
+ .action(errorHandler(require('../lib/command/configMigrate')))
79
65
 
80
- program.command('shell [path]')
66
+ program
67
+ .command('shell [path]')
81
68
  .alias('sh')
82
69
  .description('Interactive shell')
83
70
  .option(commandFlags.verbose.flag, commandFlags.verbose.description)
84
71
  .option(commandFlags.profile.flag, commandFlags.profile.description)
85
72
  .option(commandFlags.ai.flag, commandFlags.ai.description)
86
73
  .option(commandFlags.config.flag, commandFlags.config.description)
87
- .action(errorHandler(interactive));
74
+ .action(errorHandler(require('../lib/command/interactive')))
88
75
 
89
- program.command('list [path]')
76
+ program
77
+ .command('list [path]')
90
78
  .alias('l')
91
79
  .description('List all actions for I.')
92
- .action(errorHandler(list));
80
+ .action(errorHandler(require('../lib/command/list')))
93
81
 
94
- program.command('def [path]')
82
+ program
83
+ .command('def [path]')
95
84
  .description('Generates TypeScript definitions for all I actions.')
96
85
  .option(commandFlags.config.flag, commandFlags.config.description)
97
86
  .option('-o, --output [folder]', 'target folder to paste definitions')
98
- .action(errorHandler(definitions));
87
+ .action(errorHandler(require('../lib/command/definitions')))
99
88
 
100
- program.command('gherkin:init [path]')
89
+ program
90
+ .command('gherkin:init [path]')
101
91
  .alias('bdd:init')
102
92
  .description('Prepare CodeceptJS to run feature files.')
103
93
  .option(commandFlags.config.flag, commandFlags.config.description)
104
- .action(errorHandler(gherkinInit));
94
+ .action(errorHandler(require('../lib/command/gherkin/init')))
105
95
 
106
- program.command('gherkin:steps [path]')
96
+ program
97
+ .command('gherkin:steps [path]')
107
98
  .alias('bdd:steps')
108
99
  .description('Prints all defined gherkin steps.')
109
100
  .option(commandFlags.config.flag, commandFlags.config.description)
110
- .action(errorHandler(gherkinSteps));
101
+ .action(errorHandler(require('../lib/command/gherkin/steps')))
111
102
 
112
- program.command('gherkin:snippets [path]')
103
+ program
104
+ .command('gherkin:snippets [path]')
113
105
  .alias('bdd:snippets')
114
106
  .description('Generate step definitions from steps.')
115
107
  .option('--dry-run', "don't save snippets to file")
116
108
  .option(commandFlags.config.flag, commandFlags.config.description)
117
109
  .option('--feature [file]', 'feature files(s) to scan')
118
110
  .option('--path [file]', 'file in which to place the new snippets')
119
- .action(errorHandler(gherkinSnippets));
111
+ .action(errorHandler(require('../lib/command/gherkin/snippets')))
120
112
 
121
- program.command('generate:test [path]')
113
+ program
114
+ .command('generate:test [path]')
122
115
  .alias('gt')
123
116
  .description('Generates an empty test')
124
- .action(errorHandler(generate.test));
117
+ .action(errorHandler(require('../lib/command/generate').test))
125
118
 
126
- program.command('generate:pageobject [path]')
119
+ program
120
+ .command('generate:pageobject [path]')
127
121
  .alias('gpo')
128
122
  .description('Generates an empty page object')
129
- .action(errorHandler(generate.pageObject));
123
+ .action(errorHandler(require('../lib/command/generate').pageObject))
130
124
 
131
- program.command('generate:object [path]')
125
+ program
126
+ .command('generate:object [path]')
132
127
  .alias('go')
133
128
  .option('--type, -t [kind]', 'type of object to be created')
134
129
  .description('Generates an empty support object (page/step/fragment)')
135
- .action(errorHandler(generate.pageObject));
130
+ .action(errorHandler(require('../lib/command/generate').pageObject))
136
131
 
137
- program.command('generate:helper [path]')
132
+ program
133
+ .command('generate:helper [path]')
138
134
  .alias('gh')
139
135
  .description('Generates a new helper')
140
- .action(errorHandler(generate.helper));
136
+ .action(errorHandler(require('../lib/command/generate').helper))
141
137
 
142
- program.command('generate:heal [path]')
138
+ program
139
+ .command('generate:heal [path]')
143
140
  .alias('gr')
144
141
  .description('Generates basic heal recipes')
145
- .action(errorHandler(heal));
142
+ .action(errorHandler(require('../lib/command/generate').heal))
146
143
 
147
- program.command('run [test]')
144
+ program
145
+ .command('run [test]')
148
146
  .description('Executes tests')
149
147
 
150
148
  // codecept-only options
@@ -180,9 +178,10 @@ program.command('run [test]')
180
178
  .option('--recursive', 'include sub directories')
181
179
  .option('--trace', 'trace function calls')
182
180
  .option('--child <string>', 'option for child processes')
183
- .action(errorHandler(run));
181
+ .action(errorHandler(require('../lib/command/run')))
184
182
 
185
- program.command('run-workers <workers> [selectedRuns...]')
183
+ program
184
+ .command('run-workers <workers> [selectedRuns...]')
186
185
  .description('Executes tests in workers')
187
186
  .option(commandFlags.config.flag, commandFlags.config.description)
188
187
  .option('-g, --grep <pattern>', 'only run tests matching <pattern>')
@@ -198,9 +197,10 @@ program.command('run-workers <workers> [selectedRuns...]')
198
197
  .option('-p, --plugins <k=v,k2=v2,...>', 'enable plugins, comma-separated')
199
198
  .option('-O, --reporter-options <k=v,k2=v2,...>', 'reporter-specific options')
200
199
  .option('-R, --reporter <name>', 'specify the reporter to use')
201
- .action(errorHandler(runWorkers));
200
+ .action(errorHandler(require('../lib/command/run-workers')))
202
201
 
203
- program.command('run-multiple [suites...]')
202
+ program
203
+ .command('run-multiple [suites...]')
204
204
  .description('Executes tests multiple')
205
205
  .option(commandFlags.config.flag, commandFlags.config.description)
206
206
  .option(commandFlags.profile.flag, commandFlags.profile.description)
@@ -223,14 +223,16 @@ program.command('run-multiple [suites...]')
223
223
  // mocha options
224
224
  .option('--colors', 'force enabling of colors')
225
225
 
226
- .action(errorHandler(runMultiple));
226
+ .action(errorHandler(require('../lib/command/run-multiple')))
227
227
 
228
- program.command('info [path]')
228
+ program
229
+ .command('info [path]')
229
230
  .description('Print debugging information concerning the local environment')
230
231
  .option('-c, --config', 'your config file path')
231
- .action(errorHandler(info));
232
+ .action(errorHandler(require('../lib/command/info')))
232
233
 
233
- program.command('dry-run [test]')
234
+ program
235
+ .command('dry-run [test]')
234
236
  .description('Prints step-by-step scenario for a test without actually running it')
235
237
  .option('-p, --plugins <k=v,k2=v2,...>', 'enable plugins, comma-separated')
236
238
  .option('--bootstrap', 'enable bootstrap & teardown scripts for dry-run')
@@ -244,9 +246,10 @@ program.command('dry-run [test]')
244
246
  .option(commandFlags.steps.flag, commandFlags.steps.description)
245
247
  .option(commandFlags.verbose.flag, commandFlags.verbose.description)
246
248
  .option(commandFlags.debug.flag, commandFlags.debug.description)
247
- .action(errorHandler(dryRun));
249
+ .action(errorHandler(require('../lib/command/dryRun')))
248
250
 
249
- program.command('run-rerun [test]')
251
+ program
252
+ .command('run-rerun [test]')
250
253
  .description('Executes tests in more than one test suite run')
251
254
 
252
255
  // codecept-only options
@@ -281,15 +284,15 @@ program.command('run-rerun [test]')
281
284
  .option('--trace', 'trace function calls')
282
285
  .option('--child <string>', 'option for child processes')
283
286
 
284
- .action(runRerun);
287
+ .action(require('../lib/command/run-rerun'))
285
288
 
286
289
  program.on('command:*', (cmd) => {
287
- console.log(`\nUnknown command ${cmd}\n`);
288
- program.outputHelp();
289
- });
290
+ console.log(`\nUnknown command ${cmd}\n`)
291
+ program.outputHelp()
292
+ })
290
293
 
291
294
  if (process.argv.length <= 2) {
292
- program.outputHelp();
295
+ program.outputHelp()
293
296
  } else {
294
- program.parse(process.argv);
297
+ program.parse(process.argv)
295
298
  }
package/lib/actor.js CHANGED
@@ -1,16 +1,17 @@
1
- import { Step, MetaStep } from './step.js';
2
- import container from './container.js';
3
- import { methodsOfObject } from './utils.js';
4
- import recorder from './recorder.js';
5
- import * as event from './event.js';
6
- import { store } from './store.js';
7
- import * as output from './output.js';
1
+ const Step = require('./step');
2
+ const { MetaStep } = require('./step');
3
+ const container = require('./container');
4
+ const { methodsOfObject } = require('./utils');
5
+ const recorder = require('./recorder');
6
+ const event = require('./event');
7
+ const store = require('./store');
8
+ const output = require('./output');
8
9
 
9
10
  /**
10
11
  * @interface
11
12
  * @alias ActorStatic
12
13
  */
13
- export class Actor {
14
+ class Actor {
14
15
  /**
15
16
  * Print the comment on log. Also, adding a step in the `Test.steps` object
16
17
  * @param {string} msg
@@ -40,7 +41,7 @@ export class Actor {
40
41
  if (!store.timeouts) return this;
41
42
 
42
43
  event.dispatcher.prependOnceListener(event.step.before, (step) => {
43
- output.output.log(`Timeout to ${step}: ${timeout}s`);
44
+ output.log(`Timeout to ${step}: ${timeout}s`);
44
45
  step.setTimeout(timeout * 1000, Step.TIMEOUT_ORDER.codeLimitTime);
45
46
  });
46
47
 
@@ -68,8 +69,7 @@ export class Actor {
68
69
  * Wraps helper methods into promises.
69
70
  * @ignore
70
71
  */
71
- // eslint-disable-next-line import/prefer-default-export
72
- export function actor(obj = {}) {
72
+ module.exports = function (obj = {}) {
73
73
  if (!store.actor) {
74
74
  store.actor = new Actor();
75
75
  }
@@ -117,9 +117,9 @@ export function actor(obj = {}) {
117
117
  });
118
118
 
119
119
  return actor;
120
- }
120
+ };
121
121
 
122
- export function recordStep(step, args) {
122
+ function recordStep(step, args) {
123
123
  step.status = 'queued';
124
124
  step.setArguments(args);
125
125
 
package/lib/ai.js CHANGED
@@ -1,9 +1,7 @@
1
- import debug from 'debug';
2
- import * as event from './event.js';
3
- import * as output from './output.js';
4
- import { removeNonInteractiveElements, minifyHtml, splitByChunks } from './html.js';
5
-
6
- debug('codeceptjs:ai');
1
+ const debug = require('debug')('codeceptjs:ai');
2
+ const output = require('./output');
3
+ const event = require('./event');
4
+ const { removeNonInteractiveElements, minifyHtml, splitByChunks } = require('./html');
7
5
 
8
6
  const defaultHtmlConfig = {
9
7
  maxLength: 50000,
@@ -124,8 +122,8 @@ class AiAssistant {
124
122
  if (this.config.request) return;
125
123
 
126
124
  const noRequestErrorMessage = `
127
- No request function is set for AI assistant.
128
- Please implement your own request function and set it in the config.
125
+ No request function is set for AI assistant.
126
+ Please implement your own request function and set it in the config.
129
127
 
130
128
  [!] AI request was decoupled from CodeceptJS. To connect to OpenAI or other AI service, please implement your own request function and set it in the config.
131
129
 
@@ -189,11 +187,10 @@ class AiAssistant {
189
187
  } catch (err) {
190
188
  debug(err.response);
191
189
  output.print('');
192
- output.output.error(`AI service error: ${err.message}`);
193
- if (err?.response?.data?.error?.code) output.output.error(err?.response?.data?.error?.code);
194
- if (err?.response?.data?.error?.message) output.output.error(err?.response?.data?.error?.message);
190
+ output.error(`AI service error: ${err.message}`);
191
+ if (err?.response?.data?.error?.code) output.error(err?.response?.data?.error?.code);
192
+ if (err?.response?.data?.error?.message) output.error(err?.response?.data?.error?.message);
195
193
  this.stopWhenReachingTokensLimit();
196
-
197
194
  return '';
198
195
  }
199
196
  }
@@ -298,4 +295,4 @@ function parseCodeBlocks(response) {
298
295
  return modifiedSnippets.filter(snippet => !!snippet);
299
296
  }
300
297
 
301
- export default new AiAssistant();
298
+ module.exports = new AiAssistant();
@@ -1,44 +1,43 @@
1
- import Assertion from '../assert.js';
2
- import AssertionFailedError from './error.js';
3
- import { template } from '../utils.js';
4
- import * as output from '../output.js';
1
+ const Assertion = require('../assert')
2
+ const AssertionFailedError = require('./error')
3
+ const { template } = require('../utils')
4
+ const output = require('../output')
5
5
 
6
6
  class EmptinessAssertion extends Assertion {
7
7
  constructor(params) {
8
8
  super((value) => {
9
9
  if (Array.isArray(value)) {
10
- return value.length === 0;
10
+ return value.length === 0
11
11
  }
12
- return !value;
13
- }, params);
14
- this.params.type = 'to be empty';
12
+ return !value
13
+ }, params)
14
+ this.params.type = 'to be empty'
15
15
  }
16
16
 
17
17
  getException() {
18
18
  if (Array.isArray(this.params.value)) {
19
- this.params.value = `[${this.params.value.join(', ')}]`;
19
+ this.params.value = `[${this.params.value.join(', ')}]`
20
20
  }
21
21
 
22
- const err = new AssertionFailedError(this.params, "{{customMessage}}expected {{subject}} '{{value}}' {{type}}");
22
+ const err = new AssertionFailedError(this.params, "{{customMessage}}expected {{subject}} '{{value}}' {{type}}")
23
23
 
24
24
  err.cliMessage = () => {
25
25
  const msg = err.template
26
26
  .replace('{{value}}', output.colors.bold('{{value}}'))
27
- .replace('{{subject}}', output.colors.bold('{{subject}}'));
28
- return template(msg, this.params);
29
- };
30
- return err;
27
+ .replace('{{subject}}', output.colors.bold('{{subject}}'))
28
+ return template(msg, this.params)
29
+ }
30
+ return err
31
31
  }
32
32
 
33
33
  addAssertParams() {
34
- this.params.value = this.params.actual = arguments[0];
35
- this.params.expected = [];
36
- this.params.customMessage = arguments[1] ? `${arguments[1]}\n\n` : '';
34
+ this.params.value = this.params.actual = arguments[0]
35
+ this.params.expected = []
36
+ this.params.customMessage = arguments[1] ? `${arguments[1]}\n\n` : ''
37
37
  }
38
38
  }
39
39
 
40
- export { EmptinessAssertion as Assertion };
41
-
42
- export function empty(subject) {
43
- return new EmptinessAssertion({ subject });
40
+ module.exports = {
41
+ Assertion: EmptinessAssertion,
42
+ empty: (subject) => new EmptinessAssertion({ subject }),
44
43
  }
@@ -1,59 +1,57 @@
1
- import Assertion from '../assert.js';
2
- import AssertionFailedError from './error.js';
3
- import { template } from '../utils.js';
4
- import * as output from '../output.js';
1
+ const Assertion = require('../assert')
2
+ const AssertionFailedError = require('./error')
3
+ const { template } = require('../utils')
4
+ const output = require('../output')
5
5
 
6
6
  class EqualityAssertion extends Assertion {
7
7
  constructor(params) {
8
8
  const comparator = function (a, b) {
9
9
  if (b.length === 0) {
10
- b = '';
10
+ b = ''
11
11
  }
12
- return a === b;
13
- };
14
- super(comparator, params);
15
- this.params.type = 'to equal';
12
+ return a === b
13
+ }
14
+ super(comparator, params)
15
+ this.params.type = 'to equal'
16
16
  }
17
17
 
18
18
  getException() {
19
- const params = this.params;
20
- params.jar = template(params.jar, params);
21
- const err = new AssertionFailedError(params, '{{customMessage}}expected {{jar}} "{{expected}}" {{type}} "{{actual}}"');
22
- err.showDiff = false;
19
+ const params = this.params
20
+ params.jar = template(params.jar, params)
21
+ const err = new AssertionFailedError(
22
+ params,
23
+ '{{customMessage}}expected {{jar}} "{{expected}}" {{type}} "{{actual}}"',
24
+ )
25
+ err.showDiff = false
23
26
  if (typeof err.cliMessage === 'function') {
24
- err.message = err.cliMessage();
27
+ err.message = err.cliMessage()
25
28
  }
26
29
  err.cliMessage = () => {
27
- const msg = err.template
28
- .replace('{{jar}}', output.colors.bold('{{jar}}'));
29
- return template(msg, this.params);
30
- };
31
- return err;
30
+ const msg = err.template.replace('{{jar}}', output.colors.bold('{{jar}}'))
31
+ return template(msg, this.params)
32
+ }
33
+ return err
32
34
  }
33
35
 
34
36
  addAssertParams() {
35
- this.params.expected = arguments[0];
36
- this.params.actual = arguments[1];
37
- this.params.customMessage = arguments[2] ? `${arguments[2]}\n\n` : '';
37
+ this.params.expected = arguments[0]
38
+ this.params.actual = arguments[1]
39
+ this.params.customMessage = arguments[2] ? `${arguments[2]}\n\n` : ''
38
40
  }
39
41
  }
40
42
 
41
- export function fileEquals(file) {
42
- return new EqualityAssertion({ file, jar: 'contents of {{file}}' });
43
- }
44
-
45
- export { EqualityAssertion as Assertion };
46
- export function equals(jar) {
47
- return new EqualityAssertion({ jar });
48
- }
49
-
50
- export function urlEquals(baseUrl) {
51
- const assert = new EqualityAssertion({ jar: 'url of current page' });
52
- assert.comparator = function (expected, actual) {
53
- if (expected.indexOf('http') !== 0) {
54
- actual = actual.slice(actual.indexOf(baseUrl) + baseUrl.length);
43
+ module.exports = {
44
+ Assertion: EqualityAssertion,
45
+ equals: (jar) => new EqualityAssertion({ jar }),
46
+ urlEquals: (baseUrl) => {
47
+ const assert = new EqualityAssertion({ jar: 'url of current page' })
48
+ assert.comparator = function (expected, actual) {
49
+ if (expected.indexOf('http') !== 0) {
50
+ actual = actual.slice(actual.indexOf(baseUrl) + baseUrl.length)
51
+ }
52
+ return actual === expected
55
53
  }
56
- return actual === expected;
57
- };
58
- return assert;
54
+ return assert
55
+ },
56
+ fileEquals: (file) => new EqualityAssertion({ file, jar: 'contents of {{file}}' }),
59
57
  }
@@ -1,4 +1,4 @@
1
- import { template as subs } from '../utils.js';
1
+ const subs = require('../utils').template
2
2
 
3
3
  /**
4
4
  * Assertion errors, can provide a detailed error messages.
@@ -6,27 +6,27 @@ import { template as subs } from '../utils.js';
6
6
  * inspect() and cliMessage() added to display errors with params.
7
7
  */
8
8
  function AssertionFailedError(params, template) {
9
- this.params = params;
10
- this.template = template;
9
+ this.params = params
10
+ this.template = template
11
11
  // this.message = "AssertionFailedError";
12
12
  // this.showDiff = true;
13
13
 
14
14
  // @todo cut assert things nicer
15
- this.showDiff = true;
15
+ this.showDiff = true
16
16
 
17
- this.actual = this.params.actual;
18
- this.expected = this.params.expected;
17
+ this.actual = this.params.actual
18
+ this.expected = this.params.expected
19
19
 
20
20
  this.inspect = () => {
21
- const params = this.params || {};
22
- const msg = params.customMessage || '';
23
- return msg + subs(this.template, params);
24
- };
21
+ const params = this.params || {}
22
+ const msg = params.customMessage || ''
23
+ return msg + subs(this.template, params)
24
+ }
25
25
 
26
- this.cliMessage = () => this.inspect();
26
+ this.cliMessage = () => this.inspect()
27
27
  }
28
28
 
29
- AssertionFailedError.prototype = Object.create(Error.prototype);
30
- AssertionFailedError.constructor = AssertionFailedError;
29
+ AssertionFailedError.prototype = Object.create(Error.prototype)
30
+ AssertionFailedError.constructor = AssertionFailedError
31
31
 
32
- export default AssertionFailedError;
32
+ module.exports = AssertionFailedError