Skip to content

Commit 1f62a88

Browse files
introduced BeforeExecution and AfterExecution hooks (#252)
* introduced `BeforeExecution` and `AfterExecution` hooks
1 parent f47e408 commit 1f62a88

File tree

13 files changed

+396
-253
lines changed

13 files changed

+396
-253
lines changed

CHANGELOG.MD

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,35 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how
1010
:pencil: - chore
1111
:microscope: - experimental
1212

13-
## [Unreleased]
13+
## [2.4.0]
14+
- :microscope: introduced `BeforeExecution` and `AfterExecution` hooks
15+
16+
```typescript
17+
import { BeforeExecution, AfterExecution } from '@qavajs/core';
18+
import { Server } from './server';
19+
20+
const server = new Server();
21+
22+
BeforeExecution(async function () {
23+
await server.start();
24+
});
25+
26+
AfterExecution(async function () {
27+
await server.stop();
28+
});
29+
```
1430
- :microscope: added capability to define `Template`
1531

16-
## 2.3.0
32+
```typescript
33+
import { When, Template } from '@qavajs/core';
34+
35+
When('I click {string} and verify {string}', Template((locator, expected) => `
36+
I click '${locator}'
37+
I expect '${locator} > Value' to equal '${expected}'
38+
`));
39+
```
40+
41+
## [2.3.0]
1742
- :microscope: added capability to define `Fixture`
1843
```typescript
1944
import { Fixture } from '@qavajs/core';

README.MD

Lines changed: 55 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -22,42 +22,6 @@ example
2222

2323
it will override $url memory value
2424

25-
### Service
26-
Services is an entities that can execute logic before and after whole test run.
27-
28-
```typescript
29-
import externalService from './externalService';
30-
31-
export default {
32-
service: [
33-
{
34-
options: {
35-
data: 42
36-
},
37-
before() {
38-
console.log(this.options.data);
39-
},
40-
after(result) {
41-
if (!result.success) process.exitCode = 1;
42-
}
43-
},
44-
{
45-
options: {
46-
data: 42
47-
},
48-
...externalService
49-
}
50-
]
51-
}
52-
```
53-
There is a one minute-long default timeout for a before and after test logic to prevent entire process from freezing.
54-
To set up a custom timeout in milliseconds use serviceTimeout property in the config file
55-
```typescript
56-
export default {
57-
serviceTimeout: 1_200_000
58-
}
59-
```
60-
6125
### Pass CLI params to workers
6226
All params that you passed to qavajs cli will be available in CLI_ARGV environment variable in all child workers.
6327

@@ -166,4 +130,59 @@ When('I click {string} and verify {string}', Template((locator, expected) => `
166130
I click '${locator}'
167131
I expect '${locator} > Value' to equal '${expected}'
168132
`));
133+
```
134+
135+
### Test Execution Hooks
136+
`BeforeExecution` and `AfterExecution` allow to define hooks that will be executed
137+
once before/after whole test execution
138+
139+
```typescript
140+
import { BeforeExecution, AfterExecution } from '@qavajs/core';
141+
import { Server } from './server';
142+
143+
const server = new Server();
144+
145+
BeforeExecution(async function () {
146+
await server.start();
147+
});
148+
149+
AfterExecution(async function () {
150+
await server.stop();
151+
});
152+
```
153+
154+
### Service
155+
Services is an entities that can execute logic before and after whole test run.
156+
157+
```typescript
158+
import externalService from './externalService';
159+
160+
export default {
161+
service: [
162+
{
163+
options: {
164+
data: 42
165+
},
166+
before() {
167+
console.log(this.options.data);
168+
},
169+
after(result) {
170+
if (!result.success) process.exitCode = 1;
171+
}
172+
},
173+
{
174+
options: {
175+
data: 42
176+
},
177+
...externalService
178+
}
179+
]
180+
}
181+
```
182+
There is a one minute-long default timeout for a before and after test logic to prevent entire process from freezing.
183+
To set up a custom timeout in milliseconds use serviceTimeout property in the config file
184+
```typescript
185+
export default {
186+
serviceTimeout: 1_200_000
187+
}
169188
```

index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { IConfiguration, IRunResult } from '@cucumber/cucumber/api';
44
export const Override: typeof When;
55
export { Fixture } from 'src/Fixture';
66
export { Template } from 'src/Template';
7+
export { BeforeExecution, AfterExecution } from 'src/executionHooks.js';
78

89
/**
910
* Validation function

index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@ const cucumber = require('@cucumber/cucumber');
22
const { Override } = require('./lib/Override');
33
const { Fixture } = require('./lib/Fixture');
44
const { Template } = require('./lib/Template');
5+
const { BeforeExecution, AfterExecution } = require('./lib/executionHooks');
56

67
module.exports = {
78
...cucumber,
89
Override,
910
Fixture,
10-
Template
11+
Template,
12+
BeforeExecution,
13+
AfterExecution
1114
}

index.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export { Override } from './lib/Override.js';
22
export { Fixture } from './lib/Fixture.js';
33
export { Template } from './lib/Template.js';
4+
export { BeforeExecution, AfterExecution } from './lib/executionHooks.js';
45
export * from '@cucumber/cucumber';

0 commit comments

Comments
 (0)