Skip to content

Commit 9c499a4

Browse files
committed
fix: lint
1 parent 83030f5 commit 9c499a4

File tree

1 file changed

+44
-35
lines changed

1 file changed

+44
-35
lines changed

lib/helper/network/actions.js

Lines changed: 44 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,77 @@
1-
const assert = require('assert')
2-
const { isInTraffic, createAdvancedTestResults, getTrafficDump } = require('./utils')
1+
const assert = require('assert');
2+
const { isInTraffic, createAdvancedTestResults, getTrafficDump } = require('./utils');
33

44
function dontSeeTraffic({ name, url }) {
55
if (!this.recordedAtLeastOnce) {
6-
throw new Error('Failure in test automation. You use "I.dontSeeTraffic", but "I.startRecordingTraffic" was never called before.')
6+
throw new Error('Failure in test automation. You use "I.dontSeeTraffic", but "I.startRecordingTraffic" was never called before.');
77
}
88

99
if (!name) {
10-
throw new Error('Missing required key "name" in object given to "I.dontSeeTraffic".')
10+
throw new Error('Missing required key "name" in object given to "I.dontSeeTraffic".');
1111
}
1212

1313
if (!url) {
14-
throw new Error('Missing required key "url" in object given to "I.dontSeeTraffic".')
14+
throw new Error('Missing required key "url" in object given to "I.dontSeeTraffic".');
1515
}
1616

1717
if (isInTraffic.call(this, url)) {
18-
assert.fail(`Traffic with name "${name}" (URL: "${url}') found, but was not expected to be found.`)
18+
assert.fail(`Traffic with name "${name}" (URL: "${url}') found, but was not expected to be found.`);
1919
}
2020
}
2121

22-
async function seeTraffic({ name, url, parameters, requestPostData, timeout = 10 }) {
22+
async function seeTraffic({
23+
name, url, parameters, requestPostData, timeout = 10,
24+
}) {
2325
if (!name) {
24-
throw new Error('Missing required key "name" in object given to "I.seeTraffic".')
26+
throw new Error('Missing required key "name" in object given to "I.seeTraffic".');
2527
}
2628

2729
if (!url) {
28-
throw new Error('Missing required key "url" in object given to "I.seeTraffic".')
30+
throw new Error('Missing required key "url" in object given to "I.seeTraffic".');
2931
}
3032

3133
if (!this.recordedAtLeastOnce) {
32-
throw new Error('Failure in test automation. You use "I.seeTraffic", but "I.startRecordingTraffic" was never called before.')
34+
throw new Error('Failure in test automation. You use "I.seeTraffic", but "I.startRecordingTraffic" was never called before.');
3335
}
3436

3537
for (let i = 0; i <= timeout * 2; i++) {
36-
const found = isInTraffic.call(this, url, parameters)
38+
const found = isInTraffic.call(this, url, parameters);
3739
if (found) {
38-
return true
40+
return true;
3941
}
40-
await new Promise(done => {
41-
setTimeout(done, 1000)
42-
})
42+
await new Promise((done) => {
43+
setTimeout(done, 1000);
44+
});
4345
}
4446

4547
// check request post data
4648
if (requestPostData && isInTraffic.call(this, url)) {
47-
const advancedTestResults = createAdvancedTestResults(url, requestPostData, this.requests)
49+
const advancedTestResults = createAdvancedTestResults(url, requestPostData, this.requests);
4850

49-
assert.equal(advancedTestResults, true, `Traffic named "${name}" found correct URL ${url}, BUT the post data did not match:\n ${advancedTestResults}`)
51+
assert.equal(advancedTestResults, true, `Traffic named "${name}" found correct URL ${url}, BUT the post data did not match:\n ${advancedTestResults}`);
5052
} else if (parameters && isInTraffic.call(this, url)) {
51-
const advancedTestResults = createAdvancedTestResults(url, parameters, this.requests)
53+
const advancedTestResults = createAdvancedTestResults(url, parameters, this.requests);
5254

53-
assert.fail(`Traffic named "${name}" found correct URL ${url}, BUT the query parameters did not match:\n` + `${advancedTestResults}`)
55+
assert.fail(
56+
`Traffic named "${name}" found correct URL ${url}, BUT the query parameters did not match:\n`
57+
+ `${advancedTestResults}`,
58+
);
5459
} else {
55-
assert.fail(`Traffic named "${name}" not found in recorded traffic within ${timeout} seconds.\n` + `Expected url: ${url}.\n` + `Recorded traffic:\n${getTrafficDump.call(this)}`)
60+
assert.fail(
61+
`Traffic named "${name}" not found in recorded traffic within ${timeout} seconds.\n`
62+
+ `Expected url: ${url}.\n`
63+
+ `Recorded traffic:\n${getTrafficDump.call(this)}`,
64+
);
5665
}
5766
}
5867

5968
async function grabRecordedNetworkTraffics() {
6069
if (!this.recordedAtLeastOnce) {
61-
throw new Error('Failure in test automation. You use "I.grabRecordedNetworkTraffics", but "I.startRecordingTraffic" was never called before.')
70+
throw new Error('Failure in test automation. You use "I.grabRecordedNetworkTraffics", but "I.startRecordingTraffic" was never called before.');
6271
}
6372

64-
const promises = this.requests.map(async request => {
65-
const resp = await request.response
73+
const promises = this.requests.map(async (request) => {
74+
const resp = await request.response;
6675

6776
if (!resp) {
6877
return {
@@ -72,13 +81,13 @@ async function grabRecordedNetworkTraffics() {
7281
statusText: '',
7382
body: '',
7483
},
75-
}
84+
};
7685
}
7786

78-
let body
87+
let body;
7988
try {
8089
// There's no 'body' for some requests (redirect etc...)
81-
body = JSON.parse((await resp.body()).toString())
90+
body = JSON.parse((await resp.body()).toString());
8291
} catch (e) {
8392
// only interested in JSON, not HTML responses.
8493
}
@@ -90,21 +99,21 @@ async function grabRecordedNetworkTraffics() {
9099
statusText: resp.statusText(),
91100
body,
92101
},
93-
}
94-
})
95-
return Promise.all(promises)
102+
};
103+
});
104+
return Promise.all(promises);
96105
}
97106

98107
function stopRecordingTraffic() {
99108
// @ts-ignore
100-
this.page.removeAllListeners('request')
101-
// @ts-ignore
102-
this.page.removeAllListeners('requestfinished')
103-
this.recording = false
109+
this.page.removeAllListeners('request');
110+
// @ts-ignore
111+
this.page.removeAllListeners('requestfinished');
112+
this.recording = false;
104113
}
105114

106115
function flushNetworkTraffics() {
107-
this.requests = []
116+
this.requests = [];
108117
}
109118

110119
module.exports = {
@@ -113,4 +122,4 @@ module.exports = {
113122
grabRecordedNetworkTraffics,
114123
stopRecordingTraffic,
115124
flushNetworkTraffics,
116-
}
125+
};

0 commit comments

Comments
 (0)