mirror of https://github.com/probot/probot.git
reduce use of getPort
This commit is contained in:
parent
3e26598eb7
commit
45dd482786
|
@ -163,17 +163,17 @@ export class Server {
|
|||
|
||||
this.state.httpServer = await new Promise((resolve, reject) => {
|
||||
const server = this.state.httpServer!.listen(port, host, async () => {
|
||||
this.state.port = (server.address() as AddressInfo).port;
|
||||
|
||||
if (webhookProxy) {
|
||||
this.state.eventSource = await createWebhookProxy({
|
||||
logger: this.log,
|
||||
path: webhookPath,
|
||||
port: port,
|
||||
port: this.port,
|
||||
url: webhookProxy,
|
||||
});
|
||||
}
|
||||
const { port: serverPort } = server.address() as AddressInfo;
|
||||
this.state.port = serverPort;
|
||||
this.log.info(`Listening on http://${printableHost}:${serverPort}`);
|
||||
this.log.info(`Listening on http://${printableHost}:${this.port}`);
|
||||
resolve(server);
|
||||
});
|
||||
|
||||
|
|
|
@ -6,7 +6,6 @@ import { beforeEach, afterEach, describe, expect, it, vi } from "vitest";
|
|||
|
||||
import { Probot, Server } from "../../src/index.js";
|
||||
import { setupAppFactory } from "../../src/apps/setup.js";
|
||||
import getPort from "get-port";
|
||||
|
||||
const mocks = vi.hoisted(() => {
|
||||
return {
|
||||
|
@ -23,9 +22,9 @@ vi.mock("update-dotenv", () => ({
|
|||
}));
|
||||
|
||||
describe("Setup app", async () => {
|
||||
const port = await getPort();
|
||||
let server: Server;
|
||||
let logOutput: any[] = [];
|
||||
let port = 0;
|
||||
|
||||
const streamLogsToOutput = new Stream.Writable({ objectMode: true });
|
||||
streamLogsToOutput._write = (msg, _encoding, done) => {
|
||||
|
@ -43,12 +42,14 @@ describe("Setup app", async () => {
|
|||
privateKey: "dummy value for setup, see #1512",
|
||||
}),
|
||||
log: pino(streamLogsToOutput),
|
||||
port,
|
||||
port: 0,
|
||||
});
|
||||
|
||||
await server.loadHandler(setupAppFactory(undefined, port));
|
||||
|
||||
await server.start();
|
||||
|
||||
port = server.port!;
|
||||
|
||||
await server.loadHandler(setupAppFactory(undefined, port));
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
|
@ -111,8 +112,6 @@ describe("Setup app", async () => {
|
|||
|
||||
describe("GET /probot/setup", () => {
|
||||
it("returns a redirect", async () => {
|
||||
const port = await getPort();
|
||||
|
||||
const mock = fetchMock
|
||||
.createInstance()
|
||||
.postOnce("https://api.github.com/app-manifests/123/conversions", {
|
||||
|
@ -139,15 +138,15 @@ describe("Setup app", async () => {
|
|||
fetch: mock.fetchHandler,
|
||||
},
|
||||
host: "localhost",
|
||||
port,
|
||||
port: 0,
|
||||
});
|
||||
|
||||
await server.loadHandler(setupAppFactory("localhost", port));
|
||||
await server.loadHandler(setupAppFactory("localhost", server.port));
|
||||
|
||||
await server.start();
|
||||
|
||||
const setupResponse = await fetch(
|
||||
`http://localhost:${port}/probot/setup?code=123`,
|
||||
`http://localhost:${server.port}/probot/setup?code=123`,
|
||||
{ redirect: "manual" },
|
||||
);
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
import { Writable } from "node:stream";
|
||||
import { ManifestCreation } from "../../src/manifest-creation.js";
|
||||
import { describe, test, expect, afterEach } from "vitest";
|
||||
import getPort from "get-port";
|
||||
import { ApplicationFunction, Probot, Server } from "../../src/index.js";
|
||||
import { pino } from "pino";
|
||||
import WebhookExamples, {
|
||||
|
@ -101,8 +100,6 @@ describe("smee-client", () => {
|
|||
});
|
||||
};
|
||||
|
||||
const port = await getPort();
|
||||
|
||||
const server = new Server({
|
||||
Probot: Probot.defaults({
|
||||
appId: APP_ID,
|
||||
|
@ -110,7 +107,7 @@ describe("smee-client", () => {
|
|||
secret: WEBHOOK_SECRET,
|
||||
}),
|
||||
log: pino(streamLogsToOutput),
|
||||
port,
|
||||
port: 0,
|
||||
webhookProxy: WEBHOOK_PROXY_URL,
|
||||
webhookPath: "/",
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue