cucumber-fixture 0.1.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/LICENSE +21 -0
- package/README.md +77 -0
- package/dist/index.cjs +52 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.js +50 -0
- package/package.json +64 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Lennart Gerken
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# cucumber-fixture
|
|
2
|
+
|
|
3
|
+
`cucumber-fixture` provides a fixture structure for Cucumber step definitions.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npm i -D cucumber-fixture
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
To use `cucumber-fixture`, call `createKeywords`, pass the original Cucumber keywords, and define the fixtures you need.
|
|
14
|
+
|
|
15
|
+
For every fixture, define a `setup` function that specifies how the fixture is created. You can also optionally define a `teardown` function. `teardown` functions are called automatically after each test.
|
|
16
|
+
|
|
17
|
+
A fixture can also be marked as `global` to keep it alive for the whole test run. In that case, its `teardown` is run automatically after the run.
|
|
18
|
+
|
|
19
|
+
An example would be to define fixtures for E2E tests:
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
import { createKeywords } from 'cucumber-fixture'
|
|
23
|
+
import {
|
|
24
|
+
BeforeAll as baseBeforeAll,
|
|
25
|
+
AfterAll as baseAfterAll,
|
|
26
|
+
Before as baseBefore,
|
|
27
|
+
After as baseAfter,
|
|
28
|
+
defineStep
|
|
29
|
+
} from '@cucumber/cucumber'
|
|
30
|
+
import { Browser, BrowserContext, chromium, Page } from 'playwright'
|
|
31
|
+
import { CustomWorld, world } from '@/features/support/world'
|
|
32
|
+
import { SomePageObject } from '@/pages/some-page-object'
|
|
33
|
+
|
|
34
|
+
export const { BeforeAll, AfterAll, Before, After, Given, When, Then } =
|
|
35
|
+
createKeywords<{
|
|
36
|
+
world: CustomWorld
|
|
37
|
+
browser: Browser
|
|
38
|
+
context: BrowserContext
|
|
39
|
+
page: Page
|
|
40
|
+
somePageObject: SomePageObject
|
|
41
|
+
}>(baseBeforeAll, baseAfterAll, baseBefore, baseAfter, defineStep, {
|
|
42
|
+
world: () => world,
|
|
43
|
+
browser: {
|
|
44
|
+
setup: () => chromium.launch(),
|
|
45
|
+
teardown: ({ browser }) => browser.close(),
|
|
46
|
+
global: true
|
|
47
|
+
},
|
|
48
|
+
context: {
|
|
49
|
+
setup: ({ browser }) => browser.newContext(),
|
|
50
|
+
teardown: ({ context }) => context.close()
|
|
51
|
+
},
|
|
52
|
+
page: ({ context }) => context.newPage(),
|
|
53
|
+
somePageObject: ({ page }) => {
|
|
54
|
+
// Initialize the page object.
|
|
55
|
+
// ...
|
|
56
|
+
return new SomePageObject(page)
|
|
57
|
+
}
|
|
58
|
+
})
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
You can now use your fixtures directly in your step definitions:
|
|
62
|
+
|
|
63
|
+
```ts
|
|
64
|
+
import { Given } from '@/keywords'
|
|
65
|
+
|
|
66
|
+
Given(
|
|
67
|
+
'some Given step with a parameter {string}',
|
|
68
|
+
async ({ somePageObject }, someData: string) => {
|
|
69
|
+
// Use the fixtures in your step definitions.
|
|
70
|
+
await somePageObject.doSomething(someData)
|
|
71
|
+
}
|
|
72
|
+
)
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## License
|
|
76
|
+
|
|
77
|
+
This package is licensed under the [MIT License](./LICENSE).
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var pseudoFixture = require('pseudo-fixture');
|
|
4
|
+
|
|
5
|
+
function createKeywords(baseBeforeAll, baseAfterAll, baseBefore, baseAfter, defineStep, fixtureDefinitions) {
|
|
6
|
+
const pseudoFixture$1 = new pseudoFixture.PseudoFixture(fixtureDefinitions);
|
|
7
|
+
baseAfter(() => pseudoFixture$1.runTeardown());
|
|
8
|
+
baseAfterAll(() => pseudoFixture$1.runGlobalTeardown());
|
|
9
|
+
function createCallback(code) {
|
|
10
|
+
const callback = (...args) => {
|
|
11
|
+
return pseudoFixture$1.run(code, ...args);
|
|
12
|
+
};
|
|
13
|
+
const originalLength = code.length;
|
|
14
|
+
Object.defineProperty(callback, 'length', {
|
|
15
|
+
value: originalLength > 0 ? code.length - 1 : 0
|
|
16
|
+
});
|
|
17
|
+
return callback;
|
|
18
|
+
}
|
|
19
|
+
function createHook(baseHook) {
|
|
20
|
+
return function (optionsOrCode, code) {
|
|
21
|
+
if (typeof optionsOrCode === 'function')
|
|
22
|
+
baseHook(createCallback(optionsOrCode));
|
|
23
|
+
else
|
|
24
|
+
baseHook(optionsOrCode, createCallback(code));
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
function createGlobalHook(baseGlobalHook) {
|
|
28
|
+
return function (optionsOrCode, code) {
|
|
29
|
+
if (typeof optionsOrCode === 'function')
|
|
30
|
+
baseGlobalHook(createCallback(optionsOrCode));
|
|
31
|
+
else
|
|
32
|
+
baseGlobalHook(optionsOrCode, createCallback(code));
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
const fixDefineStep = function (pattern, optionsOrCode, code) {
|
|
36
|
+
if (typeof optionsOrCode === 'function')
|
|
37
|
+
defineStep(pattern, createCallback(optionsOrCode));
|
|
38
|
+
else
|
|
39
|
+
defineStep(pattern, optionsOrCode, createCallback(code));
|
|
40
|
+
};
|
|
41
|
+
return {
|
|
42
|
+
BeforeAll: createGlobalHook(baseBeforeAll),
|
|
43
|
+
AfterAll: createGlobalHook(baseAfterAll),
|
|
44
|
+
Before: createHook(baseBefore),
|
|
45
|
+
After: createHook(baseAfter),
|
|
46
|
+
Given: fixDefineStep,
|
|
47
|
+
When: fixDefineStep,
|
|
48
|
+
Then: fixDefineStep
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
exports.createKeywords = createKeywords;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { BeforeAll as OriginalBeforeAll, Before as OriginalBefore, defineStep as OriginalStep } from '@cucumber/cucumber';
|
|
2
|
+
import { Definitions } from 'pseudo-fixture';
|
|
3
|
+
type BaseGlobalHook = typeof OriginalBeforeAll;
|
|
4
|
+
type BaseHook = typeof OriginalBefore;
|
|
5
|
+
type BaseStep = typeof OriginalStep;
|
|
6
|
+
type Code<F, A extends unknown[]> = (fixtures: F, ...args: A) => Promise<void> | void;
|
|
7
|
+
type HookCode<F> = (fixtures: F, options: Parameters<Parameters<BaseHook>[1]>[0]) => Promise<void> | void;
|
|
8
|
+
type GlobalHookCode<F> = (fixtures: F) => Promise<void> | void;
|
|
9
|
+
type Step<F> = {
|
|
10
|
+
<A extends unknown[]>(pattern: string | RegExp, options: Parameters<BaseStep>[1], code: Code<F, A>): void;
|
|
11
|
+
<A extends unknown[]>(pattern: string | RegExp, code: Code<F, A>): void;
|
|
12
|
+
};
|
|
13
|
+
type Hook<F> = {
|
|
14
|
+
(options: Parameters<BaseHook>[0], code: HookCode<F>): void;
|
|
15
|
+
(code: HookCode<F>): void;
|
|
16
|
+
};
|
|
17
|
+
type GlobalHook<F> = {
|
|
18
|
+
(options: Parameters<BaseGlobalHook>[0], code: GlobalHookCode<F>): void;
|
|
19
|
+
(code: GlobalHookCode<F>): void;
|
|
20
|
+
};
|
|
21
|
+
export declare function createKeywords<F extends object>(baseBeforeAll: BaseGlobalHook, baseAfterAll: BaseGlobalHook, baseBefore: BaseHook, baseAfter: BaseHook, defineStep: BaseStep, fixtureDefinitions: Definitions<F, object>): {
|
|
22
|
+
BeforeAll: GlobalHook<F>;
|
|
23
|
+
AfterAll: GlobalHook<F>;
|
|
24
|
+
Before: Hook<F>;
|
|
25
|
+
After: Hook<F>;
|
|
26
|
+
Given: Step<F>;
|
|
27
|
+
When: Step<F>;
|
|
28
|
+
Then: Step<F>;
|
|
29
|
+
};
|
|
30
|
+
export {};
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { PseudoFixture } from 'pseudo-fixture';
|
|
2
|
+
|
|
3
|
+
function createKeywords(baseBeforeAll, baseAfterAll, baseBefore, baseAfter, defineStep, fixtureDefinitions) {
|
|
4
|
+
const pseudoFixture = new PseudoFixture(fixtureDefinitions);
|
|
5
|
+
baseAfter(() => pseudoFixture.runTeardown());
|
|
6
|
+
baseAfterAll(() => pseudoFixture.runGlobalTeardown());
|
|
7
|
+
function createCallback(code) {
|
|
8
|
+
const callback = (...args) => {
|
|
9
|
+
return pseudoFixture.run(code, ...args);
|
|
10
|
+
};
|
|
11
|
+
const originalLength = code.length;
|
|
12
|
+
Object.defineProperty(callback, 'length', {
|
|
13
|
+
value: originalLength > 0 ? code.length - 1 : 0
|
|
14
|
+
});
|
|
15
|
+
return callback;
|
|
16
|
+
}
|
|
17
|
+
function createHook(baseHook) {
|
|
18
|
+
return function (optionsOrCode, code) {
|
|
19
|
+
if (typeof optionsOrCode === 'function')
|
|
20
|
+
baseHook(createCallback(optionsOrCode));
|
|
21
|
+
else
|
|
22
|
+
baseHook(optionsOrCode, createCallback(code));
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
function createGlobalHook(baseGlobalHook) {
|
|
26
|
+
return function (optionsOrCode, code) {
|
|
27
|
+
if (typeof optionsOrCode === 'function')
|
|
28
|
+
baseGlobalHook(createCallback(optionsOrCode));
|
|
29
|
+
else
|
|
30
|
+
baseGlobalHook(optionsOrCode, createCallback(code));
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
const fixDefineStep = function (pattern, optionsOrCode, code) {
|
|
34
|
+
if (typeof optionsOrCode === 'function')
|
|
35
|
+
defineStep(pattern, createCallback(optionsOrCode));
|
|
36
|
+
else
|
|
37
|
+
defineStep(pattern, optionsOrCode, createCallback(code));
|
|
38
|
+
};
|
|
39
|
+
return {
|
|
40
|
+
BeforeAll: createGlobalHook(baseBeforeAll),
|
|
41
|
+
AfterAll: createGlobalHook(baseAfterAll),
|
|
42
|
+
Before: createHook(baseBefore),
|
|
43
|
+
After: createHook(baseAfter),
|
|
44
|
+
Given: fixDefineStep,
|
|
45
|
+
When: fixDefineStep,
|
|
46
|
+
Then: fixDefineStep
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export { createKeywords };
|
package/package.json
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "cucumber-fixture",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"author": "Lennart Gerken",
|
|
6
|
+
"description": "cucumber-fixture provides a fixture structure for Cucumber step definitions.",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"cucumber",
|
|
9
|
+
"bdd",
|
|
10
|
+
"test",
|
|
11
|
+
"testautomation",
|
|
12
|
+
"fixtures"
|
|
13
|
+
],
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "git+https://github.com/lennartgerken/cucumber-fixture.git"
|
|
17
|
+
},
|
|
18
|
+
"bugs": {
|
|
19
|
+
"url": "https://github.com/lennartgerken/cucumber-fixture/issues"
|
|
20
|
+
},
|
|
21
|
+
"type": "module",
|
|
22
|
+
"types": "./dist/index.d.ts",
|
|
23
|
+
"exports": {
|
|
24
|
+
".": {
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
|
+
"import": "./dist/index.js",
|
|
27
|
+
"require": "./dist/index.cjs"
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"module": "./dist/index.js",
|
|
31
|
+
"main": "./dist/index.cjs",
|
|
32
|
+
"files": [
|
|
33
|
+
"dist"
|
|
34
|
+
],
|
|
35
|
+
"scripts": {
|
|
36
|
+
"pretty": "prettier . --write",
|
|
37
|
+
"pretty:check": "prettier . --check",
|
|
38
|
+
"lint": "eslint .",
|
|
39
|
+
"type-check": "tsc -p tsconfig.json --noEmit",
|
|
40
|
+
"type-check:tests": "tsc -p tests/tsconfig.json --noEmit",
|
|
41
|
+
"build": "rollup -c",
|
|
42
|
+
"test": "vitest run"
|
|
43
|
+
},
|
|
44
|
+
"peerDependencies": {
|
|
45
|
+
"@cucumber/cucumber": "^13.0.0"
|
|
46
|
+
},
|
|
47
|
+
"dependencies": {
|
|
48
|
+
"pseudo-fixture": "^1.4.0"
|
|
49
|
+
},
|
|
50
|
+
"devDependencies": {
|
|
51
|
+
"@cucumber/cucumber": "^13.0.0",
|
|
52
|
+
"@eslint/js": "^10.0.1",
|
|
53
|
+
"@rollup/plugin-typescript": "^12.3.0",
|
|
54
|
+
"@types/node": "^25.9.3",
|
|
55
|
+
"eslint": "^10.4.1",
|
|
56
|
+
"prettier": "^3.8.4",
|
|
57
|
+
"rollup": "^4.61.1",
|
|
58
|
+
"tslib": "^2.8.1",
|
|
59
|
+
"tsx": "^4.22.4",
|
|
60
|
+
"typescript": "^6.0.3",
|
|
61
|
+
"typescript-eslint": "^8.60.1",
|
|
62
|
+
"vitest": "^4.1.8"
|
|
63
|
+
}
|
|
64
|
+
}
|