@@ -10,8 +10,9 @@ import { getAvailablePort, tmpdir } from "../../utils/helpers"
10
10
describe ( "createApp" , ( ) => {
11
11
let spy : jest . SpyInstance
12
12
let unlinkSpy : jest . SpyInstance
13
+ let port : number
13
14
14
- beforeEach ( ( ) => {
15
+ beforeEach ( async ( ) => {
15
16
spy = jest . spyOn ( logger , "error" )
16
17
// NOTE:@jsjoeio
17
18
// Be mindful when spying.
@@ -20,6 +21,7 @@ describe("createApp", () => {
20
21
// then you can spy on those modules methods, like unlink.
21
22
// See: https://github.com/aelbore/esbuild-jest/issues/26#issuecomment-893763840
22
23
unlinkSpy = jest . spyOn ( promises , "unlink" )
24
+ port = await getAvailablePort ( )
23
25
} )
24
26
25
27
afterEach ( ( ) => {
@@ -30,9 +32,7 @@ describe("createApp", () => {
30
32
jest . restoreAllMocks ( )
31
33
} )
32
34
33
- // TODO@jsjoeio refactor to use beforeEach and afterEach
34
35
it ( "should return an Express app, a WebSockets Express app and an http server" , async ( ) => {
35
- const port = await getAvailablePort ( )
36
36
const defaultArgs = await setDefaults ( {
37
37
port,
38
38
_ : [ ] ,
@@ -50,7 +50,6 @@ describe("createApp", () => {
50
50
} )
51
51
52
52
it ( "should handle error events on the server" , async ( ) => {
53
- const port = await getAvailablePort ( )
54
53
const defaultArgs = await setDefaults ( {
55
54
port,
56
55
_ : [ ] ,
@@ -82,11 +81,6 @@ describe("createApp", () => {
82
81
_ : [ ] ,
83
82
} )
84
83
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
90
84
async function masterBall ( ) {
91
85
const app = await createApp ( defaultArgs )
92
86
const server = app [ 2 ]
@@ -144,8 +138,6 @@ describe("createApp", () => {
144
138
} )
145
139
146
140
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 ( )
149
141
const cert = new OptionalString ( "./test/utils/test.crt" )
150
142
const defaultArgs = await setDefaults ( {
151
143
port,
0 commit comments