Skip to content

Commit d5a95e8

Browse files
committed
fix: move things around
1 parent 8ece077 commit d5a95e8

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

test/unit/node/app.test.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@ describe("createApp", () => {
1111
let spy: jest.SpyInstance
1212
let unlinkSpy: jest.SpyInstance
1313
let port: number
14+
let tmpDirPath: string
15+
let tmpFilePath: string
16+
17+
beforeAll(async () => {
18+
tmpDirPath = await tmpdir("unlink-socket")
19+
tmpFilePath = path.join(tmpDirPath, "unlink-socket-file")
20+
})
1421

1522
beforeEach(async () => {
1623
spy = jest.spyOn(logger, "error")
@@ -30,6 +37,8 @@ describe("createApp", () => {
3037

3138
afterAll(() => {
3239
jest.restoreAllMocks()
40+
// Ensure directory was removed
41+
rmdirSync(tmpDirPath, { recursive: true })
3342
})
3443

3544
it("should return an Express app, a WebSockets Express app and an http server", async () => {
@@ -100,28 +109,20 @@ describe("createApp", () => {
100109
})
101110

102111
it("should unlink a socket before listening on the socket", async () => {
103-
const tmpDir = await tmpdir("unlink-socket")
104-
const tmpFile = path.join(tmpDir, "unlink-socket-file")
105-
await promises.writeFile(tmpFile, "")
106-
const socketPath = tmpFile
112+
await promises.writeFile(tmpFilePath, "")
107113
const defaultArgs = await setDefaults({
108114
_: [],
109-
socket: socketPath,
115+
socket: tmpFilePath,
110116
})
111117

112118
const app = await createApp(defaultArgs)
113119
const server = app[2]
114120

115121
expect(unlinkSpy).toHaveBeenCalledTimes(1)
116-
// Ensure directory was removed
117-
rmdirSync(socketPath, { recursive: true })
118122
server.close()
119123
})
120124
it("should catch errors thrown when unlinking a socket", async () => {
121-
const tmpDir = await tmpdir("unlink-socket")
122-
const tmpFile = path.join(tmpDir, "unlink-socket-file")
123-
// await promises.writeFile(tmpFile, "")
124-
const socketPath = tmpFile
125+
const socketPath = `${tmpFilePath}-doesnt-exist`
125126
const defaultArgs = await setDefaults({
126127
_: [],
127128
socket: socketPath,
@@ -132,8 +133,7 @@ describe("createApp", () => {
132133

133134
expect(spy).toHaveBeenCalledTimes(1)
134135
expect(spy).toHaveBeenCalledWith(`ENOENT: no such file or directory, unlink '${socketPath}'`)
135-
// Ensure directory was removed
136-
rmdirSync(socketPath, { recursive: true })
136+
137137
server.close()
138138
})
139139

0 commit comments

Comments
 (0)