Skip to content

Commit e2878ca

Browse files
committed
fixup
1 parent 3a4d303 commit e2878ca

File tree

1 file changed

+3
-11
lines changed

1 file changed

+3
-11
lines changed

test/unit/node/app.test.ts

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ import { getAvailablePort, tmpdir } from "../../utils/helpers"
1010
describe("createApp", () => {
1111
let spy: jest.SpyInstance
1212
let unlinkSpy: jest.SpyInstance
13+
let port: number
1314

14-
beforeEach(() => {
15+
beforeEach(async () => {
1516
spy = jest.spyOn(logger, "error")
1617
// NOTE:@jsjoeio
1718
// Be mindful when spying.
@@ -20,6 +21,7 @@ describe("createApp", () => {
2021
// then you can spy on those modules methods, like unlink.
2122
// See: https://github.com/aelbore/esbuild-jest/issues/26#issuecomment-893763840
2223
unlinkSpy = jest.spyOn(promises, "unlink")
24+
port = await getAvailablePort()
2325
})
2426

2527
afterEach(() => {
@@ -30,9 +32,7 @@ describe("createApp", () => {
3032
jest.restoreAllMocks()
3133
})
3234

33-
// TODO@jsjoeio refactor to use beforeEach and afterEach
3435
it("should return an Express app, a WebSockets Express app and an http server", async () => {
35-
const port = await getAvailablePort()
3636
const defaultArgs = await setDefaults({
3737
port,
3838
_: [],
@@ -50,7 +50,6 @@ describe("createApp", () => {
5050
})
5151

5252
it("should handle error events on the server", async () => {
53-
const port = await getAvailablePort()
5453
const defaultArgs = await setDefaults({
5554
port,
5655
_: [],
@@ -82,11 +81,6 @@ describe("createApp", () => {
8281
_: [],
8382
})
8483

85-
// This looks funky, but that's because createApp
86-
// returns an array like [app, wsApp, server]
87-
// We only need server which is at index 2
88-
// we do it this way so ESLint is happy that we're
89-
// have no declared variables not being used
9084
async function masterBall() {
9185
const app = await createApp(defaultArgs)
9286
const server = app[2]
@@ -144,8 +138,6 @@ describe("createApp", () => {
144138
})
145139

146140
it("should create an https server if args.cert exists", async () => {
147-
// No idea why we have this weird optional string thing
148-
const port = await getAvailablePort()
149141
const cert = new OptionalString("./test/utils/test.crt")
150142
const defaultArgs = await setDefaults({
151143
port,

0 commit comments

Comments
 (0)