codeceptjs 3.5.12-beta.9 → 3.5.12
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/lib/actor.js +6 -3
- package/lib/step.js +3 -1
- package/package.json +3 -5
- package/typings/index.d.ts +0 -16
- package/typings/types.d.ts +1 -1
- package/lib/helper/MockServer.js +0 -221
package/lib/actor.js
CHANGED
|
@@ -13,15 +13,18 @@ const output = require('./output');
|
|
|
13
13
|
*/
|
|
14
14
|
class Actor {
|
|
15
15
|
/**
|
|
16
|
-
*
|
|
16
|
+
* Print the comment on log. Also, adding a step in the `Test.steps` object
|
|
17
17
|
* @param {string} msg
|
|
18
18
|
* @param {string} color
|
|
19
19
|
* @inner
|
|
20
20
|
*
|
|
21
21
|
* ⚠️ returns a promise which is synchronized internally by recorder
|
|
22
22
|
*/
|
|
23
|
-
say(msg, color = 'cyan') {
|
|
24
|
-
|
|
23
|
+
async say(msg, color = 'cyan') {
|
|
24
|
+
const step = new Step('say', 'say');
|
|
25
|
+
step.status = 'passed';
|
|
26
|
+
return recordStep(step, [msg]).then(() => {
|
|
27
|
+
// this is backward compatibility as this event may be used somewhere
|
|
25
28
|
event.emit(event.step.comment, msg);
|
|
26
29
|
output.say(msg, `${color}`);
|
|
27
30
|
});
|
package/lib/step.js
CHANGED
|
@@ -119,7 +119,9 @@ class Step {
|
|
|
119
119
|
}
|
|
120
120
|
let result;
|
|
121
121
|
try {
|
|
122
|
-
|
|
122
|
+
if (this.helperMethod !== 'say') {
|
|
123
|
+
result = this.helper[this.helperMethod].apply(this.helper, this.args);
|
|
124
|
+
}
|
|
123
125
|
this.setStatus('success');
|
|
124
126
|
} catch (err) {
|
|
125
127
|
this.setStatus('failed');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "codeceptjs",
|
|
3
|
-
"version": "3.5.12
|
|
3
|
+
"version": "3.5.12",
|
|
4
4
|
"description": "Supercharged End 2 End Testing Framework for NodeJS",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"acceptance",
|
|
@@ -55,7 +55,6 @@
|
|
|
55
55
|
"test:unit:webbapi:webDriver:devtools": "mocha test/helper/WebDriver_devtools_test.js --exit",
|
|
56
56
|
"test:unit:webbapi:testCafe": "mocha test/helper/TestCafe_test.js",
|
|
57
57
|
"test:unit:expect": "mocha test/helper/Expect_test.js",
|
|
58
|
-
"test:unit:mockServer": "mocha test/helper/MockServer_test.js",
|
|
59
58
|
"test:plugin": "mocha test/plugin/plugin_test.js",
|
|
60
59
|
"def": "./runok.js def",
|
|
61
60
|
"dev:graphql": "node test/data/graphql/index.js",
|
|
@@ -105,7 +104,6 @@
|
|
|
105
104
|
"ms": "2.1.3",
|
|
106
105
|
"openai": "3.2.1",
|
|
107
106
|
"ora-classic": "5.4.2",
|
|
108
|
-
"pactum": "3.6.0",
|
|
109
107
|
"parse-function": "5.6.4",
|
|
110
108
|
"parse5": "7.1.2",
|
|
111
109
|
"promise-retry": "1.1.1",
|
|
@@ -126,7 +124,7 @@
|
|
|
126
124
|
"@types/node": "20.10.7",
|
|
127
125
|
"@wdio/sauce-service": "8.27.0",
|
|
128
126
|
"@wdio/selenium-standalone-service": "8.3.2",
|
|
129
|
-
"@wdio/utils": "8.
|
|
127
|
+
"@wdio/utils": "8.28.8",
|
|
130
128
|
"@xmldom/xmldom": "0.8.10",
|
|
131
129
|
"apollo-server-express": "2.25.3",
|
|
132
130
|
"chai-as-promised": "7.1.1",
|
|
@@ -171,4 +169,4 @@
|
|
|
171
169
|
"npm": ">=5.6.0"
|
|
172
170
|
},
|
|
173
171
|
"es6": true
|
|
174
|
-
}
|
|
172
|
+
}
|
package/typings/index.d.ts
CHANGED
|
@@ -382,22 +382,6 @@ declare namespace CodeceptJS {
|
|
|
382
382
|
[key: string]: any;
|
|
383
383
|
};
|
|
384
384
|
|
|
385
|
-
type MockRequest = {
|
|
386
|
-
method: 'GET'|'PUT'|'POST'|'PATCH'|'DELETE'|string;
|
|
387
|
-
path: string;
|
|
388
|
-
queryParams?: object;
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
type MockResponse = {
|
|
392
|
-
status: number;
|
|
393
|
-
body?: object;
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
type MockInteraction = {
|
|
397
|
-
request: MockRequest;
|
|
398
|
-
response: MockResponse;
|
|
399
|
-
}
|
|
400
|
-
|
|
401
385
|
interface PageScrollPosition {
|
|
402
386
|
x: number;
|
|
403
387
|
y: number;
|
package/typings/types.d.ts
CHANGED
|
@@ -11448,7 +11448,7 @@ declare namespace CodeceptJS {
|
|
|
11448
11448
|
}
|
|
11449
11449
|
interface ActorStatic {
|
|
11450
11450
|
/**
|
|
11451
|
-
*
|
|
11451
|
+
* Print the comment on log. Also, adding a step in the `Test.steps` object
|
|
11452
11452
|
*/
|
|
11453
11453
|
say(msg: string, color?: string): void;
|
|
11454
11454
|
/**
|
package/lib/helper/MockServer.js
DELETED
|
@@ -1,221 +0,0 @@
|
|
|
1
|
-
const { mock, settings } = require('pactum');
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* ## Configuration
|
|
5
|
-
*
|
|
6
|
-
* This helper should be configured in codecept.conf.(js|ts)
|
|
7
|
-
*
|
|
8
|
-
* @typedef MockServerConfig
|
|
9
|
-
* @type {object}
|
|
10
|
-
* @prop {number} [port=9393] - Mock server port
|
|
11
|
-
* @prop {string} [host="0.0.0.0"] - Mock server host
|
|
12
|
-
* @prop {object} [httpsOpts] - key & cert values are the paths to .key and .crt files
|
|
13
|
-
*/
|
|
14
|
-
let config = {
|
|
15
|
-
port: 9393,
|
|
16
|
-
host: '0.0.0.0',
|
|
17
|
-
httpsOpts: {
|
|
18
|
-
key: '',
|
|
19
|
-
cert: '',
|
|
20
|
-
},
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* MockServer
|
|
25
|
-
*
|
|
26
|
-
* The MockServer Helper in CodeceptJS empowers you to mock any server or service via HTTP or HTTPS, making it an excellent tool for simulating REST endpoints and other HTTP-based APIs.
|
|
27
|
-
*
|
|
28
|
-
* <!-- configuration -->
|
|
29
|
-
*
|
|
30
|
-
* #### Examples
|
|
31
|
-
*
|
|
32
|
-
* You can seamlessly integrate MockServer with other helpers like REST or Playwright. Here's a configuration example inside the `codecept.conf.js` file:
|
|
33
|
-
*
|
|
34
|
-
* ```javascript
|
|
35
|
-
* {
|
|
36
|
-
* helpers: {
|
|
37
|
-
* REST: {...},
|
|
38
|
-
* MockServer: {
|
|
39
|
-
* // default mock server config
|
|
40
|
-
* port: 9393,
|
|
41
|
-
* host: '0.0.0.0',
|
|
42
|
-
* httpsOpts: {
|
|
43
|
-
* key: '',
|
|
44
|
-
* cert: '',
|
|
45
|
-
* },
|
|
46
|
-
* },
|
|
47
|
-
* }
|
|
48
|
-
* }
|
|
49
|
-
* ```
|
|
50
|
-
*
|
|
51
|
-
* #### Adding Interactions
|
|
52
|
-
*
|
|
53
|
-
* Interactions add behavior to the mock server. Use the `I.addInteractionToMockServer()` method to include interactions. It takes an interaction object as an argument, containing request and response details.
|
|
54
|
-
*
|
|
55
|
-
* ```javascript
|
|
56
|
-
* I.addInteractionToMockServer({
|
|
57
|
-
* request: {
|
|
58
|
-
* method: 'GET',
|
|
59
|
-
* path: '/api/hello'
|
|
60
|
-
* },
|
|
61
|
-
* response: {
|
|
62
|
-
* status: 200,
|
|
63
|
-
* body: {
|
|
64
|
-
* 'say': 'hello to mock server'
|
|
65
|
-
* }
|
|
66
|
-
* }
|
|
67
|
-
* });
|
|
68
|
-
* ```
|
|
69
|
-
*
|
|
70
|
-
* #### Request Matching
|
|
71
|
-
*
|
|
72
|
-
* When a real request is sent to the mock server, it matches the received request with the interactions. If a match is found, it returns the specified response; otherwise, a 404 status code is returned.
|
|
73
|
-
*
|
|
74
|
-
* - Strong match on HTTP Method, Path, Query Params & JSON body.
|
|
75
|
-
* - Loose match on Headers.
|
|
76
|
-
*
|
|
77
|
-
* ##### Strong Match on Query Params
|
|
78
|
-
*
|
|
79
|
-
* You can send different responses based on query parameters:
|
|
80
|
-
*
|
|
81
|
-
* ```javascript
|
|
82
|
-
* I.addInteractionToMockServer({
|
|
83
|
-
* request: {
|
|
84
|
-
* method: 'GET',
|
|
85
|
-
* path: '/api/users',
|
|
86
|
-
* queryParams: {
|
|
87
|
-
* id: 1
|
|
88
|
-
* }
|
|
89
|
-
* },
|
|
90
|
-
* response: {
|
|
91
|
-
* status: 200,
|
|
92
|
-
* body: 'user 1'
|
|
93
|
-
* }
|
|
94
|
-
* });
|
|
95
|
-
*
|
|
96
|
-
* I.addInteractionToMockServer({
|
|
97
|
-
* request: {
|
|
98
|
-
* method: 'GET',
|
|
99
|
-
* path: '/api/users',
|
|
100
|
-
* queryParams: {
|
|
101
|
-
* id: 2
|
|
102
|
-
* }
|
|
103
|
-
* },
|
|
104
|
-
* response: {
|
|
105
|
-
* status: 200,
|
|
106
|
-
* body: 'user 2'
|
|
107
|
-
* }
|
|
108
|
-
* });
|
|
109
|
-
* ```
|
|
110
|
-
*
|
|
111
|
-
* - GET to `/api/users?id=1` will return 'user 1'.
|
|
112
|
-
* - GET to `/api/users?id=2` will return 'user 2'.
|
|
113
|
-
* - For all other requests, it returns a 404 status code.
|
|
114
|
-
*
|
|
115
|
-
* ##### Loose Match on Body
|
|
116
|
-
*
|
|
117
|
-
* When `strict` is set to false, it performs a loose match on query params and response body:
|
|
118
|
-
*
|
|
119
|
-
* ```javascript
|
|
120
|
-
* I.addInteractionToMockServer({
|
|
121
|
-
* strict: false,
|
|
122
|
-
* request: {
|
|
123
|
-
* method: 'POST',
|
|
124
|
-
* path: '/api/users',
|
|
125
|
-
* body: {
|
|
126
|
-
* name: 'john'
|
|
127
|
-
* }
|
|
128
|
-
* },
|
|
129
|
-
* response: {
|
|
130
|
-
* status: 200
|
|
131
|
-
* }
|
|
132
|
-
* });
|
|
133
|
-
* ```
|
|
134
|
-
*
|
|
135
|
-
* - POST to `/api/users` with the body containing `name` as 'john' will return a 200 status code.
|
|
136
|
-
* - POST to `/api/users` without the `name` property in the body will return a 404 status code.
|
|
137
|
-
*
|
|
138
|
-
* Happy testing with MockServer in CodeceptJS! 🚀
|
|
139
|
-
*
|
|
140
|
-
* ## Methods
|
|
141
|
-
*/
|
|
142
|
-
class MockServer {
|
|
143
|
-
constructor(passedConfig) {
|
|
144
|
-
settings.setLogLevel('SILENT');
|
|
145
|
-
config = { ...passedConfig };
|
|
146
|
-
if (global.debugMode) {
|
|
147
|
-
settings.setLogLevel('VERBOSE');
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* Start the mock server
|
|
153
|
-
* @param {number} [port] start the mock server with given port
|
|
154
|
-
*
|
|
155
|
-
* @returns void
|
|
156
|
-
*/
|
|
157
|
-
async startMockServer(port) {
|
|
158
|
-
const _config = { ...config };
|
|
159
|
-
if (port) _config.port = port;
|
|
160
|
-
await mock.setDefaults(_config);
|
|
161
|
-
await mock.start();
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
/**
|
|
165
|
-
* Stop the mock server
|
|
166
|
-
*
|
|
167
|
-
* @returns void
|
|
168
|
-
*
|
|
169
|
-
*/
|
|
170
|
-
async stopMockServer() {
|
|
171
|
-
await mock.stop();
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
/**
|
|
175
|
-
* An interaction adds behavior to the mock server
|
|
176
|
-
*
|
|
177
|
-
*
|
|
178
|
-
* ```js
|
|
179
|
-
* I.addInteractionToMockServer({
|
|
180
|
-
* request: {
|
|
181
|
-
* method: 'GET',
|
|
182
|
-
* path: '/api/hello'
|
|
183
|
-
* },
|
|
184
|
-
* response: {
|
|
185
|
-
* status: 200,
|
|
186
|
-
* body: {
|
|
187
|
-
* 'say': 'hello to mock server'
|
|
188
|
-
* }
|
|
189
|
-
* }
|
|
190
|
-
* });
|
|
191
|
-
* ```
|
|
192
|
-
* ```js
|
|
193
|
-
* // with query params
|
|
194
|
-
* I.addInteractionToMockServer({
|
|
195
|
-
* request: {
|
|
196
|
-
* method: 'GET',
|
|
197
|
-
* path: '/api/hello',
|
|
198
|
-
* queryParams: {
|
|
199
|
-
* id: 2
|
|
200
|
-
* }
|
|
201
|
-
* },
|
|
202
|
-
* response: {
|
|
203
|
-
* status: 200,
|
|
204
|
-
* body: {
|
|
205
|
-
* 'say': 'hello to mock server'
|
|
206
|
-
* }
|
|
207
|
-
* }
|
|
208
|
-
* });
|
|
209
|
-
* ```
|
|
210
|
-
*
|
|
211
|
-
* @param {CodeceptJS.MockInteraction|object} interaction add behavior to the mock server
|
|
212
|
-
*
|
|
213
|
-
* @returns void
|
|
214
|
-
*
|
|
215
|
-
*/
|
|
216
|
-
async addInteractionToMockServer(interaction) {
|
|
217
|
-
await mock.addInteraction(interaction);
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
module.exports = MockServer;
|