codeceptjs 3.6.4 → 3.6.5-beta.1

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 (88) hide show
  1. package/bin/codecept.js +84 -63
  2. package/lib/assert/empty.js +19 -19
  3. package/lib/assert/equal.js +32 -30
  4. package/lib/assert/error.js +14 -14
  5. package/lib/assert/include.js +42 -42
  6. package/lib/assert/throws.js +13 -11
  7. package/lib/assert/truth.js +17 -18
  8. package/lib/command/configMigrate.js +57 -52
  9. package/lib/command/definitions.js +88 -88
  10. package/lib/command/dryRun.js +65 -63
  11. package/lib/command/generate.js +191 -181
  12. package/lib/command/info.js +39 -37
  13. package/lib/command/init.js +289 -286
  14. package/lib/command/interactive.js +32 -32
  15. package/lib/command/list.js +26 -26
  16. package/lib/command/run-multiple.js +113 -93
  17. package/lib/command/run-rerun.js +22 -22
  18. package/lib/command/run-workers.js +63 -63
  19. package/lib/command/run.js +24 -26
  20. package/lib/command/utils.js +64 -63
  21. package/lib/data/context.js +60 -60
  22. package/lib/data/dataScenarioConfig.js +47 -47
  23. package/lib/data/dataTableArgument.js +29 -29
  24. package/lib/data/table.js +26 -20
  25. package/lib/helper/AI.js +67 -65
  26. package/lib/helper/ApiDataFactory.js +72 -69
  27. package/lib/helper/Appium.js +409 -379
  28. package/lib/helper/ExpectHelper.js +214 -248
  29. package/lib/helper/FileSystem.js +77 -78
  30. package/lib/helper/GraphQL.js +44 -43
  31. package/lib/helper/GraphQLDataFactory.js +49 -50
  32. package/lib/helper/JSONResponse.js +64 -62
  33. package/lib/helper/Mochawesome.js +28 -28
  34. package/lib/helper/MockServer.js +12 -12
  35. package/lib/helper/Nightmare.js +664 -572
  36. package/lib/helper/Playwright.js +1320 -1211
  37. package/lib/helper/Protractor.js +663 -629
  38. package/lib/helper/Puppeteer.js +1232 -1124
  39. package/lib/helper/REST.js +87 -72
  40. package/lib/helper/TestCafe.js +490 -491
  41. package/lib/helper/WebDriver.js +1294 -1156
  42. package/lib/interfaces/bdd.js +38 -51
  43. package/lib/interfaces/featureConfig.js +19 -19
  44. package/lib/interfaces/gherkin.js +122 -111
  45. package/lib/interfaces/scenarioConfig.js +29 -29
  46. package/lib/listener/artifacts.js +9 -9
  47. package/lib/listener/config.js +24 -23
  48. package/lib/listener/exit.js +12 -12
  49. package/lib/listener/helpers.js +42 -42
  50. package/lib/listener/mocha.js +11 -11
  51. package/lib/listener/retry.js +32 -30
  52. package/lib/listener/steps.js +50 -51
  53. package/lib/listener/timeout.js +53 -53
  54. package/lib/plugin/allure.js +14 -14
  55. package/lib/plugin/autoDelay.js +29 -36
  56. package/lib/plugin/autoLogin.js +70 -66
  57. package/lib/plugin/commentStep.js +18 -18
  58. package/lib/plugin/coverage.js +92 -77
  59. package/lib/plugin/customLocator.js +20 -19
  60. package/lib/plugin/debugErrors.js +24 -24
  61. package/lib/plugin/eachElement.js +37 -37
  62. package/lib/plugin/fakerTransform.js +6 -6
  63. package/lib/plugin/heal.js +66 -63
  64. package/lib/plugin/pauseOnFail.js +10 -10
  65. package/lib/plugin/retryFailedStep.js +31 -38
  66. package/lib/plugin/retryTo.js +28 -28
  67. package/lib/plugin/screenshotOnFail.js +107 -86
  68. package/lib/plugin/selenoid.js +131 -117
  69. package/lib/plugin/standardActingHelpers.js +2 -8
  70. package/lib/plugin/stepByStepReport.js +102 -92
  71. package/lib/plugin/stepTimeout.js +23 -22
  72. package/lib/plugin/subtitles.js +34 -34
  73. package/lib/plugin/tryTo.js +39 -29
  74. package/lib/plugin/wdio.js +77 -72
  75. package/lib/template/heal.js +11 -14
  76. package/package.json +4 -2
  77. package/translations/de-DE.js +1 -1
  78. package/translations/fr-FR.js +1 -1
  79. package/translations/index.js +9 -9
  80. package/translations/it-IT.js +1 -1
  81. package/translations/ja-JP.js +1 -1
  82. package/translations/pl-PL.js +1 -1
  83. package/translations/pt-BR.js +1 -1
  84. package/translations/ru-RU.js +1 -1
  85. package/translations/zh-CN.js +1 -1
  86. package/translations/zh-TW.js +1 -1
  87. package/typings/promiseBasedTypes.d.ts +238 -0
  88. package/typings/types.d.ts +32 -0
package/bin/codecept.js CHANGED
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env node
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');
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')
6
6
 
7
7
  const commandFlags = {
8
8
  ai: {
@@ -29,104 +29,120 @@ const commandFlags = {
29
29
  flag: '--steps',
30
30
  description: 'show step-by-step execution',
31
31
  },
32
- };
33
-
34
- const errorHandler = (fn) => async (...args) => {
35
- try {
36
- await fn(...args);
37
- } catch (e) {
38
- printError(e);
39
- 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
+ }
40
43
  }
41
- };
42
44
 
43
45
  if (process.versions.node && process.versions.node.split('.') && process.versions.node.split('.')[0] < 12) {
44
- error('NodeJS >= 12 is required to run.');
45
- print();
46
- print('Please upgrade your NodeJS engine');
47
- print(`Current NodeJS version: ${process.version}`);
48
- 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)
49
51
  }
50
52
 
51
- program.usage('<command> [options]');
52
- program.version(Codecept.version());
53
+ program.usage('<command> [options]')
54
+ program.version(Codecept.version())
53
55
 
54
- program.command('init [path]')
56
+ program
57
+ .command('init [path]')
55
58
  .description('Creates dummy config in current dir or [path]')
56
- .action(errorHandler(require('../lib/command/init')));
59
+ .action(errorHandler(require('../lib/command/init')))
57
60
 
58
- program.command('migrate [path]')
61
+ program
62
+ .command('migrate [path]')
59
63
  .description('Migrate json config to js config in current dir or [path]')
60
- .action(errorHandler(require('../lib/command/configMigrate')));
64
+ .action(errorHandler(require('../lib/command/configMigrate')))
61
65
 
62
- program.command('shell [path]')
66
+ program
67
+ .command('shell [path]')
63
68
  .alias('sh')
64
69
  .description('Interactive shell')
65
70
  .option(commandFlags.verbose.flag, commandFlags.verbose.description)
66
71
  .option(commandFlags.profile.flag, commandFlags.profile.description)
67
72
  .option(commandFlags.ai.flag, commandFlags.ai.description)
68
73
  .option(commandFlags.config.flag, commandFlags.config.description)
69
- .action(errorHandler(require('../lib/command/interactive')));
74
+ .action(errorHandler(require('../lib/command/interactive')))
70
75
 
71
- program.command('list [path]')
76
+ program
77
+ .command('list [path]')
72
78
  .alias('l')
73
79
  .description('List all actions for I.')
74
- .action(errorHandler(require('../lib/command/list')));
80
+ .action(errorHandler(require('../lib/command/list')))
75
81
 
76
- program.command('def [path]')
82
+ program
83
+ .command('def [path]')
77
84
  .description('Generates TypeScript definitions for all I actions.')
78
85
  .option(commandFlags.config.flag, commandFlags.config.description)
79
86
  .option('-o, --output [folder]', 'target folder to paste definitions')
80
- .action(errorHandler(require('../lib/command/definitions')));
87
+ .action(errorHandler(require('../lib/command/definitions')))
81
88
 
82
- program.command('gherkin:init [path]')
89
+ program
90
+ .command('gherkin:init [path]')
83
91
  .alias('bdd:init')
84
92
  .description('Prepare CodeceptJS to run feature files.')
85
93
  .option(commandFlags.config.flag, commandFlags.config.description)
86
- .action(errorHandler(require('../lib/command/gherkin/init')));
94
+ .action(errorHandler(require('../lib/command/gherkin/init')))
87
95
 
88
- program.command('gherkin:steps [path]')
96
+ program
97
+ .command('gherkin:steps [path]')
89
98
  .alias('bdd:steps')
90
99
  .description('Prints all defined gherkin steps.')
91
100
  .option(commandFlags.config.flag, commandFlags.config.description)
92
- .action(errorHandler(require('../lib/command/gherkin/steps')));
101
+ .action(errorHandler(require('../lib/command/gherkin/steps')))
93
102
 
94
- program.command('gherkin:snippets [path]')
103
+ program
104
+ .command('gherkin:snippets [path]')
95
105
  .alias('bdd:snippets')
96
106
  .description('Generate step definitions from steps.')
97
107
  .option('--dry-run', "don't save snippets to file")
98
108
  .option(commandFlags.config.flag, commandFlags.config.description)
99
109
  .option('--feature [file]', 'feature files(s) to scan')
100
110
  .option('--path [file]', 'file in which to place the new snippets')
101
- .action(errorHandler(require('../lib/command/gherkin/snippets')));
111
+ .action(errorHandler(require('../lib/command/gherkin/snippets')))
102
112
 
103
- program.command('generate:test [path]')
113
+ program
114
+ .command('generate:test [path]')
104
115
  .alias('gt')
105
116
  .description('Generates an empty test')
106
- .action(errorHandler(require('../lib/command/generate').test));
117
+ .action(errorHandler(require('../lib/command/generate').test))
107
118
 
108
- program.command('generate:pageobject [path]')
119
+ program
120
+ .command('generate:pageobject [path]')
109
121
  .alias('gpo')
110
122
  .description('Generates an empty page object')
111
- .action(errorHandler(require('../lib/command/generate').pageObject));
123
+ .action(errorHandler(require('../lib/command/generate').pageObject))
112
124
 
113
- program.command('generate:object [path]')
125
+ program
126
+ .command('generate:object [path]')
114
127
  .alias('go')
115
128
  .option('--type, -t [kind]', 'type of object to be created')
116
129
  .description('Generates an empty support object (page/step/fragment)')
117
- .action(errorHandler(require('../lib/command/generate').pageObject));
130
+ .action(errorHandler(require('../lib/command/generate').pageObject))
118
131
 
119
- program.command('generate:helper [path]')
132
+ program
133
+ .command('generate:helper [path]')
120
134
  .alias('gh')
121
135
  .description('Generates a new helper')
122
- .action(errorHandler(require('../lib/command/generate').helper));
136
+ .action(errorHandler(require('../lib/command/generate').helper))
123
137
 
124
- program.command('generate:heal [path]')
138
+ program
139
+ .command('generate:heal [path]')
125
140
  .alias('gr')
126
141
  .description('Generates basic heal recipes')
127
- .action(errorHandler(require('../lib/command/generate').heal));
142
+ .action(errorHandler(require('../lib/command/generate').heal))
128
143
 
129
- program.command('run [test]')
144
+ program
145
+ .command('run [test]')
130
146
  .description('Executes tests')
131
147
 
132
148
  // codecept-only options
@@ -162,9 +178,10 @@ program.command('run [test]')
162
178
  .option('--recursive', 'include sub directories')
163
179
  .option('--trace', 'trace function calls')
164
180
  .option('--child <string>', 'option for child processes')
165
- .action(errorHandler(require('../lib/command/run')));
181
+ .action(errorHandler(require('../lib/command/run')))
166
182
 
167
- program.command('run-workers <workers> [selectedRuns...]')
183
+ program
184
+ .command('run-workers <workers> [selectedRuns...]')
168
185
  .description('Executes tests in workers')
169
186
  .option(commandFlags.config.flag, commandFlags.config.description)
170
187
  .option('-g, --grep <pattern>', 'only run tests matching <pattern>')
@@ -180,9 +197,10 @@ program.command('run-workers <workers> [selectedRuns...]')
180
197
  .option('-p, --plugins <k=v,k2=v2,...>', 'enable plugins, comma-separated')
181
198
  .option('-O, --reporter-options <k=v,k2=v2,...>', 'reporter-specific options')
182
199
  .option('-R, --reporter <name>', 'specify the reporter to use')
183
- .action(errorHandler(require('../lib/command/run-workers')));
200
+ .action(errorHandler(require('../lib/command/run-workers')))
184
201
 
185
- program.command('run-multiple [suites...]')
202
+ program
203
+ .command('run-multiple [suites...]')
186
204
  .description('Executes tests multiple')
187
205
  .option(commandFlags.config.flag, commandFlags.config.description)
188
206
  .option(commandFlags.profile.flag, commandFlags.profile.description)
@@ -205,14 +223,16 @@ program.command('run-multiple [suites...]')
205
223
  // mocha options
206
224
  .option('--colors', 'force enabling of colors')
207
225
 
208
- .action(errorHandler(require('../lib/command/run-multiple')));
226
+ .action(errorHandler(require('../lib/command/run-multiple')))
209
227
 
210
- program.command('info [path]')
228
+ program
229
+ .command('info [path]')
211
230
  .description('Print debugging information concerning the local environment')
212
231
  .option('-c, --config', 'your config file path')
213
- .action(errorHandler(require('../lib/command/info')));
232
+ .action(errorHandler(require('../lib/command/info')))
214
233
 
215
- program.command('dry-run [test]')
234
+ program
235
+ .command('dry-run [test]')
216
236
  .description('Prints step-by-step scenario for a test without actually running it')
217
237
  .option('-p, --plugins <k=v,k2=v2,...>', 'enable plugins, comma-separated')
218
238
  .option('--bootstrap', 'enable bootstrap & teardown scripts for dry-run')
@@ -226,9 +246,10 @@ program.command('dry-run [test]')
226
246
  .option(commandFlags.steps.flag, commandFlags.steps.description)
227
247
  .option(commandFlags.verbose.flag, commandFlags.verbose.description)
228
248
  .option(commandFlags.debug.flag, commandFlags.debug.description)
229
- .action(errorHandler(require('../lib/command/dryRun')));
249
+ .action(errorHandler(require('../lib/command/dryRun')))
230
250
 
231
- program.command('run-rerun [test]')
251
+ program
252
+ .command('run-rerun [test]')
232
253
  .description('Executes tests in more than one test suite run')
233
254
 
234
255
  // codecept-only options
@@ -263,15 +284,15 @@ program.command('run-rerun [test]')
263
284
  .option('--trace', 'trace function calls')
264
285
  .option('--child <string>', 'option for child processes')
265
286
 
266
- .action(require('../lib/command/run-rerun'));
287
+ .action(require('../lib/command/run-rerun'))
267
288
 
268
289
  program.on('command:*', (cmd) => {
269
- console.log(`\nUnknown command ${cmd}\n`);
270
- program.outputHelp();
271
- });
290
+ console.log(`\nUnknown command ${cmd}\n`)
291
+ program.outputHelp()
292
+ })
272
293
 
273
294
  if (process.argv.length <= 2) {
274
- program.outputHelp();
295
+ program.outputHelp()
275
296
  } else {
276
- program.parse(process.argv);
297
+ program.parse(process.argv)
277
298
  }
@@ -1,43 +1,43 @@
1
- const Assertion = require('../assert');
2
- const AssertionFailedError = require('./error');
3
- const { template } = require('../utils');
4
- const output = require('../output');
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
40
  module.exports = {
41
41
  Assertion: EmptinessAssertion,
42
- empty: subject => new EmptinessAssertion({ subject }),
43
- };
42
+ empty: (subject) => new EmptinessAssertion({ subject }),
43
+ }
@@ -1,55 +1,57 @@
1
- const Assertion = require('../assert');
2
- const AssertionFailedError = require('./error');
3
- const { template } = require('../utils');
4
- const output = require('../output');
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
43
  module.exports = {
42
44
  Assertion: EqualityAssertion,
43
- equals: jar => new EqualityAssertion({ jar }),
45
+ equals: (jar) => new EqualityAssertion({ jar }),
44
46
  urlEquals: (baseUrl) => {
45
- const assert = new EqualityAssertion({ jar: 'url of current page' });
47
+ const assert = new EqualityAssertion({ jar: 'url of current page' })
46
48
  assert.comparator = function (expected, actual) {
47
49
  if (expected.indexOf('http') !== 0) {
48
- actual = actual.slice(actual.indexOf(baseUrl) + baseUrl.length);
50
+ actual = actual.slice(actual.indexOf(baseUrl) + baseUrl.length)
49
51
  }
50
- return actual === expected;
51
- };
52
- return assert;
52
+ return actual === expected
53
+ }
54
+ return assert
53
55
  },
54
- fileEquals: file => new EqualityAssertion({ file, jar: 'contents of {{file}}' }),
55
- };
56
+ fileEquals: (file) => new EqualityAssertion({ file, jar: 'contents of {{file}}' }),
57
+ }
@@ -1,4 +1,4 @@
1
- const subs = require('../utils').template;
1
+ const subs = require('../utils').template
2
2
 
3
3
  /**
4
4
  * Assertion errors, can provide a detailed error messages.
@@ -6,27 +6,27 @@ const subs = require('../utils').template;
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
- module.exports = AssertionFailedError;
32
+ module.exports = AssertionFailedError
@@ -1,78 +1,78 @@
1
- const Assertion = require('../assert');
2
- const AssertionFailedError = require('./error');
3
- const { template } = require('../utils');
4
- const output = require('../output');
1
+ const Assertion = require('../assert')
2
+ const AssertionFailedError = require('./error')
3
+ const { template } = require('../utils')
4
+ const output = require('../output')
5
5
 
6
- const MAX_LINES = 10;
6
+ const MAX_LINES = 10
7
7
 
8
8
  class InclusionAssertion extends Assertion {
9
9
  constructor(params) {
10
- params.jar = params.jar || 'string';
10
+ params.jar = params.jar || 'string'
11
11
  const comparator = function (needle, haystack) {
12
12
  if (Array.isArray(haystack)) {
13
- return haystack.filter(part => part.indexOf(needle) >= 0).length > 0;
13
+ return haystack.filter((part) => part.indexOf(needle) >= 0).length > 0
14
14
  }
15
- return haystack.indexOf(needle) >= 0;
16
- };
17
- super(comparator, params);
18
- this.params.type = 'to include';
15
+ return haystack.indexOf(needle) >= 0
16
+ }
17
+ super(comparator, params)
18
+ this.params.type = 'to include'
19
19
  }
20
20
 
21
21
  getException() {
22
- const params = this.params;
23
- params.jar = template(params.jar, params);
24
- const err = new AssertionFailedError(params, '{{customMessage}}expected {{jar}} {{type}} "{{needle}}"');
25
- err.expected = params.needle;
26
- err.actual = params.haystack;
22
+ const params = this.params
23
+ params.jar = template(params.jar, params)
24
+ const err = new AssertionFailedError(params, '{{customMessage}}expected {{jar}} {{type}} "{{needle}}"')
25
+ err.expected = params.needle
26
+ err.actual = params.haystack
27
27
  if (Array.isArray(this.params.haystack)) {
28
- this.params.haystack = this.params.haystack.join('\n___(next element)___\n');
28
+ this.params.haystack = this.params.haystack.join('\n___(next element)___\n')
29
29
  }
30
30
  err.cliMessage = function () {
31
31
  const msg = this.template
32
32
  .replace('{{jar}}', output.colors.bold('{{jar}}'))
33
- .replace('{{needle}}', output.colors.bold('{{needle}}'));
34
- return template(msg, this.params);
35
- };
36
- return err;
33
+ .replace('{{needle}}', output.colors.bold('{{needle}}'))
34
+ return template(msg, this.params)
35
+ }
36
+ return err
37
37
  }
38
38
 
39
39
  getFailedAssertion() {
40
- const err = this.getException();
41
- const lines = this.params.haystack.split('\n');
40
+ const err = this.getException()
41
+ const lines = this.params.haystack.split('\n')
42
42
  if (lines.length > MAX_LINES) {
43
- const more = lines.length - MAX_LINES;
44
- err.actual = `${lines.slice(0, MAX_LINES).join('\n')}\n--( ${more} lines more )---`;
43
+ const more = lines.length - MAX_LINES
44
+ err.actual = `${lines.slice(0, MAX_LINES).join('\n')}\n--( ${more} lines more )---`
45
45
  }
46
- return err;
46
+ return err
47
47
  }
48
48
 
49
49
  getFailedNegation() {
50
- this.params.type = 'not to include';
51
- const err = this.getException();
52
- const pattern = new RegExp(`^.*?\n?^.*?\n?^.*?${escapeRegExp(this.params.needle)}.*?$\n?.*$\n?.*$`, 'm');
53
- const matched = this.params.haystack.match(pattern);
54
- if (!matched) return err;
55
- err.actual = matched[0].replace(this.params.needle, output.colors.bold(this.params.needle));
56
- err.actual = `------\n${err.actual}\n------`;
57
- return err;
50
+ this.params.type = 'not to include'
51
+ const err = this.getException()
52
+ const pattern = new RegExp(`^.*?\n?^.*?\n?^.*?${escapeRegExp(this.params.needle)}.*?$\n?.*$\n?.*$`, 'm')
53
+ const matched = this.params.haystack.match(pattern)
54
+ if (!matched) return err
55
+ err.actual = matched[0].replace(this.params.needle, output.colors.bold(this.params.needle))
56
+ err.actual = `------\n${err.actual}\n------`
57
+ return err
58
58
  }
59
59
 
60
60
  addAssertParams() {
61
- this.params.needle = arguments[0];
62
- this.params.haystack = arguments[1];
63
- this.params.customMessage = arguments[2] ? `${arguments[2]}\n\n` : '';
61
+ this.params.needle = arguments[0]
62
+ this.params.haystack = arguments[1]
63
+ this.params.customMessage = arguments[2] ? `${arguments[2]}\n\n` : ''
64
64
  }
65
65
  }
66
66
 
67
67
  module.exports = {
68
68
  Assertion: InclusionAssertion,
69
69
  includes: (needleType) => {
70
- needleType = needleType || 'string';
71
- return new InclusionAssertion({ jar: needleType });
70
+ needleType = needleType || 'string'
71
+ return new InclusionAssertion({ jar: needleType })
72
72
  },
73
- fileIncludes: file => new InclusionAssertion({ file, jar: 'file {{file}}' }),
74
- };
73
+ fileIncludes: (file) => new InclusionAssertion({ file, jar: 'file {{file}}' }),
74
+ }
75
75
 
76
76
  function escapeRegExp(str) {
77
- return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&');
77
+ return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&')
78
78
  }
@@ -1,20 +1,22 @@
1
1
  function errorThrown(actual, expected) {
2
- if (!expected) return null;
3
- if (!actual) throw new Error(`Expected ${expected} error to be thrown`);
4
- const msg = actual.inspect ? actual.inspect() : actual.toString();
2
+ if (!expected) return null
3
+ if (!actual) throw new Error(`Expected ${expected} error to be thrown`)
4
+ const msg = actual.inspect ? actual.inspect() : actual.toString()
5
5
  if (expected instanceof RegExp) {
6
- if (msg.match(expected)) return null;
7
- throw new Error(`Expected error to be thrown with message matching ${expected} while '${msg}' caught`);
6
+ if (msg.match(expected)) return null
7
+ throw new Error(`Expected error to be thrown with message matching ${expected} while '${msg}' caught`)
8
8
  }
9
9
  if (typeof expected === 'string') {
10
- if (msg === expected) return null;
11
- throw new Error(`Expected error to be thrown with message ${expected} while '${msg}' caught`);
10
+ if (msg === expected) return null
11
+ throw new Error(`Expected error to be thrown with message ${expected} while '${msg}' caught`)
12
12
  }
13
13
  if (typeof expected === 'object') {
14
- if (actual.constructor.name !== expected.constructor.name) throw new Error(`Expected ${expected} error to be thrown but ${actual} was caught`);
15
- if (expected.message && expected.message !== msg) throw new Error(`Expected error to be thrown with message ${expected.message} while '${msg}' caught`);
14
+ if (actual.constructor.name !== expected.constructor.name)
15
+ throw new Error(`Expected ${expected} error to be thrown but ${actual} was caught`)
16
+ if (expected.message && expected.message !== msg)
17
+ throw new Error(`Expected error to be thrown with message ${expected.message} while '${msg}' caught`)
16
18
  }
17
- return null;
19
+ return null
18
20
  }
19
21
 
20
- module.exports = errorThrown;
22
+ module.exports = errorThrown