Skip to content

Commit 7a54f8a

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent b6eecab commit 7a54f8a

File tree

3 files changed

+144
-121
lines changed

3 files changed

+144
-121
lines changed

test/api_spec.js

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ describe("API Tests", function () {
2424
.then(function () {
2525
r = (path, options) => {
2626
options = options || {};
27-
path = path || '';
27+
path = path || "";
2828
const url = `${options.url || apiUrl}${path}`;
2929
delete options.url;
3030
const fetchOptions = {
@@ -81,7 +81,9 @@ describe("API Tests", function () {
8181
});
8282

8383
it("GET /api/routes fetches the routing table", function (done) {
84-
r().then(res => res.json()).then(function (reply) {
84+
r()
85+
.then((res) => res.json())
86+
.then(function (reply) {
8587
var keys = Object.keys(reply);
8688
expect(keys.length).toEqual(1);
8789
expect(keys).toContain("/");
@@ -97,7 +99,7 @@ describe("API Tests", function () {
9799
.then(function () {
98100
return r(path);
99101
})
100-
.then(res => res.json())
102+
.then((res) => res.json())
101103
.then(function (reply) {
102104
var keys = Object.keys(reply);
103105
expect(keys).toContain("target");
@@ -120,10 +122,10 @@ describe("API Tests", function () {
120122
var target = "http://127.0.0.1:" + port;
121123

122124
r("/user/foo", {
123-
method: 'POST',
125+
method: "POST",
124126
body: JSON.stringify({ target: target }),
125127
})
126-
.then(res => res.text())
128+
.then((res) => res.text())
127129
.then((body) => {
128130
expect(body).toEqual("");
129131
})
@@ -143,7 +145,7 @@ describe("API Tests", function () {
143145
method: "POST",
144146
body: JSON.stringify({ target: target }),
145147
})
146-
.then(res => res.text())
148+
.then((res) => res.text())
147149
.then((body) => {
148150
expect(body).toEqual("");
149151
})
@@ -162,11 +164,11 @@ describe("API Tests", function () {
162164
it("POST /api/routes creates a new root route", function (done) {
163165
var port = 8998;
164166
var target = "http://127.0.0.1:" + port;
165-
r('', {
167+
r("", {
166168
method: "POST",
167169
body: JSON.stringify({ target: target }),
168170
})
169-
.then(res => res.text())
171+
.then((res) => res.text())
170172
.then((body) => {
171173
expect(body).toEqual("");
172174
return proxy._routes.get("/");
@@ -188,7 +190,7 @@ describe("API Tests", function () {
188190
.then(() => proxy._routes.get(path))
189191
.then((route) => expect(route.target).toEqual(target))
190192
.then(() => r(path, { url: apiUrl, method: "DELETE" }))
191-
.then(res => res.text())
193+
.then((res) => res.text())
192194
.then((body) => expect(body).toEqual(""))
193195
.then(() => proxy._routes.get(path))
194196
.then((deletedRoute) => expect(deletedRoute).toBe(undefined))
@@ -235,27 +237,29 @@ describe("API Tests", function () {
235237
var seen = 0;
236238
var doReq = function (i) {
237239
var t = tests[i];
238-
return r("?inactiveSince=" + t.since.toISOString()).then(res => res.json()).then(function (routes) {
239-
var routeKeys = Object.keys(routes);
240-
var expectedKeys = Object.keys(t.expected);
240+
return r("?inactiveSince=" + t.since.toISOString())
241+
.then((res) => res.json())
242+
.then(function (routes) {
243+
var routeKeys = Object.keys(routes);
244+
var expectedKeys = Object.keys(t.expected);
241245

242-
routeKeys.forEach(function (key) {
243-
// check that all routes are expected
244-
expect(expectedKeys).toContain(key);
245-
});
246+
routeKeys.forEach(function (key) {
247+
// check that all routes are expected
248+
expect(expectedKeys).toContain(key);
249+
});
246250

247-
expectedKeys.forEach(function (key) {
248-
// check that all expected routes are found
249-
expect(routeKeys).toContain(key);
250-
});
251+
expectedKeys.forEach(function (key) {
252+
// check that all expected routes are found
253+
expect(routeKeys).toContain(key);
254+
});
251255

252-
seen += 1;
253-
if (seen === tests.length) {
254-
done();
255-
} else {
256-
return doReq(seen);
257-
}
258-
});
256+
seen += 1;
257+
if (seen === tests.length) {
258+
done();
259+
} else {
260+
return doReq(seen);
261+
}
262+
});
259263
};
260264

261265
proxy

test/cli_spec.js

Lines changed: 52 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ describe("CLI Tests", function () {
9696
var redirectUrl = "http://127.0.0.1:" + redirectPort;
9797
var redirectToUrl = "https://127.0.0.1:" + redirectToPort;
9898

99-
10099
beforeEach(function (callback) {
101100
childProcess = null;
102101
addServer("default", testPort).then(callback);
@@ -118,14 +117,16 @@ describe("CLI Tests", function () {
118117
var args = ["--ip", "127.0.0.1", "--port", port, "--default-target", testUrl];
119118
executeCLI(execCmd, args).then((cliProcess) => {
120119
childProcess = cliProcess;
121-
fetch(proxyUrl).then((res) => res.json()).then((body) => {
122-
expect(body).toEqual(
123-
jasmine.objectContaining({
124-
name: "default",
125-
})
126-
);
127-
done();
128-
});
120+
fetch(proxyUrl)
121+
.then((res) => res.json())
122+
.then((body) => {
123+
expect(body).toEqual(
124+
jasmine.objectContaining({
125+
name: "default",
126+
})
127+
);
128+
done();
129+
});
129130
});
130131
});
131132

@@ -144,16 +145,19 @@ describe("CLI Tests", function () {
144145
];
145146
executeCLI(execCmd, args).then((cliProcess) => {
146147
childProcess = cliProcess;
147-
fetch(SSLproxyUrl).then((res) => res.json()).then((body) => {
148-
expect(body).toEqual(
149-
jasmine.objectContaining({
150-
name: "default",
151-
})
152-
);
153-
done();
154-
}).catch(err => {
155-
done.fail(err);
156-
});
148+
fetch(SSLproxyUrl)
149+
.then((res) => res.json())
150+
.then((body) => {
151+
expect(body).toEqual(
152+
jasmine.objectContaining({
153+
name: "default",
154+
})
155+
);
156+
done();
157+
})
158+
.catch((err) => {
159+
done.fail(err);
160+
});
157161
});
158162
});
159163

@@ -175,19 +179,20 @@ describe("CLI Tests", function () {
175179
];
176180
executeCLI(execCmd, args).then((cliProcess) => {
177181
childProcess = cliProcess;
178-
fetch(redirectUrl, { redirect: 'manual'})
179-
.then((res) => {
180-
expect(res.status).toEqual(301);
181-
expect(res.headers.get('location')).toContain(SSLproxyUrl);
182-
});
183-
fetch(redirectUrl, { redirect: 'follow' }).then(res => res.json()).then((body) => {
184-
expect(body).toEqual(
185-
jasmine.objectContaining({
186-
name: "default",
187-
})
188-
);
189-
done();
182+
fetch(redirectUrl, { redirect: "manual" }).then((res) => {
183+
expect(res.status).toEqual(301);
184+
expect(res.headers.get("location")).toContain(SSLproxyUrl);
190185
});
186+
fetch(redirectUrl, { redirect: "follow" })
187+
.then((res) => res.json())
188+
.then((body) => {
189+
expect(body).toEqual(
190+
jasmine.objectContaining({
191+
name: "default",
192+
})
193+
);
194+
done();
195+
});
191196
});
192197
});
193198

@@ -211,12 +216,11 @@ describe("CLI Tests", function () {
211216
];
212217
executeCLI(execCmd, args).then((cliProcess) => {
213218
childProcess = cliProcess;
214-
fetch(redirectUrl, { redirect: 'manual'})
215-
.then((res) => {
216-
expect(res.status).toEqual(301);
217-
expect(res.headers.get('location')).toContain(redirectToUrl);
218-
done();
219-
});
219+
fetch(redirectUrl, { redirect: "manual" }).then((res) => {
220+
expect(res.status).toEqual(301);
221+
expect(res.headers.get("location")).toContain(redirectToUrl);
222+
done();
223+
});
220224
});
221225
});
222226

@@ -239,15 +243,17 @@ describe("CLI Tests", function () {
239243
];
240244
executeCLI(execCmd, args).then((cliProcess) => {
241245
childProcess = cliProcess;
242-
fetch(SSLproxyUrl).then(res => res.json()).then((body) => {
243-
expect(body.headers).toEqual(
244-
jasmine.objectContaining({
245-
k1: "v1",
246-
k2: "host:123",
247-
})
248-
);
249-
done();
250-
});
246+
fetch(SSLproxyUrl)
247+
.then((res) => res.json())
248+
.then((body) => {
249+
expect(body.headers).toEqual(
250+
jasmine.objectContaining({
251+
k1: "v1",
252+
k2: "host:123",
253+
})
254+
);
255+
done();
256+
});
251257
});
252258
});
253259
it("invalid-custom-header", function (done) {

0 commit comments

Comments
 (0)