@serenity-js/mocha 3.41.1 → 3.42.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/esm/OutcomeRecorder.d.ts +13 -0
  3. package/esm/OutcomeRecorder.d.ts.map +1 -0
  4. package/esm/OutcomeRecorder.js +21 -0
  5. package/esm/OutcomeRecorder.js.map +1 -0
  6. package/esm/SerenityReporterForMocha.d.ts +34 -0
  7. package/esm/SerenityReporterForMocha.d.ts.map +1 -0
  8. package/esm/SerenityReporterForMocha.js +154 -0
  9. package/esm/SerenityReporterForMocha.js.map +1 -0
  10. package/esm/adapter/MochaAdapter.d.ts +48 -0
  11. package/esm/adapter/MochaAdapter.d.ts.map +1 -0
  12. package/esm/adapter/MochaAdapter.js +95 -0
  13. package/esm/adapter/MochaAdapter.js.map +1 -0
  14. package/esm/adapter/MochaConfig.d.ts +105 -0
  15. package/esm/adapter/MochaConfig.d.ts.map +1 -0
  16. package/esm/adapter/MochaConfig.js +2 -0
  17. package/esm/adapter/MochaConfig.js.map +1 -0
  18. package/esm/adapter/index.d.ts +3 -0
  19. package/esm/adapter/index.d.ts.map +1 -0
  20. package/esm/adapter/index.js +3 -0
  21. package/esm/adapter/index.js.map +1 -0
  22. package/esm/index.d.ts +9 -0
  23. package/esm/index.d.ts.map +1 -0
  24. package/esm/index.js +20 -0
  25. package/esm/index.js.map +1 -0
  26. package/esm/mappers/MochaOutcomeMapper.d.ts +12 -0
  27. package/esm/mappers/MochaOutcomeMapper.d.ts.map +1 -0
  28. package/esm/mappers/MochaOutcomeMapper.js +42 -0
  29. package/esm/mappers/MochaOutcomeMapper.js.map +1 -0
  30. package/esm/mappers/MochaTestMapper.d.ts +18 -0
  31. package/esm/mappers/MochaTestMapper.d.ts.map +1 -0
  32. package/esm/mappers/MochaTestMapper.js +53 -0
  33. package/esm/mappers/MochaTestMapper.js.map +1 -0
  34. package/esm/mappers/index.d.ts +3 -0
  35. package/esm/mappers/index.d.ts.map +1 -0
  36. package/esm/mappers/index.js +3 -0
  37. package/esm/mappers/index.js.map +1 -0
  38. package/lib/OutcomeRecorder.d.ts +1 -1
  39. package/lib/OutcomeRecorder.d.ts.map +1 -1
  40. package/lib/SerenityReporterForMocha.d.ts +1 -1
  41. package/lib/SerenityReporterForMocha.d.ts.map +1 -1
  42. package/lib/SerenityReporterForMocha.js +8 -8
  43. package/lib/SerenityReporterForMocha.js.map +1 -1
  44. package/lib/adapter/MochaAdapter.d.ts +4 -4
  45. package/lib/adapter/MochaAdapter.d.ts.map +1 -1
  46. package/lib/adapter/MochaAdapter.js +4 -3
  47. package/lib/adapter/MochaAdapter.js.map +1 -1
  48. package/lib/adapter/index.d.ts +2 -2
  49. package/lib/adapter/index.d.ts.map +1 -1
  50. package/lib/adapter/index.js +2 -2
  51. package/lib/adapter/index.js.map +1 -1
  52. package/lib/index.d.ts +2 -2
  53. package/lib/index.d.ts.map +1 -1
  54. package/lib/index.js +11 -4
  55. package/lib/index.js.map +1 -1
  56. package/lib/mappers/MochaOutcomeMapper.d.ts +1 -1
  57. package/lib/mappers/MochaOutcomeMapper.d.ts.map +1 -1
  58. package/lib/mappers/MochaOutcomeMapper.js +1 -1
  59. package/lib/mappers/MochaOutcomeMapper.js.map +1 -1
  60. package/lib/mappers/MochaTestMapper.d.ts +2 -2
  61. package/lib/mappers/MochaTestMapper.d.ts.map +1 -1
  62. package/lib/mappers/MochaTestMapper.js +2 -2
  63. package/lib/mappers/MochaTestMapper.js.map +1 -1
  64. package/lib/mappers/index.d.ts +2 -2
  65. package/lib/mappers/index.d.ts.map +1 -1
  66. package/lib/mappers/index.js +2 -2
  67. package/lib/mappers/index.js.map +1 -1
  68. package/lib/package.json +1 -0
  69. package/package.json +54 -7
  70. package/src/OutcomeRecorder.ts +1 -1
  71. package/src/SerenityReporterForMocha.ts +6 -6
  72. package/src/adapter/MochaAdapter.ts +9 -8
  73. package/src/adapter/index.ts +2 -2
  74. package/src/index.ts +10 -3
  75. package/src/mappers/MochaOutcomeMapper.ts +2 -2
  76. package/src/mappers/MochaTestMapper.ts +2 -2
  77. package/src/mappers/index.ts +2 -2
  78. package/tsconfig-cjs.build.json +18 -0
  79. package/tsconfig-esm.build.json +18 -0
package/CHANGELOG.md CHANGED
@@ -3,6 +3,31 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [3.42.0](https://github.com/serenity-js/serenity-js/compare/v3.41.2...v3.42.0) (2026-03-19)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * **mocha:** add CommonJS compatibility for Mocha reporter loading ([5fa8162](https://github.com/serenity-js/serenity-js/commit/5fa81628ce2e7fc92285318bd64b9ed30c05f2fc))
12
+
13
+
14
+ ### Features
15
+
16
+ * **core:** add dual ESM/CJS build support for Wave 2 packages ([0e2631c](https://github.com/serenity-js/serenity-js/commit/0e2631ca7cdbe68da7feec343eaf4f7fe9bb64d6))
17
+ * **core:** add ESM/CJS dual build support for web packages ([94c5a64](https://github.com/serenity-js/serenity-js/commit/94c5a6423dc369477bbabbacee5a54f8fca20209))
18
+
19
+
20
+
21
+
22
+
23
+ ## [3.41.2](https://github.com/serenity-js/serenity-js/compare/v3.41.1...v3.41.2) (2026-03-05)
24
+
25
+ **Note:** Version bump only for package @serenity-js/mocha
26
+
27
+
28
+
29
+
30
+
6
31
  ## [3.41.1](https://github.com/serenity-js/serenity-js/compare/v3.41.0...v3.41.1) (2026-02-27)
7
32
 
8
33
  **Note:** Version bump only for package @serenity-js/mocha
@@ -0,0 +1,13 @@
1
+ import type { Outcome } from '@serenity-js/core/model';
2
+ import type { Test } from 'mocha';
3
+ /**
4
+ * @package
5
+ */
6
+ export declare class OutcomeRecorder {
7
+ private recordedOutcomes;
8
+ started(test: Test): void;
9
+ finished(test: Test, outcome: Outcome): void;
10
+ outcomeOf(test: Test): Outcome;
11
+ erase(test: Test): void;
12
+ }
13
+ //# sourceMappingURL=OutcomeRecorder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"OutcomeRecorder.d.ts","sourceRoot":"","sources":["../src/OutcomeRecorder.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC;AAElC;;GAEG;AACH,qBAAa,eAAe;IACxB,OAAO,CAAC,gBAAgB,CAAyB;IAE1C,OAAO,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI;IAIzB,QAAQ,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,GAAG,IAAI;IAQ5C,SAAS,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO;IAI9B,KAAK,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI;CAGjC"}
@@ -0,0 +1,21 @@
1
+ /**
2
+ * @package
3
+ */
4
+ export class OutcomeRecorder {
5
+ recordedOutcomes = [];
6
+ started(test) {
7
+ this.recordedOutcomes.push({ test });
8
+ }
9
+ finished(test, outcome) {
10
+ this.recordedOutcomes = this.recordedOutcomes.map(recordedOutcome => recordedOutcome.test === test
11
+ ? { ...recordedOutcome, outcome }
12
+ : recordedOutcome);
13
+ }
14
+ outcomeOf(test) {
15
+ return this.recordedOutcomes.find(recordedOutcome => recordedOutcome.test === test)?.outcome;
16
+ }
17
+ erase(test) {
18
+ this.recordedOutcomes = this.recordedOutcomes.filter(recordedOutcome => recordedOutcome.test !== test);
19
+ }
20
+ }
21
+ //# sourceMappingURL=OutcomeRecorder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"OutcomeRecorder.js","sourceRoot":"","sources":["../src/OutcomeRecorder.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,MAAM,OAAO,eAAe;IAChB,gBAAgB,GAAsB,EAAE,CAAC;IAE1C,OAAO,CAAC,IAAU;QACrB,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC;IACzC,CAAC;IAEM,QAAQ,CAAC,IAAU,EAAE,OAAgB;QACxC,IAAI,CAAC,gBAAgB,GAAG,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,eAAe,CAAC,EAAE,CAChE,eAAe,CAAC,IAAI,KAAK,IAAI;YACzB,CAAC,CAAC,EAAC,GAAG,eAAe,EAAE,OAAO,EAAE;YAChC,CAAC,CAAC,eAAe,CACxB,CAAA;IACL,CAAC;IAEM,SAAS,CAAC,IAAU;QACvB,OAAO,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,eAAe,CAAC,EAAE,CAAC,eAAe,CAAC,IAAI,KAAK,IAAI,CAAC,EAAE,OAAO,CAAC;IACjG,CAAC;IAEM,KAAK,CAAC,IAAU;QACnB,IAAI,CAAC,gBAAgB,GAAG,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,eAAe,CAAC,EAAE,CAAC,eAAe,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC;IAC3G,CAAC;CACJ"}
@@ -0,0 +1,34 @@
1
+ import type { Serenity } from '@serenity-js/core';
2
+ import { type RequirementsHierarchy } from '@serenity-js/core/io';
3
+ import type { MochaOptions } from 'mocha';
4
+ import { reporters, Runner } from 'mocha';
5
+ /**
6
+ * @package
7
+ */
8
+ export declare class SerenityReporterForMocha extends reporters.Base {
9
+ private readonly serenity;
10
+ private readonly requirementsHierarchy;
11
+ private readonly testMapper;
12
+ private readonly outcomeMapper;
13
+ private readonly recorder;
14
+ private suiteIds;
15
+ private currentSceneId;
16
+ /**
17
+ * @param {Serenity} serenity
18
+ * @param requirementsHierarchy
19
+ * @param {mocha~Runner} runner
20
+ * @param {mocha~MochaOptions} options
21
+ */
22
+ constructor(serenity: Serenity, requirementsHierarchy: RequirementsHierarchy, runner: Runner, options?: MochaOptions);
23
+ done(failures: number, callback?: (failures: number) => void): void;
24
+ private announceSuiteStartsFor;
25
+ private announceSuiteFinishedFor;
26
+ private announceSceneStartsFor;
27
+ private announceSceneFinishedFor;
28
+ private announceSceneSkippedFor;
29
+ private announceRetryIfNeeded;
30
+ private isRetriable;
31
+ private currentRetryOf;
32
+ private emit;
33
+ }
34
+ //# sourceMappingURL=SerenityReporterForMocha.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SerenityReporterForMocha.d.ts","sourceRoot":"","sources":["../src/SerenityReporterForMocha.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAelD,OAAO,EAA4B,KAAK,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAU5F,OAAO,KAAK,EAAE,YAAY,EAAyB,MAAM,OAAO,CAAC;AACjE,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAK1C;;GAEG;AACH,qBAAa,wBAAyB,SAAQ,SAAS,CAAC,IAAI;IAiBpD,OAAO,CAAC,QAAQ,CAAC,QAAQ;IACzB,OAAO,CAAC,QAAQ,CAAC,qBAAqB;IAhB1C,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAkB;IAC7C,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAgD;IAE9E,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAA0C;IAEnE,OAAO,CAAC,QAAQ,CAAuB;IACvC,OAAO,CAAC,cAAc,CAA4B;IAElD;;;;;OAKG;gBAEkB,QAAQ,EAAE,QAAQ,EAClB,qBAAqB,EAAE,qBAAqB,EAC7D,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,YAAY;IA4FnB,IAAI,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,GAAG,IAAI;IAkB1E,OAAO,CAAC,sBAAsB;IAgB9B,OAAO,CAAC,wBAAwB;IAyBhC,OAAO,CAAC,sBAAsB;IAiB9B,OAAO,CAAC,wBAAwB;IA2ChC,OAAO,CAAC,uBAAuB;IAsB/B,OAAO,CAAC,qBAAqB;IA8B7B,OAAO,CAAC,WAAW;IAInB,OAAO,CAAC,cAAc;IAItB,OAAO,CAAC,IAAI;CAGf"}
@@ -0,0 +1,154 @@
1
+ import { RetryableSceneDetected, SceneFinished, SceneFinishes, SceneStarts, SceneTagged, TestRunFinished, TestRunFinishes, TestRunnerDetected, TestRunStarts, TestSuiteFinished, TestSuiteStarts, } from '@serenity-js/core/events';
2
+ import { FileSystemLocation, Path } from '@serenity-js/core/io';
3
+ import { ArbitraryTag, CorrelationId, ExecutionFailedWithError, ExecutionRetriedTag, ExecutionSuccessful, Name, TestSuiteDetails } from '@serenity-js/core/model';
4
+ import { reporters, Runner } from 'mocha';
5
+ import { MochaOutcomeMapper, MochaTestMapper } from './mappers/index.js';
6
+ import { OutcomeRecorder } from './OutcomeRecorder.js';
7
+ /**
8
+ * @package
9
+ */
10
+ export class SerenityReporterForMocha extends reporters.Base {
11
+ serenity;
12
+ requirementsHierarchy;
13
+ testMapper;
14
+ outcomeMapper = new MochaOutcomeMapper();
15
+ recorder = new OutcomeRecorder();
16
+ suiteIds = [];
17
+ currentSceneId = undefined;
18
+ /**
19
+ * @param {Serenity} serenity
20
+ * @param requirementsHierarchy
21
+ * @param {mocha~Runner} runner
22
+ * @param {mocha~MochaOptions} options
23
+ */
24
+ constructor(serenity, requirementsHierarchy, runner, options) {
25
+ super(runner, options);
26
+ this.serenity = serenity;
27
+ this.requirementsHierarchy = requirementsHierarchy;
28
+ this.testMapper = new MochaTestMapper(this.serenity.cwd());
29
+ runner.on(Runner.constants.EVENT_RUN_BEGIN, () => {
30
+ this.emit(new TestRunStarts(this.serenity.currentTime()));
31
+ });
32
+ runner.on(Runner.constants.EVENT_SUITE_BEGIN, (suite) => {
33
+ if (suite.root === false) {
34
+ this.announceSuiteStartsFor(suite);
35
+ }
36
+ });
37
+ runner.on(Runner.constants.EVENT_SUITE_END, (suite) => {
38
+ if (suite.root === false) {
39
+ this.announceSuiteFinishedFor(suite);
40
+ }
41
+ });
42
+ runner.on(Runner.constants.EVENT_TEST_BEGIN, (test) => {
43
+ this.recorder.started(test);
44
+ this.announceSceneStartsFor(test);
45
+ });
46
+ runner.on(Runner.constants.EVENT_TEST_PASS, (test) => {
47
+ this.announceRetryIfNeeded(test);
48
+ this.recorder.finished(test.ctx ? test.ctx.currentTest : test, this.outcomeMapper.outcomeOf(test));
49
+ });
50
+ runner.on(Runner.constants.EVENT_TEST_FAIL, (test, error) => {
51
+ this.announceRetryIfNeeded(test);
52
+ this.recorder.finished(test.ctx ? test.ctx.currentTest : test, this.outcomeMapper.outcomeOf(test, error));
53
+ });
54
+ runner.on(Runner.constants.EVENT_TEST_RETRY, (test, error) => {
55
+ this.announceRetryIfNeeded(test);
56
+ this.recorder.finished(!!test.ctx && test.ctx.currentTest ? test.ctx.currentTest : test, this.outcomeMapper.outcomeOf(test, error));
57
+ });
58
+ const announceSceneFinishedFor = SerenityReporterForMocha.prototype.announceSceneFinishedFor.bind(this);
59
+ runner.suite.afterEach('Serenity/JS', function () {
60
+ return announceSceneFinishedFor(this.currentTest, this.test);
61
+ });
62
+ // https://github.com/cypress-io/cypress/issues/7562
63
+ runner.on('test:after:run', (test) => {
64
+ return announceSceneFinishedFor(test, test);
65
+ });
66
+ // Tests without body don't trigger the above custom afterEach hook
67
+ runner.on(Runner.constants.EVENT_TEST_PENDING, (test) => {
68
+ if (!test.fn) {
69
+ this.announceSceneSkippedFor(test);
70
+ }
71
+ });
72
+ }
73
+ done(failures, callback) {
74
+ this.emit(new TestRunFinishes(this.serenity.currentTime()));
75
+ this.serenity.waitForNextCue()
76
+ .then(() => {
77
+ this.emit(new TestRunFinished(new ExecutionSuccessful(), this.serenity.currentTime()));
78
+ return callback(failures);
79
+ })
80
+ .catch(error => {
81
+ const numberOfFailures = failures === 0
82
+ ? 1
83
+ : failures;
84
+ this.emit(new TestRunFinished(new ExecutionFailedWithError(error), this.serenity.currentTime()));
85
+ return callback(numberOfFailures);
86
+ });
87
+ }
88
+ announceSuiteStartsFor(suite) {
89
+ const suiteId = CorrelationId.create();
90
+ this.suiteIds.push(suiteId);
91
+ const details = new TestSuiteDetails(new Name(suite.title), new FileSystemLocation(Path.from(suite.file)), // all suites except for the root suite should have .file property set
92
+ suiteId);
93
+ this.emit(new TestSuiteStarts(details, this.serenity.currentTime()));
94
+ }
95
+ announceSuiteFinishedFor(suite) {
96
+ const details = new TestSuiteDetails(new Name(suite.title), new FileSystemLocation(Path.from(suite.file)), // all suites except for the root suite should have .file property set
97
+ this.suiteIds.pop());
98
+ const outcomes = suite.tests.map(test => this.recorder.outcomeOf(test) || this.outcomeMapper.outcomeOf(test));
99
+ const worstOutcome = outcomes.reduce((worstSoFar, outcome) => outcome.isWorseThan(worstSoFar)
100
+ ? outcome
101
+ : worstSoFar, new ExecutionSuccessful());
102
+ this.emit(new TestSuiteFinished(details, worstOutcome, this.serenity.currentTime()));
103
+ }
104
+ announceSceneStartsFor(test) {
105
+ this.currentSceneId = this.serenity.assignNewSceneId();
106
+ const { scenarioDetails, scenarioTags } = this.testMapper.detailsOf(test);
107
+ this.emit(new SceneStarts(this.currentSceneId, scenarioDetails, this.serenity.currentTime()), ...this.requirementsHierarchy.requirementTagsFor(scenarioDetails.location.path, scenarioDetails.category.value)
108
+ .map(tag => new SceneTagged(this.currentSceneId, tag, this.serenity.currentTime())), new TestRunnerDetected(this.currentSceneId, new Name('Mocha'), this.serenity.currentTime()), ...scenarioTags.map(tag => new SceneTagged(this.currentSceneId, tag, this.serenity.currentTime())));
109
+ }
110
+ announceSceneFinishedFor(test, runnable) {
111
+ const { scenarioDetails } = this.testMapper.detailsOf(test), outcome = this.recorder.outcomeOf(test) || this.outcomeMapper.outcomeOf(test);
112
+ this.emit(new SceneFinishes(this.currentSceneId, outcome, this.serenity.currentTime()));
113
+ return this.serenity.waitForNextCue()
114
+ .then(() => {
115
+ this.emit(new SceneFinished(this.currentSceneId, scenarioDetails, outcome, this.serenity.currentTime()));
116
+ this.recorder.erase(test);
117
+ }, error => {
118
+ const errorOutcome = new ExecutionFailedWithError(error);
119
+ this.emit(new SceneFinished(this.currentSceneId, scenarioDetails, errorOutcome.isWorseThan(outcome)
120
+ ? errorOutcome
121
+ : outcome, this.serenity.currentTime()));
122
+ this.recorder.erase(test);
123
+ // re-throwing an error here would cause Mocha to halt test suite, which we don't want to do
124
+ // https://github.com/mochajs/mocha/issues/1635
125
+ runnable.error(error);
126
+ });
127
+ }
128
+ announceSceneSkippedFor(test) {
129
+ const { scenarioDetails } = this.testMapper.detailsOf(test), outcome = this.outcomeMapper.outcomeOf(test);
130
+ this.announceSceneStartsFor(test);
131
+ this.emit(new SceneFinishes(this.currentSceneId, outcome, this.serenity.currentTime()), new SceneFinished(this.currentSceneId, scenarioDetails, outcome, this.serenity.currentTime()));
132
+ }
133
+ announceRetryIfNeeded(test) {
134
+ if (!this.isRetriable(test)) {
135
+ return void 0;
136
+ }
137
+ // todo: RetryableSceneDetected(maxRetries) ?
138
+ this.emit(new RetryableSceneDetected(this.currentSceneId, this.serenity.currentTime()), new SceneTagged(this.currentSceneId, new ArbitraryTag('retried'), // todo: replace with a dedicated tag
139
+ this.serenity.currentTime()));
140
+ if (this.currentRetryOf(test) > 0) {
141
+ this.emit(new SceneTagged(this.currentSceneId, new ExecutionRetriedTag(this.currentRetryOf(test)), this.serenity.currentTime()));
142
+ }
143
+ }
144
+ isRetriable(test) {
145
+ return test.retries() >= 0;
146
+ }
147
+ currentRetryOf(test) {
148
+ return test.currentRetry();
149
+ }
150
+ emit(...events) {
151
+ events.forEach(event => this.serenity.announce(event));
152
+ }
153
+ }
154
+ //# sourceMappingURL=SerenityReporterForMocha.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SerenityReporterForMocha.js","sourceRoot":"","sources":["../src/SerenityReporterForMocha.ts"],"names":[],"mappings":"AAEA,OAAO,EACH,sBAAsB,EACtB,aAAa,EACb,aAAa,EACb,WAAW,EACX,WAAW,EACX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I,CACL,IAAI,sBAAsB,CACtB,IAAI,CAAC,cAAc,EACnB,IAAI,CAAC,QAAQ,CAAC,WAAW,EAAE,CAC9B,EACD,IAAI,WAAW,CACX,IAAI,CAAC,cAAc,EACnB,IAAI,YAAY,CAAC,SAAS,CAAC,EAAS,qCAAqC;QACzE,IAAI,CAAC,QAAQ,CAAC,WAAW,EAAE,CAC9B,CACJ,CAAC;QAEF,IAAI,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;YAChC,IAAI,CAAC,IAAI,CACL,IAAI,WAAW,CACX,IAAI,CAAC,cAAc,EACnB,IAAI,mBAAmB,CAAC,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,EAClD,IAAI,CAAC,QAAQ,CAAC,WAAW,EAAE,CAC9B,CACJ,CAAC;QACN,CAAC;IACL,CAAC;IAEO,WAAW,CAAC,IAAU;QAC1B,OAAQ,IAAY,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IACxC,CAAC;IAEO,cAAc,CAAC,IAAU;QAC7B,OAAQ,IAAY,CAAC,YAAY,EAAE,CAAC;IACxC,CAAC;IAEO,IAAI,CAAC,GAAG,MAAqB;QACjC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC;IAC3D,CAAC;CACJ"}
@@ -0,0 +1,48 @@
1
+ import type { TestRunnerAdapter } from '@serenity-js/core/adapter';
2
+ import type { ModuleLoader } from '@serenity-js/core/io';
3
+ import type { Outcome } from '@serenity-js/core/model';
4
+ import type { MochaConfig } from './MochaConfig.js';
5
+ /**
6
+ * Allows for programmatic execution of Mocha test scenarios,
7
+ * using [`SerenityReporterForMocha`](https://serenity-js.org/api/mocha/function/export=/) to report progress.
8
+ *
9
+ * ## Learn more
10
+ * - [`TestRunnerAdapter`](https://serenity-js.org/api/core-adapter/interface/TestRunnerAdapter/)
11
+ *
12
+ * @group Integration
13
+ */
14
+ export declare class MochaAdapter implements TestRunnerAdapter {
15
+ private readonly config;
16
+ private readonly loader;
17
+ private mocha;
18
+ private totalScenarios;
19
+ constructor(config: MochaConfig, loader: ModuleLoader);
20
+ /**
21
+ * Scenario success threshold for this test runner.
22
+ */
23
+ successThreshold(): Outcome | {
24
+ Code: number;
25
+ };
26
+ /**
27
+ * Loads test scenarios.
28
+ *
29
+ * @param pathsToScenarios
30
+ */
31
+ load(pathsToScenarios: string[]): Promise<void>;
32
+ /**
33
+ * Returns the number of loaded scenarios
34
+ *
35
+ * @throws [`LogicError`](https://serenity-js.org/api/core/class/LogicError/)
36
+ * If called before `load`
37
+ */
38
+ scenarioCount(): number;
39
+ /**
40
+ * Runs loaded test scenarios.
41
+ *
42
+ * @throws [`LogicError`](https://serenity-js.org/api/core/class/LogicError/)
43
+ * If called before `load`
44
+ */
45
+ run(): Promise<void>;
46
+ private requireAny;
47
+ }
48
+ //# sourceMappingURL=MochaAdapter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MochaAdapter.d.ts","sourceRoot":"","sources":["../../src/adapter/MochaAdapter.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AACnE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAKvD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAEpD;;;;;;;;GAQG;AACH,qBAAa,YAAa,YAAW,iBAAiB;IAM9C,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,MAAM;IAL3B,OAAO,CAAC,KAAK,CAAQ;IACrB,OAAO,CAAC,cAAc,CAAS;gBAGV,MAAM,EAAE,WAAW,EACnB,MAAM,EAAE,YAAY;IAIzC;;OAEG;IACH,gBAAgB,IAAI,OAAO,GAAG;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE;IAM9C;;;;OAIG;IACG,IAAI,CAAC,gBAAgB,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IA6BrD;;;;;OAKG;IACH,aAAa,IAAI,MAAM;IAQvB;;;;;OAKG;IACH,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;IAUpB,OAAO,CAAC,UAAU;CAarB"}
@@ -0,0 +1,95 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { LogicError } from '@serenity-js/core';
4
+ import { ExecutionIgnored, ImplementationPending } from '@serenity-js/core/model';
5
+ import reporter from '../index.js';
6
+ /**
7
+ * Allows for programmatic execution of Mocha test scenarios,
8
+ * using [`SerenityReporterForMocha`](https://serenity-js.org/api/mocha/function/export=/) to report progress.
9
+ *
10
+ * ## Learn more
11
+ * - [`TestRunnerAdapter`](https://serenity-js.org/api/core-adapter/interface/TestRunnerAdapter/)
12
+ *
13
+ * @group Integration
14
+ */
15
+ export class MochaAdapter {
16
+ config;
17
+ loader;
18
+ mocha;
19
+ totalScenarios;
20
+ constructor(config, loader) {
21
+ this.config = config;
22
+ this.loader = loader;
23
+ }
24
+ /**
25
+ * Scenario success threshold for this test runner.
26
+ */
27
+ successThreshold() {
28
+ return this.config.strict
29
+ ? ExecutionIgnored
30
+ : ImplementationPending;
31
+ }
32
+ /**
33
+ * Loads test scenarios.
34
+ *
35
+ * @param pathsToScenarios
36
+ */
37
+ async load(pathsToScenarios) {
38
+ const _Mocha = this.loader.require('mocha');
39
+ this.mocha = new _Mocha({
40
+ ...this.config,
41
+ reporter: reporter,
42
+ });
43
+ this.mocha.fullTrace();
44
+ this.mocha.files = pathsToScenarios;
45
+ this.mocha.suite.on('pre-require', (context, file, mocha) => {
46
+ this.requireAny(this.config.require);
47
+ });
48
+ await this.mocha.loadFilesAsync();
49
+ const mochaRunner = new _Mocha.Runner(this.mocha.suite, {
50
+ delay: false,
51
+ });
52
+ if (this.config.grep) {
53
+ mochaRunner.grep(this.mocha.options.grep, this.config.invert);
54
+ }
55
+ this.totalScenarios = mochaRunner.total;
56
+ }
57
+ /**
58
+ * Returns the number of loaded scenarios
59
+ *
60
+ * @throws [`LogicError`](https://serenity-js.org/api/core/class/LogicError/)
61
+ * If called before `load`
62
+ */
63
+ scenarioCount() {
64
+ if (this.totalScenarios === undefined) {
65
+ throw new LogicError('Make sure to call `load` before calling `scenarioCount`');
66
+ }
67
+ return this.totalScenarios;
68
+ }
69
+ /**
70
+ * Runs loaded test scenarios.
71
+ *
72
+ * @throws [`LogicError`](https://serenity-js.org/api/core/class/LogicError/)
73
+ * If called before `load`
74
+ */
75
+ run() {
76
+ return new Promise((resolve, reject) => {
77
+ if (this.mocha === undefined) {
78
+ throw new LogicError('Make sure to call `load` before calling `run`');
79
+ }
80
+ this.mocha.run(numberOfFailures => resolve());
81
+ });
82
+ }
83
+ requireAny(filesOrModules) {
84
+ const requires = filesOrModules
85
+ ? [].concat(filesOrModules).filter(item => !!item)
86
+ : [];
87
+ requires.forEach(fileOrModule => {
88
+ const required = fs.existsSync(fileOrModule) || fs.existsSync(`${fileOrModule}.js`)
89
+ ? path.resolve(fileOrModule) // local file
90
+ : fileOrModule; // module
91
+ this.loader.require(required);
92
+ });
93
+ }
94
+ }
95
+ //# sourceMappingURL=MochaAdapter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MochaAdapter.js","sourceRoot":"","sources":["../../src/adapter/MochaAdapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAI/C,OAAO,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAGlF,OAAO,QAAQ,MAAM,aAAa,CAAC;AAGnC;;;;;;;;GAQG;AACH,MAAM,OAAO,YAAY;IAMA;IACA;IAL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3
+ *
4
+ * ## Learn more
5
+ *
6
+ * - [`.mocharc.yml` example](https://github.com/mochajs/mocha/blob/v8.0.1/example/config/.mocharc.yml)
7
+ *
8
+ * @group Configuration
9
+ */
10
+ export interface MochaConfig {
11
+ /**
12
+ * Path to config file.
13
+ *
14
+ * #### Learn more
15
+ * - [Mocha configuration examples](https://github.com/mochajs/mocha/tree/v8.0.1/example/config)
16
+ */
17
+ config?: string;
18
+ /**
19
+ * Allow uncaught errors to propagate.
20
+ */
21
+ 'allow-uncaught'?: boolean;
22
+ /**
23
+ * Require all tests to use a callback (async) or return a Promise.
24
+ */
25
+ 'async-only'?: boolean;
26
+ /**
27
+ * Abort ("bail") after first test failure.
28
+ */
29
+ bail?: boolean;
30
+ /**
31
+ * Check for global variable leaks.
32
+ */
33
+ 'check-leaks'?: boolean;
34
+ /**
35
+ * Delay initial execution of root suite.
36
+ */
37
+ delay?: boolean;
38
+ /**
39
+ * Only run tests containing this string.
40
+ *
41
+ * **Note:** [`MochaConfig.fgrep`](https://serenity-js.org/api/mocha-adapter/interface/MochaConfig/#fgrep) and [`MochaConfig.grep`](https://serenity-js.org/api/mocha-adapter/interface/MochaConfig/#grep) are mutually exclusive.
42
+ */
43
+ fgrep?: string;
44
+ /**
45
+ * Files to be loaded prior to root suite execution.
46
+ */
47
+ file?: string[];
48
+ /**
49
+ * Fail if exclusive test(s) encountered.
50
+ */
51
+ 'forbid-only'?: boolean;
52
+ /**
53
+ * Fail if pending test(s) encountered.
54
+ */
55
+ 'forbid-pending': boolean;
56
+ /**
57
+ * List of allowed global variables.
58
+ */
59
+ global?: string[];
60
+ /**
61
+ * Only run tests matching this string or regexp.
62
+ *
63
+ * **Note:** [`MochaConfig.grep`](https://serenity-js.org/api/mocha-adapter/interface/MochaConfig/#grep) and [`MochaConfig.fgrep`](https://serenity-js.org/api/mocha-adapter/interface/MochaConfig/#fgrep) are mutually exclusive.
64
+ */
65
+ grep?: string | RegExp;
66
+ /**
67
+ * Enable Growl notifications.
68
+ */
69
+ growl?: boolean;
70
+ /**
71
+ * Inverts [`MochaConfig.grep`](https://serenity-js.org/api/mocha-adapter/interface/MochaConfig/#grep) and [`MochaConfig.fgrep`](https://serenity-js.org/api/mocha-adapter/interface/MochaConfig/#fgrep) matches.
72
+ */
73
+ invert?: boolean;
74
+ /**
75
+ * Require module.
76
+ */
77
+ require?: string[];
78
+ /**
79
+ * Retry failed tests this many times.
80
+ */
81
+ retries?: number;
82
+ /**
83
+ * Specify "slow" test threshold (in milliseconds).
84
+ */
85
+ slow?: number;
86
+ /**
87
+ * Specify test timeout threshold (in milliseconds).
88
+ *
89
+ * **Note:** setting this property to 0 means "no timeout".
90
+ */
91
+ timeout?: number;
92
+ /**
93
+ * Specify user interface. Defaults to `bdd`.
94
+ *
95
+ * #### Learn more
96
+ *
97
+ * - [Mocha interfaces](https://mochajs.org/#interfaces)
98
+ */
99
+ ui?: string;
100
+ /**
101
+ * When set to `true`, a skipped test is considered a failure.
102
+ */
103
+ strict?: boolean;
104
+ }
105
+ //# sourceMappingURL=MochaConfig.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MochaConfig.d.ts","sourceRoot":"","sources":["../../src/adapter/MochaConfig.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,MAAM,WAAW,WAAW;IAExB;;;;;OAKG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAE3B;;OAEG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;IAEvB;;OAEG;IACH,IAAI,CAAC,EAAE,OAAO,CAAC;IAEf;;OAEG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IAExB;;OAEG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;IAEhB;;;;OAIG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAEhB;;OAEG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IAExB;;OAEG;IACH,gBAAgB,EAAE,OAAO,CAAC;IAE1B;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAElB;;;;OAIG;IACH,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAEvB;;OAEG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;IAEhB;;OAEG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;IAEjB;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IAEnB;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;;;;;OAMG;IACH,EAAE,CAAC,EAAE,MAAM,CAAC;IAEZ;;OAEG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;CACpB"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=MochaConfig.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MochaConfig.js","sourceRoot":"","sources":["../../src/adapter/MochaConfig.ts"],"names":[],"mappings":""}
@@ -0,0 +1,3 @@
1
+ export * from './MochaAdapter.js';
2
+ export * from './MochaConfig.js';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/adapter/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC"}
@@ -0,0 +1,3 @@
1
+ export * from './MochaAdapter.js';
2
+ export * from './MochaConfig.js';
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/adapter/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC"}
package/esm/index.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ import type { MochaOptions, Runner } from 'mocha';
2
+ import { SerenityReporterForMocha } from './SerenityReporterForMocha.js';
3
+ /**
4
+ * Registers a Mocha reporter that emits [Serenity/JS domain events](https://serenity-js.org/api/core-events/class/DomainEvent/)
5
+ * and informs Serenity/JS when a test scenario starts, finishes, and with what result.
6
+ */
7
+ declare function bootstrap(runner: Runner, options?: MochaOptions): SerenityReporterForMocha;
8
+ export default bootstrap;
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAElD,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AAEzE;;;GAGG;AACH,iBAAS,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,wBAAwB,CAQnF;AAED,eAAe,SAAS,CAAC"}
package/esm/index.js ADDED
@@ -0,0 +1,20 @@
1
+ import { serenity } from '@serenity-js/core';
2
+ import { FileSystem, Path, RequirementsHierarchy } from '@serenity-js/core/io';
3
+ import { SerenityReporterForMocha } from './SerenityReporterForMocha.js';
4
+ /**
5
+ * Registers a Mocha reporter that emits [Serenity/JS domain events](https://serenity-js.org/api/core-events/class/DomainEvent/)
6
+ * and informs Serenity/JS when a test scenario starts, finishes, and with what result.
7
+ */
8
+ function bootstrap(runner, options) {
9
+ const cwd = Path.from(process.cwd());
10
+ const requirementsHierarchy = new RequirementsHierarchy(new FileSystem(cwd), options?.reporterOptions?.specDirectory && cwd.resolve(Path.from(options?.reporterOptions?.specDirectory)));
11
+ return new SerenityReporterForMocha(serenity, requirementsHierarchy, runner, options);
12
+ }
13
+ export default bootstrap;
14
+ // CommonJS compatibility - assign to module.exports for Mocha reporter loading
15
+ // This is needed because Mocha expects module.exports to be the reporter function
16
+ if (typeof module !== 'undefined' && module.exports) {
17
+ module.exports = bootstrap;
18
+ module.exports.default = bootstrap;
19
+ }
20
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAG/E,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AAEzE;;;GAGG;AACH,SAAS,SAAS,CAAC,MAAc,EAAE,OAAsB;IACrD,MAAM,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;IACrC,MAAM,qBAAqB,GAAG,IAAI,qBAAqB,CACnD,IAAI,UAAU,CAAC,GAAG,CAAC,EACnB,OAAO,EAAE,eAAe,EAAE,aAAa,IAAI,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,eAAe,EAAE,aAAa,CAAC,CAAC,CAC7G,CAAC;IAEF,OAAO,IAAI,wBAAwB,CAAC,QAAQ,EAAE,qBAAqB,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;AAC1F,CAAC;AAED,eAAe,SAAS,CAAC;AAEzB,+EAA+E;AAC/E,kFAAkF;AAClF,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;IAClD,MAAM,CAAC,OAAO,GAAG,SAAS,CAAC;IAC3B,MAAM,CAAC,OAAO,CAAC,OAAO,GAAG,SAAS,CAAC;AACvC,CAAC"}
@@ -0,0 +1,12 @@
1
+ import type { Outcome } from '@serenity-js/core/model';
2
+ import type { Test } from 'mocha';
3
+ /**
4
+ * @package
5
+ */
6
+ export declare class MochaOutcomeMapper {
7
+ outcomeOf(test: Test, maybeError?: Error): Outcome;
8
+ private isGoingToBeRetried;
9
+ private isAssertionError;
10
+ private looksLikeAnAssertionError;
11
+ }
12
+ //# sourceMappingURL=MochaOutcomeMapper.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MochaOutcomeMapper.d.ts","sourceRoot":"","sources":["../../src/mappers/MochaOutcomeMapper.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACR,OAAO,EAAC,MAAM,yBAAyB,CAAC;AAU5C,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC;AAElC;;GAEG;AACH,qBAAa,kBAAkB;IACpB,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,UAAU,CAAC,EAAE,KAAK,GAAG,OAAO;IA2BzD,OAAO,CAAC,kBAAkB;IAO1B,OAAO,CAAC,gBAAgB;IAKxB,OAAO,CAAC,yBAAyB;CAKpC"}