@qavajs/playwright-runner-adapter 0.1.1 → 0.3.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 +8 -1
- package/README.md +11 -6
- package/adapter/adapter.spec.js +8 -13
- package/adapter/adapter.spec.js.map +1 -1
- package/adapter/defineCucumber.js +9 -0
- package/adapter/defineCucumber.js.map +1 -0
- package/adapter/loader.js +28 -4
- package/adapter/loader.js.map +1 -1
- package/index.d.ts +1 -0
- package/index.js +4 -1
- package/package.json +6 -7
- package/src/adapter.spec.ts +12 -17
- package/src/defineCucumber.ts +8 -0
- package/src/loader.ts +30 -5
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,5 +10,12 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how
|
|
|
10
10
|
:pencil: - chore
|
|
11
11
|
:microscope: - experimental
|
|
12
12
|
|
|
13
|
+
## [0.3.0]
|
|
14
|
+
- :rocket: added _defineCucumber_ util function
|
|
15
|
+
- :rocket: added logic to process duplicates
|
|
16
|
+
|
|
17
|
+
## [0.2.0]
|
|
18
|
+
- :rocket: updated fixture implementation
|
|
19
|
+
|
|
13
20
|
## [0.1.0]
|
|
14
21
|
- :rocket: initial implementation
|
package/README.md
CHANGED
|
@@ -20,16 +20,17 @@ export default {
|
|
|
20
20
|
### Set testDir
|
|
21
21
|
Set testDir to adapter
|
|
22
22
|
```typescript
|
|
23
|
+
import { defineCucumber } from '@qavajs/playwright-runner-adapter';
|
|
24
|
+
|
|
25
|
+
defineCucumber({
|
|
26
|
+
config: 'test/cucumber.ts',
|
|
27
|
+
profile: 'default'
|
|
28
|
+
});
|
|
29
|
+
|
|
23
30
|
export default defineConfig({
|
|
24
31
|
testDir: resolve('node_modules/@qavajs/playwright-runner-adapter/adapter')
|
|
25
32
|
});
|
|
26
33
|
```
|
|
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
34
|
|
|
34
35
|
## Advanced Configuration
|
|
35
36
|
### Customizing test instance
|
|
@@ -57,6 +58,7 @@ class ExtendedPlaywrightWorld extends PlaywrightWorld {
|
|
|
57
58
|
super(options);
|
|
58
59
|
}
|
|
59
60
|
|
|
61
|
+
// set test property with extened one
|
|
60
62
|
test = customTest;
|
|
61
63
|
|
|
62
64
|
// init arrow function connects fixtures with Cucumber world instance
|
|
@@ -67,4 +69,7 @@ class ExtendedPlaywrightWorld extends PlaywrightWorld {
|
|
|
67
69
|
}
|
|
68
70
|
```
|
|
69
71
|
|
|
72
|
+
## Limitation
|
|
73
|
+
- ES modules are not supported (at least for node <= 22, where experimental ESM require is introduced)
|
|
74
|
+
|
|
70
75
|
|
package/adapter/adapter.spec.js
CHANGED
|
@@ -1,13 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var _a, _b;
|
|
3
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
3
|
const loader_1 = require("./loader");
|
|
5
|
-
const
|
|
6
|
-
const config = require((0, node_path_1.join)(process.cwd(), (_a = process.env.CONFIG) !== null && _a !== void 0 ? _a : 'config.js'));
|
|
7
|
-
const profile = (_b = process.env.PROFILE) !== null && _b !== void 0 ? _b : 'default';
|
|
8
|
-
const resolvedConfig = config[profile];
|
|
9
|
-
const features = (0, loader_1.loadFeatures)(resolvedConfig.paths);
|
|
10
|
-
const supportCodeLibrary = (0, loader_1.loadStepDefinitions)(resolvedConfig.require);
|
|
4
|
+
const { features, supportCodeLibrary } = (0, loader_1.load)();
|
|
11
5
|
function log(data) {
|
|
12
6
|
console.log(data);
|
|
13
7
|
}
|
|
@@ -17,11 +11,8 @@ function attach(body, details) {
|
|
|
17
11
|
const contentType = (_b = details.mediaType) !== null && _b !== void 0 ? _b : 'text/plain';
|
|
18
12
|
this.test.info().attach(fileName, { body, contentType });
|
|
19
13
|
}
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
attach
|
|
23
|
-
});
|
|
24
|
-
const test = world.test;
|
|
14
|
+
const fixture = new supportCodeLibrary.World({});
|
|
15
|
+
const test = fixture.test;
|
|
25
16
|
for (const feature of features) {
|
|
26
17
|
const tests = feature.tests;
|
|
27
18
|
test.describe(feature.feature, async () => {
|
|
@@ -30,9 +21,13 @@ for (const feature of features) {
|
|
|
30
21
|
await beforeAllHook.code.apply({});
|
|
31
22
|
});
|
|
32
23
|
}
|
|
24
|
+
const world = new supportCodeLibrary.World({
|
|
25
|
+
log,
|
|
26
|
+
attach
|
|
27
|
+
});
|
|
33
28
|
test.beforeEach(world.init);
|
|
34
29
|
for (const testCase of tests) {
|
|
35
|
-
const tag = testCase.tags.map(tag => tag.name);
|
|
30
|
+
const tag = testCase.tags.map((tag) => tag.name);
|
|
36
31
|
test(testCase.name, { tag }, async () => {
|
|
37
32
|
for (const beforeHook of supportCodeLibrary.beforeTestCaseHookDefinitions) {
|
|
38
33
|
if (beforeHook.appliesToTestCase(testCase)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adapter.spec.js","sourceRoot":"","sources":["../src/adapter.spec.ts"],"names":[],"mappings":"
|
|
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,I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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,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.defineCucumber = void 0;
|
|
4
|
+
function defineCucumber(config) {
|
|
5
|
+
process.env.CONFIG = config.config;
|
|
6
|
+
process.env.PROFILE = config.profile;
|
|
7
|
+
}
|
|
8
|
+
exports.defineCucumber = defineCucumber;
|
|
9
|
+
//# sourceMappingURL=defineCucumber.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defineCucumber.js","sourceRoot":"","sources":["../src/defineCucumber.ts"],"names":[],"mappings":";;;AAIA,SAAgB,cAAc,CAAC,MAAsB;IACjD,OAAO,CAAC,GAAG,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;IACnC,OAAO,CAAC,GAAG,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC;AACzC,CAAC;AAHD,wCAGC"}
|
package/adapter/loader.js
CHANGED
|
@@ -1,17 +1,31 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.loadStepDefinitions = exports.loadFeatures = void 0;
|
|
3
|
+
exports.load = exports.loadStepDefinitions = exports.loadFeatures = void 0;
|
|
4
4
|
const node_fs_1 = require("node:fs");
|
|
5
5
|
const node_path_1 = require("node:path");
|
|
6
|
+
const node_crypto_1 = require("node:crypto");
|
|
6
7
|
const gherkin_1 = require("@cucumber/gherkin");
|
|
7
|
-
const messages_1 = require("@cucumber/messages");
|
|
8
8
|
const cucumber_1 = require("@cucumber/cucumber");
|
|
9
9
|
const glob_1 = require("glob");
|
|
10
10
|
const PlaywrightWorld_1 = require("./PlaywrightWorld");
|
|
11
|
-
const uuidFn =
|
|
11
|
+
const uuidFn = () => (0, node_crypto_1.randomUUID)();
|
|
12
12
|
const builder = new gherkin_1.AstBuilder(uuidFn);
|
|
13
13
|
const matcher = new gherkin_1.GherkinClassicTokenMatcher();
|
|
14
14
|
const parser = new gherkin_1.Parser(builder, matcher);
|
|
15
|
+
function duplicates(tests) {
|
|
16
|
+
const counts = {};
|
|
17
|
+
return tests.map(item => {
|
|
18
|
+
const name = item.name;
|
|
19
|
+
if (!counts[name]) {
|
|
20
|
+
counts[name] = 0;
|
|
21
|
+
}
|
|
22
|
+
if (counts[name]) {
|
|
23
|
+
item.name = `${item.name} #${counts[item.name] + 1}`;
|
|
24
|
+
}
|
|
25
|
+
counts[item.name]++;
|
|
26
|
+
return item;
|
|
27
|
+
});
|
|
28
|
+
}
|
|
15
29
|
function loadFeatures(globPattern) {
|
|
16
30
|
const files = (0, glob_1.globSync)(globPattern);
|
|
17
31
|
return files.map(file => {
|
|
@@ -20,7 +34,7 @@ function loadFeatures(globPattern) {
|
|
|
20
34
|
const gherkinDocument = parser.parse((0, node_fs_1.readFileSync)(filePath, 'utf-8'));
|
|
21
35
|
return {
|
|
22
36
|
feature: (_a = gherkinDocument.feature) === null || _a === void 0 ? void 0 : _a.name,
|
|
23
|
-
tests: (0, gherkin_1.compile)(gherkinDocument, file, uuidFn)
|
|
37
|
+
tests: duplicates((0, gherkin_1.compile)(gherkinDocument, file, uuidFn))
|
|
24
38
|
};
|
|
25
39
|
});
|
|
26
40
|
}
|
|
@@ -36,4 +50,14 @@ function loadStepDefinitions(globPattern) {
|
|
|
36
50
|
return cucumber_1.supportCodeLibraryBuilder.finalize();
|
|
37
51
|
}
|
|
38
52
|
exports.loadStepDefinitions = loadStepDefinitions;
|
|
53
|
+
function load() {
|
|
54
|
+
var _a, _b;
|
|
55
|
+
const config = require((0, node_path_1.join)(process.cwd(), (_a = process.env.CONFIG) !== null && _a !== void 0 ? _a : 'config.js'));
|
|
56
|
+
const profile = (_b = process.env.PROFILE) !== null && _b !== void 0 ? _b : 'default';
|
|
57
|
+
const resolvedConfig = config[profile];
|
|
58
|
+
const features = loadFeatures(resolvedConfig.paths);
|
|
59
|
+
const supportCodeLibrary = loadStepDefinitions(resolvedConfig.require);
|
|
60
|
+
return { features, supportCodeLibrary };
|
|
61
|
+
}
|
|
62
|
+
exports.load = load;
|
|
39
63
|
//# 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":";;;AAAA,qCAAuC;AACvC,
|
|
1
|
+
{"version":3,"file":"loader.js","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":";;;AAAA,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,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE;QACpB,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;QACvB,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC;YAChB,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACrB,CAAC;QACD,IAAI,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC;YACf,IAAI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,kDASC;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,cAAc,CAAC,OAAO,CAAC,CAAC;IACvE,OAAO,EAAE,QAAQ,EAAE,kBAAkB,EAAE,CAAA;AAC3C,CAAC;AARD,oBAQC"}
|
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.3.0",
|
|
4
4
|
"description": "adapter for playwright test runner",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "tsc",
|
|
@@ -11,13 +11,12 @@
|
|
|
11
11
|
"license": "MIT",
|
|
12
12
|
"dependencies": {
|
|
13
13
|
"@cucumber/gherkin": "^28.0.0",
|
|
14
|
-
"
|
|
15
|
-
"glob": "^10.3.12"
|
|
14
|
+
"glob": "^10.3.15"
|
|
16
15
|
},
|
|
17
16
|
"devDependencies": {
|
|
18
|
-
"@cucumber/cucumber": "^10.
|
|
19
|
-
"@playwright/test": "^1.
|
|
20
|
-
"@types/node": "^20.12.
|
|
21
|
-
"typescript": "^5.4.
|
|
17
|
+
"@cucumber/cucumber": "^10.8.0",
|
|
18
|
+
"@playwright/test": "^1.44.1",
|
|
19
|
+
"@types/node": "^20.12.12",
|
|
20
|
+
"typescript": "^5.4.5"
|
|
22
21
|
}
|
|
23
22
|
}
|
package/src/adapter.spec.ts
CHANGED
|
@@ -1,12 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { join } from 'node:path';
|
|
1
|
+
import { load } from './loader';
|
|
3
2
|
|
|
4
|
-
const
|
|
5
|
-
const profile = process.env.PROFILE ?? 'default';
|
|
6
|
-
|
|
7
|
-
const resolvedConfig = config[profile];
|
|
8
|
-
const features = loadFeatures(resolvedConfig.paths);
|
|
9
|
-
const supportCodeLibrary = loadStepDefinitions(resolvedConfig.require);
|
|
3
|
+
const { features, supportCodeLibrary } = load();
|
|
10
4
|
|
|
11
5
|
function log(data: any) {
|
|
12
6
|
console.log(data);
|
|
@@ -14,14 +8,11 @@ function log(data: any) {
|
|
|
14
8
|
function attach(this: { test: any }, body: any, details: any) {
|
|
15
9
|
const fileName = details.fileName ?? 'attachment';
|
|
16
10
|
const contentType = details.mediaType ?? 'text/plain';
|
|
17
|
-
this.test.info().attach(fileName, { body, contentType })
|
|
11
|
+
this.test.info().attach(fileName, { body, contentType });
|
|
18
12
|
}
|
|
19
|
-
const world = new supportCodeLibrary.World({
|
|
20
|
-
log,
|
|
21
|
-
attach
|
|
22
|
-
});
|
|
23
13
|
|
|
24
|
-
const
|
|
14
|
+
const fixture = new supportCodeLibrary.World({});
|
|
15
|
+
const test = fixture.test;
|
|
25
16
|
|
|
26
17
|
for (const feature of features) {
|
|
27
18
|
const tests = feature.tests;
|
|
@@ -32,12 +23,16 @@ for (const feature of features) {
|
|
|
32
23
|
});
|
|
33
24
|
}
|
|
34
25
|
|
|
26
|
+
const world = new supportCodeLibrary.World({
|
|
27
|
+
log,
|
|
28
|
+
attach
|
|
29
|
+
});
|
|
30
|
+
|
|
35
31
|
test.beforeEach(world.init);
|
|
36
32
|
|
|
37
33
|
for (const testCase of tests) {
|
|
38
|
-
const tag = testCase.tags.map(tag => tag.name);
|
|
39
|
-
|
|
40
|
-
test(testCase.name, {tag}, async () => {
|
|
34
|
+
const tag = testCase.tags.map((tag: { name: string }) => tag.name);
|
|
35
|
+
test(testCase.name, { tag }, async () => {
|
|
41
36
|
for (const beforeHook of supportCodeLibrary.beforeTestCaseHookDefinitions) {
|
|
42
37
|
if (beforeHook.appliesToTestCase(testCase)) {
|
|
43
38
|
await test.step('Before', async () => {
|
package/src/loader.ts
CHANGED
|
@@ -1,16 +1,31 @@
|
|
|
1
1
|
import { readFileSync } from 'node:fs';
|
|
2
|
-
import { resolve } from 'node:path';
|
|
2
|
+
import { join, resolve } from 'node:path';
|
|
3
|
+
import { randomUUID } from 'node:crypto';
|
|
3
4
|
import { AstBuilder, compile, GherkinClassicTokenMatcher, Parser } from '@cucumber/gherkin';
|
|
4
|
-
import { IdGenerator } from '@cucumber/messages';
|
|
5
5
|
import { supportCodeLibraryBuilder } from '@cucumber/cucumber';
|
|
6
6
|
import { globSync } from 'glob';
|
|
7
|
-
import {PlaywrightWorld} from './PlaywrightWorld';
|
|
7
|
+
import { PlaywrightWorld } from './PlaywrightWorld';
|
|
8
8
|
|
|
9
|
-
const uuidFn =
|
|
9
|
+
const uuidFn = () => randomUUID();
|
|
10
10
|
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
|
}
|
|
@@ -33,3 +48,13 @@ export function loadStepDefinitions(globPattern: string[]) {
|
|
|
33
48
|
}
|
|
34
49
|
return supportCodeLibraryBuilder.finalize();
|
|
35
50
|
}
|
|
51
|
+
|
|
52
|
+
export function load() {
|
|
53
|
+
const config = require(join(process.cwd(), process.env.CONFIG ?? 'config.js'));
|
|
54
|
+
const profile = process.env.PROFILE ?? 'default';
|
|
55
|
+
|
|
56
|
+
const resolvedConfig = config[profile];
|
|
57
|
+
const features = loadFeatures(resolvedConfig.paths);
|
|
58
|
+
const supportCodeLibrary = loadStepDefinitions(resolvedConfig.require);
|
|
59
|
+
return { features, supportCodeLibrary }
|
|
60
|
+
}
|