allure-cucumberjs 3.0.0-beta.2 → 3.0.0-beta.4

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.
@@ -4,32 +4,15 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.AllureCucumberTestRuntime = void 0;
7
+ var _cucumber = require("@cucumber/cucumber");
7
8
  var _reporter = require("allure-js-commons/sdk/reporter");
8
9
  var _runtime = require("allure-js-commons/sdk/runtime");
9
10
  function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
10
11
  function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
11
- function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
12
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
13
- function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
14
12
  class AllureCucumberTestRuntime extends _runtime.MessageTestRuntime {
15
- constructor(_ref) {
16
- var {
17
- attach,
18
- log,
19
- parameters
20
- } = _ref;
21
- super();
22
- _defineProperty(this, "attach", void 0);
23
- _defineProperty(this, "log", void 0);
24
- _defineProperty(this, "parameters", void 0);
25
- this.attach = attach;
26
- this.log = log;
27
- this.parameters = parameters;
28
- }
29
13
  sendMessage(message) {
30
- var _this = this;
31
14
  return _asyncToGenerator(function* () {
32
- _this.attach(JSON.stringify(message), _reporter.ALLURE_RUNTIME_MESSAGE_CONTENT_TYPE);
15
+ _cucumber.world.attach(JSON.stringify(message), _reporter.ALLURE_RUNTIME_MESSAGE_CONTENT_TYPE);
33
16
  yield Promise.resolve();
34
17
  })();
35
18
  }
@@ -1 +1 @@
1
- {"version":3,"file":"runtime.js","names":["_reporter","require","_runtime","asyncGeneratorStep","n","t","e","r","o","a","c","i","u","value","done","Promise","resolve","then","_asyncToGenerator","arguments","apply","_next","_throw","_defineProperty","_toPropertyKey","Object","defineProperty","enumerable","configurable","writable","_toPrimitive","Symbol","toPrimitive","call","TypeError","String","Number","AllureCucumberTestRuntime","MessageTestRuntime","constructor","_ref","attach","log","parameters","sendMessage","message","_this","JSON","stringify","ALLURE_RUNTIME_MESSAGE_CONTENT_TYPE","exports"],"sources":["../../src/runtime.ts"],"sourcesContent":["import type { IWorld, IWorldOptions } from \"@cucumber/cucumber\";\nimport type { RuntimeMessage } from \"allure-js-commons/sdk\";\nimport { ALLURE_RUNTIME_MESSAGE_CONTENT_TYPE } from \"allure-js-commons/sdk/reporter\";\nimport { MessageTestRuntime } from \"allure-js-commons/sdk/runtime\";\n\nexport class AllureCucumberTestRuntime extends MessageTestRuntime implements IWorld {\n public readonly attach: IWorldOptions[\"attach\"];\n public readonly log: IWorldOptions[\"log\"];\n public readonly parameters: IWorldOptions[\"parameters\"];\n\n constructor({ attach, log, parameters }: IWorldOptions) {\n super();\n this.attach = attach;\n this.log = log;\n this.parameters = parameters;\n }\n\n async sendMessage(message: RuntimeMessage) {\n this.attach(JSON.stringify(message), ALLURE_RUNTIME_MESSAGE_CONTENT_TYPE as string);\n await Promise.resolve();\n }\n}\n"],"mappings":";;;;;;AAEA,IAAAA,SAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AAAmE,SAAAE,mBAAAC,CAAA,EAAAC,CAAA,EAAAC,CAAA,EAAAC,CAAA,EAAAC,CAAA,EAAAC,CAAA,EAAAC,CAAA,cAAAC,CAAA,GAAAP,CAAA,CAAAK,CAAA,EAAAC,CAAA,GAAAE,CAAA,GAAAD,CAAA,CAAAE,KAAA,WAAAT,CAAA,gBAAAE,CAAA,CAAAF,CAAA,KAAAO,CAAA,CAAAG,IAAA,GAAAT,CAAA,CAAAO,CAAA,IAAAG,OAAA,CAAAC,OAAA,CAAAJ,CAAA,EAAAK,IAAA,CAAAV,CAAA,EAAAC,CAAA;AAAA,SAAAU,kBAAAd,CAAA,6BAAAC,CAAA,SAAAC,CAAA,GAAAa,SAAA,aAAAJ,OAAA,WAAAR,CAAA,EAAAC,CAAA,QAAAC,CAAA,GAAAL,CAAA,CAAAgB,KAAA,CAAAf,CAAA,EAAAC,CAAA,YAAAe,MAAAjB,CAAA,IAAAD,kBAAA,CAAAM,CAAA,EAAAF,CAAA,EAAAC,CAAA,EAAAa,KAAA,EAAAC,MAAA,UAAAlB,CAAA,cAAAkB,OAAAlB,CAAA,IAAAD,kBAAA,CAAAM,CAAA,EAAAF,CAAA,EAAAC,CAAA,EAAAa,KAAA,EAAAC,MAAA,WAAAlB,CAAA,KAAAiB,KAAA;AAAA,SAAAE,gBAAAjB,CAAA,EAAAC,CAAA,EAAAF,CAAA,YAAAE,CAAA,GAAAiB,cAAA,CAAAjB,CAAA,MAAAD,CAAA,GAAAmB,MAAA,CAAAC,cAAA,CAAApB,CAAA,EAAAC,CAAA,IAAAM,KAAA,EAAAR,CAAA,EAAAsB,UAAA,MAAAC,YAAA,MAAAC,QAAA,UAAAvB,CAAA,CAAAC,CAAA,IAAAF,CAAA,EAAAC,CAAA;AAAA,SAAAkB,eAAAnB,CAAA,QAAAM,CAAA,GAAAmB,YAAA,CAAAzB,CAAA,uCAAAM,CAAA,GAAAA,CAAA,GAAAA,CAAA;AAAA,SAAAmB,aAAAzB,CAAA,EAAAE,CAAA,2BAAAF,CAAA,KAAAA,CAAA,SAAAA,CAAA,MAAAC,CAAA,GAAAD,CAAA,CAAA0B,MAAA,CAAAC,WAAA,kBAAA1B,CAAA,QAAAK,CAAA,GAAAL,CAAA,CAAA2B,IAAA,CAAA5B,CAAA,EAAAE,CAAA,uCAAAI,CAAA,SAAAA,CAAA,YAAAuB,SAAA,yEAAA3B,CAAA,GAAA4B,MAAA,GAAAC,MAAA,EAAA/B,CAAA;AAE5D,MAAMgC,yBAAyB,SAASC,2BAAkB,CAAmB;EAKlFC,WAAWA,CAAAC,IAAA,EAA6C;IAAA,IAA5C;MAAEC,MAAM;MAAEC,GAAG;MAAEC;IAA0B,CAAC,GAAAH,IAAA;IACpD,KAAK,CAAC,CAAC;IAACjB,eAAA;IAAAA,eAAA;IAAAA,eAAA;IACR,IAAI,CAACkB,MAAM,GAAGA,MAAM;IACpB,IAAI,CAACC,GAAG,GAAGA,GAAG;IACd,IAAI,CAACC,UAAU,GAAGA,UAAU;EAC9B;EAEMC,WAAWA,CAACC,OAAuB,EAAE;IAAA,IAAAC,KAAA;IAAA,OAAA5B,iBAAA;MACzC4B,KAAI,CAACL,MAAM,CAACM,IAAI,CAACC,SAAS,CAACH,OAAO,CAAC,EAAEI,6CAA6C,CAAC;MACnF,MAAMlC,OAAO,CAACC,OAAO,CAAC,CAAC;IAAC;EAC1B;AACF;AAACkC,OAAA,CAAAb,yBAAA,GAAAA,yBAAA","ignoreList":[]}
1
+ {"version":3,"file":"runtime.js","names":["_cucumber","require","_reporter","_runtime","asyncGeneratorStep","n","t","e","r","o","a","c","i","u","value","done","Promise","resolve","then","_asyncToGenerator","arguments","apply","_next","_throw","AllureCucumberTestRuntime","MessageTestRuntime","sendMessage","message","world","attach","JSON","stringify","ALLURE_RUNTIME_MESSAGE_CONTENT_TYPE","exports"],"sources":["../../src/runtime.ts"],"sourcesContent":["import { world } from \"@cucumber/cucumber\";\nimport type { RuntimeMessage } from \"allure-js-commons/sdk\";\nimport { ALLURE_RUNTIME_MESSAGE_CONTENT_TYPE } from \"allure-js-commons/sdk/reporter\";\nimport { MessageTestRuntime } from \"allure-js-commons/sdk/runtime\";\n\nexport class AllureCucumberTestRuntime extends MessageTestRuntime {\n async sendMessage(message: RuntimeMessage) {\n world.attach(JSON.stringify(message), ALLURE_RUNTIME_MESSAGE_CONTENT_TYPE as string);\n await Promise.resolve();\n }\n}\n"],"mappings":";;;;;;AAAA,IAAAA,SAAA,GAAAC,OAAA;AAEA,IAAAC,SAAA,GAAAD,OAAA;AACA,IAAAE,QAAA,GAAAF,OAAA;AAAmE,SAAAG,mBAAAC,CAAA,EAAAC,CAAA,EAAAC,CAAA,EAAAC,CAAA,EAAAC,CAAA,EAAAC,CAAA,EAAAC,CAAA,cAAAC,CAAA,GAAAP,CAAA,CAAAK,CAAA,EAAAC,CAAA,GAAAE,CAAA,GAAAD,CAAA,CAAAE,KAAA,WAAAT,CAAA,gBAAAE,CAAA,CAAAF,CAAA,KAAAO,CAAA,CAAAG,IAAA,GAAAT,CAAA,CAAAO,CAAA,IAAAG,OAAA,CAAAC,OAAA,CAAAJ,CAAA,EAAAK,IAAA,CAAAV,CAAA,EAAAC,CAAA;AAAA,SAAAU,kBAAAd,CAAA,6BAAAC,CAAA,SAAAC,CAAA,GAAAa,SAAA,aAAAJ,OAAA,WAAAR,CAAA,EAAAC,CAAA,QAAAC,CAAA,GAAAL,CAAA,CAAAgB,KAAA,CAAAf,CAAA,EAAAC,CAAA,YAAAe,MAAAjB,CAAA,IAAAD,kBAAA,CAAAM,CAAA,EAAAF,CAAA,EAAAC,CAAA,EAAAa,KAAA,EAAAC,MAAA,UAAAlB,CAAA,cAAAkB,OAAAlB,CAAA,IAAAD,kBAAA,CAAAM,CAAA,EAAAF,CAAA,EAAAC,CAAA,EAAAa,KAAA,EAAAC,MAAA,WAAAlB,CAAA,KAAAiB,KAAA;AAE5D,MAAME,yBAAyB,SAASC,2BAAkB,CAAC;EAC1DC,WAAWA,CAACC,OAAuB,EAAE;IAAA,OAAAR,iBAAA;MACzCS,eAAK,CAACC,MAAM,CAACC,IAAI,CAACC,SAAS,CAACJ,OAAO,CAAC,EAAEK,6CAA6C,CAAC;MACpF,MAAMhB,OAAO,CAACC,OAAO,CAAC,CAAC;IAAC;EAC1B;AACF;AAACgB,OAAA,CAAAT,yBAAA,GAAAA,yBAAA","ignoreList":[]}
package/dist/esm/index.js CHANGED
@@ -1,16 +1,31 @@
1
- import { Before } from "@cucumber/cucumber";
1
+ import { Before, BeforeAll, world } from "@cucumber/cucumber";
2
+ import { includedInTestPlan } from "allure-js-commons/sdk/reporter";
3
+ import { parseTestPlan } from "allure-js-commons/sdk/reporter";
2
4
  import { setGlobalTestRuntime } from "allure-js-commons/sdk/runtime";
3
5
  import { AllureCucumberWorld } from "./legacy.js";
4
6
  import { AllureCucumberTestRuntime } from "./runtime.js";
5
- Before(function () {
6
- // TODO: we can implement testplan logic there
7
- setGlobalTestRuntime(
8
- // @ts-ignore
9
- new AllureCucumberTestRuntime({
10
- attach: this.attach,
11
- log: this.log,
12
- parameters: this.parameters
13
- }));
7
+ BeforeAll(() => {
8
+ setGlobalTestRuntime(new AllureCucumberTestRuntime());
9
+ });
10
+ Before({
11
+ name: "ALLURE_FIXTURE_IGNORE"
12
+ }, scenario => {
13
+ var testPlan = parseTestPlan();
14
+ if (!testPlan) {
15
+ return;
16
+ }
17
+ var pickle = scenario.pickle;
18
+ var fullName = "".concat(pickle.uri, "#").concat(pickle.name);
19
+ var tags = pickle.tags.map(tag => tag.name);
20
+ if (!includedInTestPlan(testPlan, {
21
+ fullName,
22
+ tags
23
+ })) {
24
+ // we can't use regular message or Allure facade since we need label to be added
25
+ // to test, not fixture
26
+ world.attach(Buffer.from("allure-skip"), "application/vnd.allure.skipcucumber+json");
27
+ return "skipped";
28
+ }
14
29
  });
15
30
  export { AllureCucumberTestRuntime, AllureCucumberWorld };
16
31
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["Before","setGlobalTestRuntime","AllureCucumberWorld","AllureCucumberTestRuntime","attach","log","parameters"],"sources":["../../src/index.ts"],"sourcesContent":["import { Before } from \"@cucumber/cucumber\";\nimport { setGlobalTestRuntime } from \"allure-js-commons/sdk/runtime\";\nimport { AllureCucumberWorld } from \"./legacy.js\";\nimport { AllureCucumberTestRuntime } from \"./runtime.js\";\n\nBefore(function () {\n // TODO: we can implement testplan logic there\n setGlobalTestRuntime(\n // @ts-ignore\n new AllureCucumberTestRuntime({\n attach: this.attach,\n log: this.log,\n parameters: this.parameters,\n }),\n );\n});\n\nexport { AllureCucumberTestRuntime, AllureCucumberWorld };\n"],"mappings":"AAAA,SAASA,MAAM,QAAQ,oBAAoB;AAC3C,SAASC,oBAAoB,QAAQ,+BAA+B;AACpE,SAASC,mBAAmB,QAAQ,aAAa;AACjD,SAASC,yBAAyB,QAAQ,cAAc;AAExDH,MAAM,CAAC,YAAY;EACjB;EACAC,oBAAoB;EAClB;EACA,IAAIE,yBAAyB,CAAC;IAC5BC,MAAM,EAAE,IAAI,CAACA,MAAM;IACnBC,GAAG,EAAE,IAAI,CAACA,GAAG;IACbC,UAAU,EAAE,IAAI,CAACA;EACnB,CAAC,CACH,CAAC;AACH,CAAC,CAAC;AAEF,SAASH,yBAAyB,EAAED,mBAAmB","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["Before","BeforeAll","world","includedInTestPlan","parseTestPlan","setGlobalTestRuntime","AllureCucumberWorld","AllureCucumberTestRuntime","name","scenario","testPlan","pickle","fullName","concat","uri","tags","map","tag","attach","Buffer","from"],"sources":["../../src/index.ts"],"sourcesContent":["import { Before, BeforeAll, world } from \"@cucumber/cucumber\";\nimport { includedInTestPlan } from \"allure-js-commons/sdk/reporter\";\nimport { parseTestPlan } from \"allure-js-commons/sdk/reporter\";\nimport { setGlobalTestRuntime } from \"allure-js-commons/sdk/runtime\";\nimport { AllureCucumberWorld } from \"./legacy.js\";\nimport { AllureCucumberTestRuntime } from \"./runtime.js\";\n\nBeforeAll(() => {\n setGlobalTestRuntime(new AllureCucumberTestRuntime());\n});\n\nBefore({ name: \"ALLURE_FIXTURE_IGNORE\" }, (scenario) => {\n const testPlan = parseTestPlan();\n if (!testPlan) {\n return;\n }\n const pickle = scenario.pickle;\n const fullName = `${pickle.uri}#${pickle.name}`;\n const tags = pickle.tags.map((tag) => tag.name);\n\n if (!includedInTestPlan(testPlan, { fullName, tags })) {\n // we can't use regular message or Allure facade since we need label to be added\n // to test, not fixture\n world.attach(Buffer.from(\"allure-skip\"), \"application/vnd.allure.skipcucumber+json\");\n return \"skipped\";\n }\n});\n\nexport { AllureCucumberTestRuntime, AllureCucumberWorld };\n"],"mappings":"AAAA,SAASA,MAAM,EAAEC,SAAS,EAAEC,KAAK,QAAQ,oBAAoB;AAC7D,SAASC,kBAAkB,QAAQ,gCAAgC;AACnE,SAASC,aAAa,QAAQ,gCAAgC;AAC9D,SAASC,oBAAoB,QAAQ,+BAA+B;AACpE,SAASC,mBAAmB,QAAQ,aAAa;AACjD,SAASC,yBAAyB,QAAQ,cAAc;AAExDN,SAAS,CAAC,MAAM;EACdI,oBAAoB,CAAC,IAAIE,yBAAyB,CAAC,CAAC,CAAC;AACvD,CAAC,CAAC;AAEFP,MAAM,CAAC;EAAEQ,IAAI,EAAE;AAAwB,CAAC,EAAGC,QAAQ,IAAK;EACtD,IAAMC,QAAQ,GAAGN,aAAa,CAAC,CAAC;EAChC,IAAI,CAACM,QAAQ,EAAE;IACb;EACF;EACA,IAAMC,MAAM,GAAGF,QAAQ,CAACE,MAAM;EAC9B,IAAMC,QAAQ,MAAAC,MAAA,CAAMF,MAAM,CAACG,GAAG,OAAAD,MAAA,CAAIF,MAAM,CAACH,IAAI,CAAE;EAC/C,IAAMO,IAAI,GAAGJ,MAAM,CAACI,IAAI,CAACC,GAAG,CAAEC,GAAG,IAAKA,GAAG,CAACT,IAAI,CAAC;EAE/C,IAAI,CAACL,kBAAkB,CAACO,QAAQ,EAAE;IAAEE,QAAQ;IAAEG;EAAK,CAAC,CAAC,EAAE;IACrD;IACA;IACAb,KAAK,CAACgB,MAAM,CAACC,MAAM,CAACC,IAAI,CAAC,aAAa,CAAC,EAAE,0CAA0C,CAAC;IACpF,OAAO,SAAS;EAClB;AACF,CAAC,CAAC;AAEF,SAASb,yBAAyB,EAAED,mBAAmB","ignoreList":[]}
package/dist/esm/model.js CHANGED
@@ -1,2 +1,2 @@
1
- export {};
1
+ export var ALLURE_SETUP_REPORTER_HOOK = "__allure_reporter_setup_hook__";
2
2
  //# sourceMappingURL=model.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"model.js","names":[],"sources":["../../src/model.ts"],"sourcesContent":["import type { LabelName, LinkType } from \"allure-js-commons\";\nimport type { Config } from \"allure-js-commons/sdk/reporter\";\n\nexport type LabelConfig = {\n pattern: RegExp[];\n name: LabelName | string;\n};\n\nexport type LinkConfig = {\n pattern: RegExp[];\n urlTemplate: string;\n type: LinkType | string;\n};\n\nexport interface AllureCucumberReporterConfig extends Omit<Config, \"writer\" | \"links\"> {\n testMode?: boolean;\n links?: LinkConfig[];\n labels?: LabelConfig[];\n}\n"],"mappings":"","ignoreList":[]}
1
+ {"version":3,"file":"model.js","names":["ALLURE_SETUP_REPORTER_HOOK"],"sources":["../../src/model.ts"],"sourcesContent":["import type { LabelName } from \"allure-js-commons\";\nimport type { Config, LinkConfig, LinkTypeOptions } from \"allure-js-commons/sdk/reporter\";\n\nexport const ALLURE_SETUP_REPORTER_HOOK = \"__allure_reporter_setup_hook__\";\n\nexport type LabelConfig = {\n pattern: RegExp[];\n name: LabelName | string;\n};\n\nexport type AllureCucumberLinkConfig = LinkConfig<LinkTypeOptions & { pattern: RegExp[] }>;\n\nexport interface AllureCucumberReporterConfig extends Omit<Config, \"writer\" | \"links\"> {\n links?: AllureCucumberLinkConfig;\n labels?: LabelConfig[];\n}\n"],"mappings":"AAGA,OAAO,IAAMA,0BAA0B,GAAG,gCAAgC","ignoreList":[]}
@@ -1,4 +1,4 @@
1
- var _excluded = ["resultsDir", "testMode", "links", "labels"];
1
+ var _excluded = ["resultsDir", "links", "labels"];
2
2
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
3
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
4
  function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], t.indexOf(o) >= 0 || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
@@ -7,56 +7,59 @@ function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object
7
7
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
8
8
  function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
9
9
  import { Formatter, World } from "@cucumber/cucumber";
10
- import { AttachmentContentEncoding } from "@cucumber/messages";
11
- import { TestStepResultStatus } from "@cucumber/messages";
10
+ import { AttachmentContentEncoding, TestStepResultStatus } from "@cucumber/messages";
12
11
  import os from "node:os";
13
12
  import { extname } from "node:path";
14
13
  import process from "node:process";
15
14
  import { ContentType, LabelName, Stage, Status } from "allure-js-commons";
16
- import { ALLURE_RUNTIME_MESSAGE_CONTENT_TYPE, FileSystemWriter, MessageWriter, ReporterRuntime, createStepResult, getWorstStepResultStatus, md5 } from "allure-js-commons/sdk/reporter";
15
+ import { getMessageAndTraceFromError } from "allure-js-commons/sdk";
16
+ import { ALLURE_RUNTIME_MESSAGE_CONTENT_TYPE, FileSystemWriter, MessageWriter, ReporterRuntime, applyLinkTemplate, createStepResult, getWorstStepResultStatus, md5 } from "allure-js-commons/sdk/reporter";
17
17
  import { AllureCucumberWorld } from "./legacy.js";
18
18
  var {
19
- ALLURE_THREAD_NAME
19
+ ALLURE_THREAD_NAME,
20
+ ALLURE_TEST_MODE
20
21
  } = process.env;
21
22
  export default class AllureCucumberReporter extends Formatter {
22
23
  constructor(options) {
23
24
  super(options);
24
- _defineProperty(this, "afterHooks", void 0);
25
- _defineProperty(this, "beforeHooks", void 0);
26
- _defineProperty(this, "linksConfigs", []);
25
+ _defineProperty(this, "afterHooks", {});
26
+ _defineProperty(this, "beforeHooks", {});
27
+ _defineProperty(this, "linksConfigs", {});
27
28
  _defineProperty(this, "labelsConfigs", []);
28
- _defineProperty(this, "runtime", void 0);
29
+ _defineProperty(this, "allureRuntime", void 0);
29
30
  _defineProperty(this, "documentMap", new Map());
30
31
  _defineProperty(this, "scenarioMap", new Map());
31
32
  _defineProperty(this, "stepMap", new Map());
32
33
  _defineProperty(this, "testStepMap", new Map());
33
34
  _defineProperty(this, "pickleStepMap", new Map());
34
- _defineProperty(this, "testCaseTestStepsResults", new Map());
35
35
  _defineProperty(this, "pickleMap", new Map());
36
- _defineProperty(this, "hookMap", new Map());
37
36
  _defineProperty(this, "testCaseMap", new Map());
38
37
  _defineProperty(this, "testCaseStartedMap", new Map());
39
- _defineProperty(this, "allureResultsUuids", new Map());
38
+ _defineProperty(this, "testResultUuids", new Map());
39
+ _defineProperty(this, "scopeUuids", new Map());
40
+ _defineProperty(this, "fixtureUuids", new Map());
40
41
  var _ref = options.parsedArgvOptions,
41
42
  {
42
43
  resultsDir = "./allure-results",
43
- testMode,
44
44
  links,
45
45
  labels
46
46
  } = _ref,
47
47
  rest = _objectWithoutProperties(_ref, _excluded);
48
- this.runtime = new ReporterRuntime(_objectSpread({
49
- writer: testMode ? new MessageWriter() : new FileSystemWriter({
48
+ this.allureRuntime = new ReporterRuntime(_objectSpread({
49
+ writer: ALLURE_TEST_MODE ? new MessageWriter() : new FileSystemWriter({
50
50
  resultsDir
51
51
  }),
52
- links: links
52
+ links
53
53
  }, rest));
54
- this.linksConfigs = links || [];
54
+ this.linksConfigs = links || {};
55
55
  this.labelsConfigs = labels || [];
56
56
  options.eventBroadcaster.on("envelope", this.parseEnvelope.bind(this));
57
- this.beforeHooks = options.supportCodeLibrary.beforeTestCaseHookDefinitions;
58
- this.afterHooks = options.supportCodeLibrary.afterTestCaseHookDefinitions;
59
-
57
+ this.beforeHooks = options.supportCodeLibrary.beforeTestCaseHookDefinitions.reduce((acc, hook) => Object.assign(acc, {
58
+ [hook.id]: hook
59
+ }), {});
60
+ this.afterHooks = options.supportCodeLibrary.afterTestCaseHookDefinitions.reduce((acc, hook) => Object.assign(acc, {
61
+ [hook.id]: hook
62
+ }), {});
60
63
  // set AllureCucumberWorld for single thread mode
61
64
  if (options.supportCodeLibrary.World === World) {
62
65
  // @ts-ignore
@@ -69,10 +72,14 @@ export default class AllureCucumberReporter extends Formatter {
69
72
  labelsConfigs,
70
73
  linksConfigs
71
74
  } = this;
72
- return [...labelsConfigs, ...linksConfigs].flatMap(_ref2 => {
75
+ var linkConfigEntries = Object.entries(linksConfigs).map(_ref2 => {
76
+ var [, v] = _ref2;
77
+ return v;
78
+ });
79
+ return [...labelsConfigs, ...linkConfigEntries].flatMap(_ref3 => {
73
80
  var {
74
81
  pattern
75
- } = _ref2;
82
+ } = _ref3;
76
83
  return pattern;
77
84
  });
78
85
  }
@@ -96,15 +103,15 @@ export default class AllureCucumberReporter extends Formatter {
96
103
  case !!envelope.attachment:
97
104
  this.onAttachment(envelope.attachment);
98
105
  break;
99
- case !!envelope.hook:
100
- this.onHook(envelope.hook);
101
- break;
102
106
  case !!envelope.testStepStarted:
103
107
  this.onTestStepStarted(envelope.testStepStarted);
104
108
  break;
105
109
  case !!envelope.testStepFinished:
106
110
  this.onTestStepFinished(envelope.testStepFinished);
107
111
  break;
112
+ case !!envelope.testRunFinished:
113
+ this.onTestRunFinished();
114
+ break;
108
115
  }
109
116
  }
110
117
  parseTagsLabels(tags) {
@@ -134,16 +141,17 @@ export default class AllureCucumberReporter extends Formatter {
134
141
  parseTagsLinks(tags) {
135
142
  var tagKeyRe = /^@\S+=/;
136
143
  var links = [];
137
- if (this.linksConfigs.length === 0) {
144
+ if (Object.keys(this.linksConfigs).length === 0) {
138
145
  return links;
139
146
  }
140
- this.linksConfigs.forEach(matcher => {
147
+ Object.entries(this.linksConfigs).forEach(_ref4 => {
148
+ var [type, matcher] = _ref4;
141
149
  var matchedTags = tags.filter(tag => matcher.pattern.some(pattern => pattern.test(tag.name)));
142
150
  var matchedLinks = matchedTags.map(tag => {
143
151
  var tagValue = tag.name.replace(tagKeyRe, "");
144
152
  return {
145
- url: matcher.urlTemplate.replace(/%s$/, tagValue) || tagValue,
146
- type: matcher.type
153
+ url: applyLinkTemplate(matcher.urlTemplate, tagValue) || tagValue,
154
+ type
147
155
  };
148
156
  });
149
157
  links.push(...matchedLinks);
@@ -247,9 +255,11 @@ export default class AllureCucumberReporter extends Formatter {
247
255
  var scenarioLinks = this.parseTagsLinks((scenario === null || scenario === void 0 ? void 0 : scenario.tags) || []);
248
256
  result.labels.push(...featureLabels, ...scenarioLabels, ...pickleLabels);
249
257
  result.links.push(...featureLinks, ...scenarioLinks);
250
- var testUuid = this.runtime.startTest(result);
258
+ var scopeUuid = this.allureRuntime.startScope();
259
+ this.scopeUuids.set(data.id, scopeUuid);
260
+ var testUuid = this.allureRuntime.startTest(result, [scopeUuid]);
261
+ this.testResultUuids.set(data.id, testUuid);
251
262
  this.testCaseStartedMap.set(data.id, data);
252
- this.allureResultsUuids.set(data.id, testUuid);
253
263
  if (!(scenario !== null && scenario !== void 0 && scenario.examples)) {
254
264
  return;
255
265
  }
@@ -261,15 +271,18 @@ export default class AllureCucumberReporter extends Formatter {
261
271
  return;
262
272
  }
263
273
  var csvDataTable = "".concat(csvDataTableHeader, "\n").concat(csvDataTableBody, "\n");
264
- this.runtime.writeAttachment("Examples", Buffer.from(csvDataTable, "utf-8"), {
274
+ this.allureRuntime.writeAttachment(testUuid, null, "Examples", Buffer.from(csvDataTable, "utf-8"), {
265
275
  contentType: ContentType.CSV,
266
276
  fileExtension: ".csv"
267
- }, testUuid);
277
+ });
268
278
  });
269
279
  }
270
280
  onTestCaseFinished(data) {
271
- var testUuid = this.allureResultsUuids.get(data.testCaseStartedId);
272
- this.runtime.updateTest(result => {
281
+ var testUuid = this.testResultUuids.get(data.testCaseStartedId);
282
+ if (!testUuid) {
283
+ return;
284
+ }
285
+ this.allureRuntime.updateTest(testUuid, result => {
273
286
  result.status = result.steps.length > 0 ? getWorstStepResultStatus(result.steps) : Status.PASSED;
274
287
  result.stage = Stage.FINISHED;
275
288
  if (result.status === undefined) {
@@ -277,19 +290,44 @@ export default class AllureCucumberReporter extends Formatter {
277
290
  message: "The test doesn't have an implementation."
278
291
  };
279
292
  }
280
- }, testUuid);
281
- this.runtime.stopTest({
282
- uuid: testUuid,
283
- stop: Date.now()
284
293
  });
285
- this.runtime.writeTest(testUuid);
294
+ this.allureRuntime.stopTest(testUuid);
295
+ this.allureRuntime.writeTest(testUuid);
296
+ this.testResultUuids.delete(data.testCaseStartedId);
297
+ var scopeUuid = this.scopeUuids.get(data.testCaseStartedId);
298
+ if (scopeUuid) {
299
+ this.allureRuntime.writeScope(scopeUuid);
300
+ this.scopeUuids.delete(data.testCaseStartedId);
301
+ }
286
302
  }
287
303
  onTestStepStarted(data) {
288
304
  var _stepPickle$argument;
289
- var testUuid = this.allureResultsUuids.get(data.testCaseStartedId);
305
+ var testUuid = this.testResultUuids.get(data.testCaseStartedId);
290
306
  var step = this.testStepMap.get(data.testStepId);
291
-
292
- // TODO: support hooks reporting
307
+ if (step.hookId) {
308
+ var scopeUuid = this.scopeUuids.get(data.testCaseStartedId);
309
+ if (!scopeUuid) {
310
+ return;
311
+ }
312
+ var beforeHook = step.hookId && this.beforeHooks[step.hookId];
313
+ var afterHook = step.hookId && this.afterHooks[step.hookId];
314
+ var type = beforeHook ? "before" : afterHook ? "after" : undefined;
315
+ if (!type) {
316
+ return;
317
+ }
318
+ var name = beforeHook ? beforeHook.name : afterHook ? afterHook.name : "hook";
319
+ if (name === "ALLURE_FIXTURE_IGNORE") {
320
+ return;
321
+ }
322
+ var fixtureUuid = this.allureRuntime.startFixture(scopeUuid, type, {
323
+ name,
324
+ stage: Stage.RUNNING
325
+ });
326
+ if (fixtureUuid) {
327
+ this.fixtureUuids.set(data.testCaseStartedId, fixtureUuid);
328
+ }
329
+ return;
330
+ }
293
331
  if (!step.pickleStepId) {
294
332
  return;
295
333
  }
@@ -298,68 +336,102 @@ export default class AllureCucumberReporter extends Formatter {
298
336
  return;
299
337
  }
300
338
  var stepKeyword = stepPickle.astNodeIds.map(astNodeId => this.stepMap.get(astNodeId)).map(stepAstNode => stepAstNode === null || stepAstNode === void 0 ? void 0 : stepAstNode.keyword).find(keyword => keyword !== undefined) || "";
301
- var stepResult = _objectSpread(_objectSpread({}, createStepResult()), {}, {
339
+ var stepUuid = this.allureRuntime.startStep(testUuid, undefined, _objectSpread(_objectSpread({}, createStepResult()), {}, {
302
340
  name: "".concat(stepKeyword).concat(stepPickle.text),
303
341
  start: data.timestamp.nanos
304
- });
305
- this.runtime.startStep(stepResult, testUuid);
342
+ }));
306
343
  if (!((_stepPickle$argument = stepPickle.argument) !== null && _stepPickle$argument !== void 0 && _stepPickle$argument.dataTable)) {
307
344
  return;
308
345
  }
309
346
  var csvDataTable = stepPickle.argument.dataTable.rows.reduce((acc, row) => "".concat(acc + row.cells.map(cell => cell.value).join(","), "\n"), "");
310
- this.runtime.writeAttachment("Data table", Buffer.from(csvDataTable, "utf-8"), {
347
+ this.allureRuntime.writeAttachment(testUuid, stepUuid, "Data table", Buffer.from(csvDataTable, "utf-8"), {
311
348
  contentType: ContentType.CSV,
312
349
  fileExtension: ".csv"
313
- }, testUuid);
350
+ });
314
351
  }
315
352
  onTestStepFinished(data) {
316
- var testUuid = this.allureResultsUuids.get(data.testCaseStartedId);
317
- var currentStep = this.runtime.getCurrentStep(testUuid);
318
-
319
- // TODO: support hooks reporting
353
+ var step = this.testStepMap.get(data.testStepId);
354
+ if (!step) {
355
+ return;
356
+ }
357
+ var status = this.parseStatus(data.testStepResult);
358
+ var stage = status !== Status.SKIPPED ? Stage.FINISHED : Stage.PENDING;
359
+ if (step.hookId) {
360
+ var fixtureUuid = this.fixtureUuids.get(data.testCaseStartedId);
361
+ if (!fixtureUuid) {
362
+ return;
363
+ }
364
+ this.allureRuntime.updateFixture(fixtureUuid, r => {
365
+ r.stage = stage;
366
+ r.status = status;
367
+ if (data.testStepResult.exception) {
368
+ r.statusDetails = getMessageAndTraceFromError({
369
+ message: data.testStepResult.message,
370
+ stack: data.testStepResult.exception.stackTrace
371
+ });
372
+ }
373
+ });
374
+ // TODO stop from duration? use data.timestamp.nanos?
375
+ this.allureRuntime.stopFixture(fixtureUuid);
376
+ this.fixtureUuids.delete(data.testCaseStartedId);
377
+ return;
378
+ }
379
+ var testUuid = this.testResultUuids.get(data.testCaseStartedId);
380
+ var currentStep = this.allureRuntime.currentStep(testUuid);
320
381
  if (!currentStep) {
321
382
  return;
322
383
  }
323
- this.runtime.updateStep(step => {
324
- var status = this.parseStatus(data.testStepResult);
325
- step.status = status;
326
- step.stage = status !== Status.SKIPPED ? Stage.FINISHED : Stage.PENDING;
384
+ this.allureRuntime.updateStep(currentStep, r => {
385
+ r.status = status;
386
+ r.stage = stage;
327
387
  if (status === undefined) {
328
- step.statusDetails = {
388
+ r.statusDetails = {
329
389
  message: "The step doesn't have an implementation."
330
390
  };
331
391
  return;
332
392
  }
333
393
  if (data.testStepResult.exception) {
334
- step.statusDetails = {
394
+ r.statusDetails = {
335
395
  message: data.testStepResult.message,
336
396
  trace: data.testStepResult.exception.stackTrace
337
397
  };
338
398
  }
339
- }, testUuid);
340
- this.runtime.stopStep({
341
- uuid: testUuid,
342
- stop: currentStep.start + data.timestamp.nanos
343
399
  });
344
- }
345
- onHook(data) {
346
- this.hookMap.set(data.id, data);
400
+
401
+ // TODO stop from duration? use data.timestamp.nanos?
402
+ this.allureRuntime.stopStep(currentStep);
347
403
  }
348
404
  onAttachment(message) {
349
405
  var _message$fileName;
350
406
  if (!message.testCaseStartedId) {
351
407
  return;
352
408
  }
353
- var testUuid = this.allureResultsUuids.get(message.testCaseStartedId);
409
+ var fixtureUuid = this.fixtureUuids.get(message.testCaseStartedId);
410
+ var testUuid = this.testResultUuids.get(message.testCaseStartedId);
411
+ var rootUuid = fixtureUuid !== null && fixtureUuid !== void 0 ? fixtureUuid : testUuid;
412
+ if (!rootUuid) {
413
+ return;
414
+ }
415
+ if (message.mediaType === "application/vnd.allure.skipcucumber+json") {
416
+ if (testUuid) {
417
+ this.allureRuntime.updateTest(testUuid, result => {
418
+ result.labels.push({
419
+ name: "ALLURE_TESTPLAN_SKIP",
420
+ value: "true"
421
+ });
422
+ });
423
+ }
424
+ return;
425
+ }
354
426
  if (message.mediaType === ALLURE_RUNTIME_MESSAGE_CONTENT_TYPE) {
355
427
  var parsedMessage = JSON.parse(message.body);
356
- this.runtime.applyRuntimeMessages(Array.isArray(parsedMessage) ? parsedMessage : [parsedMessage], {
357
- testUuid
358
- });
428
+
429
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
430
+ this.allureRuntime.applyRuntimeMessages(rootUuid, Array.isArray(parsedMessage) ? parsedMessage : [parsedMessage]);
359
431
  return;
360
432
  }
361
433
  var encoding = message.contentEncoding === AttachmentContentEncoding.BASE64 ? "base64" : "utf-8";
362
- this.runtime.applyRuntimeMessages([{
434
+ this.allureRuntime.applyRuntimeMessages(rootUuid, [{
363
435
  type: "attachment_content",
364
436
  data: {
365
437
  name: (_message$fileName = message.fileName) !== null && _message$fileName !== void 0 ? _message$fileName : "Attachment",
@@ -369,9 +441,11 @@ export default class AllureCucumberReporter extends Formatter {
369
441
  fileExtension: message.fileName ? extname(message.fileName) : undefined,
370
442
  wrapInStep: true
371
443
  }
372
- }], {
373
- testUuid
374
- });
444
+ }]);
445
+ }
446
+ onTestRunFinished() {
447
+ this.allureRuntime.writeCategoriesDefinitions();
448
+ this.allureRuntime.writeEnvironmentInfo();
375
449
  }
376
450
  }
377
451
  //# sourceMappingURL=reporter.js.map