@qavajs/playwright-runner-adapter 0.2.0 → 0.4.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.
- package/CHANGELOG.md +10 -1
- package/README.md +11 -8
- package/adapter/PlaywrightWorld.js +3 -0
- package/adapter/PlaywrightWorld.js.map +1 -1
- package/adapter/adapter.spec.js +1 -1
- package/adapter/adapter.spec.js.map +1 -1
- package/adapter/defineCucumber.js +23 -0
- package/adapter/defineCucumber.js.map +1 -0
- package/adapter/loader.js +24 -7
- package/adapter/loader.js.map +1 -1
- package/index.d.ts +1 -0
- package/index.js +4 -1
- package/package.json +6 -6
- package/src/PlaywrightWorld.ts +4 -1
- package/src/adapter.spec.ts +3 -3
- package/src/defineCucumber.ts +25 -0
- package/src/loader.ts +21 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
-
All notable changes to the "@qavajs/
|
|
3
|
+
All notable changes to the "@qavajs/playwright-runner-adapter" will be documented in this file.
|
|
4
4
|
|
|
5
5
|
Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file.
|
|
6
6
|
|
|
@@ -10,6 +10,15 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how
|
|
|
10
10
|
:pencil: - chore
|
|
11
11
|
:microscope: - experimental
|
|
12
12
|
|
|
13
|
+
## [0.4.0]
|
|
14
|
+
- :rocket: added support of _requireModules_ option
|
|
15
|
+
- :rocket: improved _defineCucumber_ function to encapsulate adapter path
|
|
16
|
+
- :beetle: updated typing for _init_ property of PlaywrightWorld
|
|
17
|
+
|
|
18
|
+
## [0.3.0]
|
|
19
|
+
- :rocket: added _defineCucumber_ util function
|
|
20
|
+
- :rocket: added logic to process duplicates
|
|
21
|
+
|
|
13
22
|
## [0.2.0]
|
|
14
23
|
- :rocket: updated fixture implementation
|
|
15
24
|
|
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
[](https://badge.fury.io/js/@qavajs%2Fplaywright-runner-adapter)
|
|
2
2
|
|
|
3
3
|
# @qavajs/playwright-runner-adapter
|
|
4
|
-
Adapter to run
|
|
4
|
+
Adapter to run cucumber tests via playwright test runner
|
|
5
5
|
|
|
6
6
|
## Installation
|
|
7
7
|
|
|
@@ -20,16 +20,15 @@ export default {
|
|
|
20
20
|
### Set testDir
|
|
21
21
|
Set testDir to adapter
|
|
22
22
|
```typescript
|
|
23
|
+
import { defineCucumber } from '@qavajs/playwright-runner-adapter';
|
|
24
|
+
|
|
23
25
|
export default defineConfig({
|
|
24
|
-
testDir:
|
|
26
|
+
testDir: defineCucumber({
|
|
27
|
+
config: 'test/cucumber.ts',
|
|
28
|
+
profile: 'default'
|
|
29
|
+
})
|
|
25
30
|
});
|
|
26
31
|
```
|
|
27
|
-
### Add cucumber config
|
|
28
|
-
Set CONFIG and PROFILE environment variables e.g via dotenv library
|
|
29
|
-
```dotenv
|
|
30
|
-
CONFIG=test/cucumber.ts
|
|
31
|
-
PROFILE=default
|
|
32
|
-
```
|
|
33
32
|
|
|
34
33
|
## Advanced Configuration
|
|
35
34
|
### Customizing test instance
|
|
@@ -57,6 +56,7 @@ class ExtendedPlaywrightWorld extends PlaywrightWorld {
|
|
|
57
56
|
super(options);
|
|
58
57
|
}
|
|
59
58
|
|
|
59
|
+
// set test property with extened one
|
|
60
60
|
test = customTest;
|
|
61
61
|
|
|
62
62
|
// init arrow function connects fixtures with Cucumber world instance
|
|
@@ -67,4 +67,7 @@ class ExtendedPlaywrightWorld extends PlaywrightWorld {
|
|
|
67
67
|
}
|
|
68
68
|
```
|
|
69
69
|
|
|
70
|
+
## Limitation
|
|
71
|
+
- ES modules are not supported (at least for node <= 22, where experimental ESM require is introduced)
|
|
72
|
+
|
|
70
73
|
|
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.PlaywrightWorld = void 0;
|
|
4
4
|
const test_1 = require("@playwright/test");
|
|
5
|
+
/**
|
|
6
|
+
* Cucumber world for playwright adapter
|
|
7
|
+
*/
|
|
5
8
|
class PlaywrightWorld {
|
|
6
9
|
constructor(options) {
|
|
7
10
|
this.test = test_1.test;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PlaywrightWorld.js","sourceRoot":"","sources":["../src/PlaywrightWorld.ts"],"names":[],"mappings":";;;AAAA,2CAA0F;AAE1F,MAAa,eAAe;IAWxB,YAAY,OAAY;QAFxB,SAAI,GAAG,WAAI,CAAC;QAQZ,SAAI,
|
|
1
|
+
{"version":3,"file":"PlaywrightWorld.js","sourceRoot":"","sources":["../src/PlaywrightWorld.ts"],"names":[],"mappings":";;;AAAA,2CAA0F;AAE1F;;GAEG;AACH,MAAa,eAAe;IAWxB,YAAY,OAAY;QAFxB,SAAI,GAAG,WAAI,CAAC;QAQZ,SAAI,GAAiC,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAA6D,EAAE,EAAE;YAC3H,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;YACvB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;YACvB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACrB,CAAC,CAAA;QATG,IAAI,CAAC,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC;QACvB,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;QAC7B,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;IACzC,CAAC;CAOJ;AAtBD,0CAsBC"}
|
package/adapter/adapter.spec.js
CHANGED
|
@@ -27,7 +27,7 @@ for (const feature of features) {
|
|
|
27
27
|
});
|
|
28
28
|
test.beforeEach(world.init);
|
|
29
29
|
for (const testCase of tests) {
|
|
30
|
-
const tag = testCase.tags.map(tag => tag.name);
|
|
30
|
+
const tag = testCase.tags.map((tag) => tag.name);
|
|
31
31
|
test(testCase.name, { tag }, async () => {
|
|
32
32
|
for (const beforeHook of supportCodeLibrary.beforeTestCaseHookDefinitions) {
|
|
33
33
|
if (beforeHook.appliesToTestCase(testCase)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adapter.spec.js","sourceRoot":"","sources":["../src/adapter.spec.ts"],"names":[],"mappings":";;AAAA,qCAAgC;AAEhC,MAAM,EAAE,QAAQ,EAAE,kBAAkB,EAAE,GAAG,IAAA,aAAI,GAAE,CAAC;AAEhD,SAAS,GAAG,CAAC,IAAS;IAClB,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;AACtB,CAAC;
|
|
1
|
+
{"version":3,"file":"adapter.spec.js","sourceRoot":"","sources":["../src/adapter.spec.ts"],"names":[],"mappings":";;AAAA,qCAAgC;AAEhC,MAAM,EAAE,QAAQ,EAAE,kBAAkB,EAAE,GAAG,IAAA,aAAI,GAAE,CAAC;AAEhD,SAAS,GAAG,CAAC,IAAS;IAClB,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;AACtB,CAAC;AAED,SAAS,MAAM,CAAsB,IAAS,EAAE,OAAY;;IACxD,MAAM,QAAQ,GAAG,MAAA,OAAO,CAAC,QAAQ,mCAAI,YAAY,CAAC;IAClD,MAAM,WAAW,GAAG,MAAA,OAAO,CAAC,SAAS,mCAAI,YAAY,CAAC;IACtD,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,MAAM,CAAC,QAAQ,EAAE,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC,CAAC;AAC7D,CAAC;AAED,MAAM,OAAO,GAAG,IAAI,kBAAkB,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;AACjD,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;AAE1B,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;IAC7B,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;IAC5B,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,OAAi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,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC,EAAC,MAAM,EAAC,CAAC,CAAC,CAAC;4BAClD,CAAC;wBACL,CAAC;wBACD,IAAI,MAAM,CAAC,KAAK;4BAAE,MAAM,MAAM,CAAC,KAAK,CAAC;oBACzC,CAAC,CAAC,CAAC;gBACP,CAAC;gBACD,KAAK,MAAM,SAAS,IAAI,kBAAkB,CAAC,4BAA4B,EAAE,CAAC;oBACtE,IAAI,SAAS,CAAC,iBAAiB,CAAC,QAAQ,CAAC,EAAE,CAAC;wBACxC,MAAM,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,KAAK,IAAI,EAAE;4BAChC,MAAM,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC;wBAClD,CAAC,CAAC,CAAC;oBACP,CAAC;gBACL,CAAC;YACL,CAAC,CAAC,CAAA;QACN,CAAC;QACD,KAAK,MAAM,YAAY,IAAI,kBAAkB,CAAC,2BAA2B,EAAE,CAAC;YACxE,IAAI,CAAC,QAAQ,CAAC,KAAK;gBACf,MAAM,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;YACtC,CAAC,CAAC,CAAC;QACP,CAAC;IACL,CAAC,CAAC,CAAC;AACP,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.defineCucumber = defineCucumber;
|
|
4
|
+
const node_path_1 = require("node:path");
|
|
5
|
+
/**
|
|
6
|
+
* Define cucumber config in playwright config
|
|
7
|
+
* @param {CucumberConfig} config
|
|
8
|
+
* @example
|
|
9
|
+
* export default defineConfig({
|
|
10
|
+
* testDir: defineCucumber({
|
|
11
|
+
* config: 'cucumber.ts',
|
|
12
|
+
* profile: 'chrome', // optional
|
|
13
|
+
* adapter: 'path/to/adapter' // optional
|
|
14
|
+
* }),
|
|
15
|
+
* })
|
|
16
|
+
*/
|
|
17
|
+
function defineCucumber(config) {
|
|
18
|
+
var _a, _b;
|
|
19
|
+
process.env.CONFIG = config.config;
|
|
20
|
+
process.env.PROFILE = (_a = config.profile) !== null && _a !== void 0 ? _a : 'default';
|
|
21
|
+
return (_b = config.adapter) !== null && _b !== void 0 ? _b : (0, node_path_1.resolve)('./node_modules/@qavajs/playwright-runner-adapter/adapter');
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=defineCucumber.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defineCucumber.js","sourceRoot":"","sources":["../src/defineCucumber.ts"],"names":[],"mappings":";;AAoBA,wCAIC;AAxBD,yCAAoC;AAQpC;;;;;;;;;;;GAWG;AACH,SAAgB,cAAc,CAAC,MAAsB;;IACjD,OAAO,CAAC,GAAG,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;IACnC,OAAO,CAAC,GAAG,CAAC,OAAO,GAAG,MAAA,MAAM,CAAC,OAAO,mCAAI,SAAS,CAAC;IAClD,OAAO,MAAA,MAAM,CAAC,OAAO,mCAAI,IAAA,mBAAO,EAAC,0DAA0D,CAAC,CAAC;AACjG,CAAC"}
|
package/adapter/loader.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.loadFeatures = loadFeatures;
|
|
4
|
+
exports.loadStepDefinitions = loadStepDefinitions;
|
|
5
|
+
exports.load = load;
|
|
4
6
|
const node_fs_1 = require("node:fs");
|
|
5
7
|
const node_path_1 = require("node:path");
|
|
6
8
|
const node_crypto_1 = require("node:crypto");
|
|
@@ -12,6 +14,20 @@ const uuidFn = () => (0, node_crypto_1.randomUUID)();
|
|
|
12
14
|
const builder = new gherkin_1.AstBuilder(uuidFn);
|
|
13
15
|
const matcher = new gherkin_1.GherkinClassicTokenMatcher();
|
|
14
16
|
const parser = new gherkin_1.Parser(builder, matcher);
|
|
17
|
+
function duplicates(tests) {
|
|
18
|
+
const counts = {};
|
|
19
|
+
return tests.map(item => {
|
|
20
|
+
const name = item.name;
|
|
21
|
+
if (!counts[name]) {
|
|
22
|
+
counts[name] = 0;
|
|
23
|
+
}
|
|
24
|
+
if (counts[name]) {
|
|
25
|
+
item.name = `${item.name} #${counts[item.name] + 1}`;
|
|
26
|
+
}
|
|
27
|
+
counts[item.name]++;
|
|
28
|
+
return item;
|
|
29
|
+
});
|
|
30
|
+
}
|
|
15
31
|
function loadFeatures(globPattern) {
|
|
16
32
|
const files = (0, glob_1.globSync)(globPattern);
|
|
17
33
|
return files.map(file => {
|
|
@@ -20,11 +36,10 @@ function loadFeatures(globPattern) {
|
|
|
20
36
|
const gherkinDocument = parser.parse((0, node_fs_1.readFileSync)(filePath, 'utf-8'));
|
|
21
37
|
return {
|
|
22
38
|
feature: (_a = gherkinDocument.feature) === null || _a === void 0 ? void 0 : _a.name,
|
|
23
|
-
tests: (0, gherkin_1.compile)(gherkinDocument, file, uuidFn)
|
|
39
|
+
tests: duplicates((0, gherkin_1.compile)(gherkinDocument, file, uuidFn))
|
|
24
40
|
};
|
|
25
41
|
});
|
|
26
42
|
}
|
|
27
|
-
exports.loadFeatures = loadFeatures;
|
|
28
43
|
function loadStepDefinitions(globPattern) {
|
|
29
44
|
cucumber_1.supportCodeLibraryBuilder.reset(process.cwd(), uuidFn);
|
|
30
45
|
cucumber_1.supportCodeLibraryBuilder.methods.setWorldConstructor(PlaywrightWorld_1.PlaywrightWorld);
|
|
@@ -35,15 +50,17 @@ function loadStepDefinitions(globPattern) {
|
|
|
35
50
|
}
|
|
36
51
|
return cucumber_1.supportCodeLibraryBuilder.finalize();
|
|
37
52
|
}
|
|
38
|
-
exports.loadStepDefinitions = loadStepDefinitions;
|
|
39
53
|
function load() {
|
|
40
|
-
var _a, _b;
|
|
54
|
+
var _a, _b, _c, _d, _e;
|
|
41
55
|
const config = require((0, node_path_1.join)(process.cwd(), (_a = process.env.CONFIG) !== null && _a !== void 0 ? _a : 'config.js'));
|
|
42
56
|
const profile = (_b = process.env.PROFILE) !== null && _b !== void 0 ? _b : 'default';
|
|
43
57
|
const resolvedConfig = config[profile];
|
|
44
58
|
const features = loadFeatures(resolvedConfig.paths);
|
|
45
|
-
const supportCodeLibrary = loadStepDefinitions(
|
|
59
|
+
const supportCodeLibrary = loadStepDefinitions([
|
|
60
|
+
...((_c = resolvedConfig.requireModules) !== null && _c !== void 0 ? _c : []),
|
|
61
|
+
...((_d = resolvedConfig.require) !== null && _d !== void 0 ? _d : []),
|
|
62
|
+
...((_e = resolvedConfig.import) !== null && _e !== void 0 ? _e : [])
|
|
63
|
+
]);
|
|
46
64
|
return { features, supportCodeLibrary };
|
|
47
65
|
}
|
|
48
|
-
exports.load = load;
|
|
49
66
|
//# sourceMappingURL=loader.js.map
|
package/adapter/loader.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loader.js","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"loader.js","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":";;AA4BA,oCAUC;AAED,kDASC;AAED,oBAYC;AA/DD,qCAAuC;AACvC,yCAA0C;AAC1C,6CAAyC;AACzC,+CAA4F;AAC5F,iDAA+D;AAC/D,+BAAgC;AAChC,uDAAoD;AAEpD,MAAM,MAAM,GAAG,GAAG,EAAE,CAAC,IAAA,wBAAU,GAAE,CAAC;AAClC,MAAM,OAAO,GAAG,IAAI,oBAAU,CAAC,MAAM,CAAC,CAAA;AACtC,MAAM,OAAO,GAAG,IAAI,oCAA0B,EAAE,CAAC;AACjD,MAAM,MAAM,GAAG,IAAI,gBAAM,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;AAE3C,SAAS,UAAU,CAAC,KAAY;IAC5B,MAAM,MAAM,GAA2B,EAAE,CAAC;IAC1C,OAAO,K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,EAAC,WAAW,CAAC,CAAC;IACpC,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACvB,MAAM,QAAQ,GAAG,IAAA,mBAAO,EAAC,IAAI,CAAC,CAAC;QAC/B,OAAO,CAAC,QAAQ,CAAC,CAAC;IACtB,CAAC;IACD,OAAO,oCAAyB,CAAC,QAAQ,EAAE,CAAC;AAChD,CAAC;AAED,SAAgB,IAAI;;IAChB,MAAM,MAAM,GAAG,OAAO,CAAC,IAAA,gBAAI,EAAC,OAAO,CAAC,GAAG,EAAE,EAAE,MAAA,OAAO,CAAC,GAAG,CAAC,MAAM,mCAAI,WAAW,CAAC,CAAC,CAAC;IAC/E,MAAM,OAAO,GAAG,MAAA,OAAO,CAAC,GAAG,CAAC,OAAO,mCAAI,SAAS,CAAC;IAEjD,MAAM,cAAc,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC;IACvC,MAAM,QAAQ,GAAG,YAAY,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;IACpD,MAAM,kBAAkB,GAAG,mBAAmB,CAAC;QAC3C,GAAG,CAAC,MAAA,cAAc,CAAC,cAAc,mCAAI,EAAE,CAAC;QACxC,GAAG,CAAC,MAAA,cAAc,CAAC,OAAO,mCAAI,EAAE,CAAC;QACjC,GAAG,CAAC,MAAA,cAAc,CAAC,MAAM,mCAAI,EAAE,CAAC;KACnC,CAAC,CAAC;IACH,OAAO,EAAE,QAAQ,EAAE,kBAAkB,EAAE,CAAA;AAC3C,CAAC"}
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@qavajs/playwright-runner-adapter",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "adapter for playwright test runner",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "tsc",
|
|
@@ -11,12 +11,12 @@
|
|
|
11
11
|
"license": "MIT",
|
|
12
12
|
"dependencies": {
|
|
13
13
|
"@cucumber/gherkin": "^28.0.0",
|
|
14
|
-
"glob": "^
|
|
14
|
+
"glob": "^11.0.0"
|
|
15
15
|
},
|
|
16
16
|
"devDependencies": {
|
|
17
|
-
"@cucumber/cucumber": "^10.
|
|
18
|
-
"@playwright/test": "^1.
|
|
19
|
-
"@types/node": "^
|
|
20
|
-
"typescript": "^5.4
|
|
17
|
+
"@cucumber/cucumber": "^10.8.0",
|
|
18
|
+
"@playwright/test": "^1.45.3",
|
|
19
|
+
"@types/node": "^22.1.0",
|
|
20
|
+
"typescript": "^5.5.4"
|
|
21
21
|
}
|
|
22
22
|
}
|
package/src/PlaywrightWorld.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { APIRequestContext, Browser, BrowserContext, Page, test } from '@playwright/test';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Cucumber world for playwright adapter
|
|
5
|
+
*/
|
|
3
6
|
export class PlaywrightWorld {
|
|
4
7
|
page!: Page;
|
|
5
8
|
context!: BrowserContext;
|
|
@@ -17,7 +20,7 @@ export class PlaywrightWorld {
|
|
|
17
20
|
this.parameters = options.parameters;
|
|
18
21
|
}
|
|
19
22
|
|
|
20
|
-
init = ({ browser, context, page }: { browser: Browser, context: BrowserContext, page: Page }) => {
|
|
23
|
+
init: ({ [fixture: string]: any }) = ({ browser, context, page }: { browser: Browser, context: BrowserContext, page: Page }) => {
|
|
21
24
|
this.browser = browser;
|
|
22
25
|
this.context = context;
|
|
23
26
|
this.page = page;
|
package/src/adapter.spec.ts
CHANGED
|
@@ -5,10 +5,11 @@ const { features, supportCodeLibrary } = load();
|
|
|
5
5
|
function log(data: any) {
|
|
6
6
|
console.log(data);
|
|
7
7
|
}
|
|
8
|
+
|
|
8
9
|
function attach(this: { test: any }, body: any, details: any) {
|
|
9
10
|
const fileName = details.fileName ?? 'attachment';
|
|
10
11
|
const contentType = details.mediaType ?? 'text/plain';
|
|
11
|
-
this.test.info().attach(fileName, { body, contentType })
|
|
12
|
+
this.test.info().attach(fileName, { body, contentType });
|
|
12
13
|
}
|
|
13
14
|
|
|
14
15
|
const fixture = new supportCodeLibrary.World({});
|
|
@@ -31,8 +32,7 @@ for (const feature of features) {
|
|
|
31
32
|
test.beforeEach(world.init);
|
|
32
33
|
|
|
33
34
|
for (const testCase of tests) {
|
|
34
|
-
const tag = testCase.tags.map(tag => tag.name);
|
|
35
|
-
|
|
35
|
+
const tag = testCase.tags.map((tag: { name: string }) => tag.name);
|
|
36
36
|
test(testCase.name, { tag }, async () => {
|
|
37
37
|
for (const beforeHook of supportCodeLibrary.beforeTestCaseHookDefinitions) {
|
|
38
38
|
if (beforeHook.appliesToTestCase(testCase)) {
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { resolve } from 'node:path';
|
|
2
|
+
|
|
3
|
+
type CucumberConfig = {
|
|
4
|
+
config: string,
|
|
5
|
+
profile?: string,
|
|
6
|
+
adapter?: string
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Define cucumber config in playwright config
|
|
11
|
+
* @param {CucumberConfig} config
|
|
12
|
+
* @example
|
|
13
|
+
* export default defineConfig({
|
|
14
|
+
* testDir: defineCucumber({
|
|
15
|
+
* config: 'cucumber.ts',
|
|
16
|
+
* profile: 'chrome', // optional
|
|
17
|
+
* adapter: 'path/to/adapter' // optional
|
|
18
|
+
* }),
|
|
19
|
+
* })
|
|
20
|
+
*/
|
|
21
|
+
export function defineCucumber(config: CucumberConfig): string {
|
|
22
|
+
process.env.CONFIG = config.config;
|
|
23
|
+
process.env.PROFILE = config.profile ?? 'default';
|
|
24
|
+
return config.adapter ?? resolve('./node_modules/@qavajs/playwright-runner-adapter/adapter');
|
|
25
|
+
}
|
package/src/loader.ts
CHANGED
|
@@ -11,6 +11,21 @@ const builder = new AstBuilder(uuidFn)
|
|
|
11
11
|
const matcher = new GherkinClassicTokenMatcher();
|
|
12
12
|
const parser = new Parser(builder, matcher)
|
|
13
13
|
|
|
14
|
+
function duplicates(tests: any[]) {
|
|
15
|
+
const counts: Record<string, number> = {};
|
|
16
|
+
return tests.map(item => {
|
|
17
|
+
const name = item.name;
|
|
18
|
+
if (!counts[name]) {
|
|
19
|
+
counts[name] = 0;
|
|
20
|
+
}
|
|
21
|
+
if (counts[name]) {
|
|
22
|
+
item.name = `${item.name} #${counts[item.name] + 1}`;
|
|
23
|
+
}
|
|
24
|
+
counts[item.name]++;
|
|
25
|
+
return item;
|
|
26
|
+
})
|
|
27
|
+
}
|
|
28
|
+
|
|
14
29
|
export function loadFeatures(globPattern: string[]) {
|
|
15
30
|
const files = globSync(globPattern);
|
|
16
31
|
return files.map(file => {
|
|
@@ -18,7 +33,7 @@ export function loadFeatures(globPattern: string[]) {
|
|
|
18
33
|
const gherkinDocument = parser.parse(readFileSync(filePath, 'utf-8'));
|
|
19
34
|
return {
|
|
20
35
|
feature: gherkinDocument.feature?.name,
|
|
21
|
-
tests: compile(gherkinDocument, file, uuidFn)
|
|
36
|
+
tests: duplicates(compile(gherkinDocument, file, uuidFn) as any)
|
|
22
37
|
}
|
|
23
38
|
});
|
|
24
39
|
}
|
|
@@ -40,6 +55,10 @@ export function load() {
|
|
|
40
55
|
|
|
41
56
|
const resolvedConfig = config[profile];
|
|
42
57
|
const features = loadFeatures(resolvedConfig.paths);
|
|
43
|
-
const supportCodeLibrary = loadStepDefinitions(
|
|
58
|
+
const supportCodeLibrary = loadStepDefinitions([
|
|
59
|
+
...(resolvedConfig.requireModules ?? []),
|
|
60
|
+
...(resolvedConfig.require ?? []),
|
|
61
|
+
...(resolvedConfig.import ?? [])
|
|
62
|
+
]);
|
|
44
63
|
return { features, supportCodeLibrary }
|
|
45
64
|
}
|