Skip to content

Commit 5dea3ee

Browse files
committed
Add static route tests
1 parent 928780d commit 5dea3ee

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

test/unit/routes/static.test.ts

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { promises as fs } from "fs"
2+
import * as path from "path"
3+
import { tmpdir } from "../../utils/helpers"
4+
import * as httpserver from "../../utils/httpserver"
5+
import * as integration from "../../utils/integration"
6+
7+
describe("static", () => {
8+
let codeServer: httpserver.HttpServer | undefined
9+
let testFile: string | undefined
10+
let testFileContent: string | undefined
11+
12+
beforeAll(async () => {
13+
const testDir = await tmpdir("static")
14+
testFile = path.join(testDir, "test")
15+
testFileContent = "static file contents"
16+
await fs.writeFile(testFile, testFileContent)
17+
})
18+
19+
afterEach(async () => {
20+
if (codeServer) {
21+
await codeServer.close()
22+
codeServer = undefined
23+
}
24+
})
25+
26+
it("/static unauthed", async () => {
27+
codeServer = await integration.setup(["--auth=none"], "")
28+
let resp = await codeServer.fetch("/static")
29+
expect(resp.status).toBe(404)
30+
31+
resp = await codeServer.fetch(`/static/-${testFile}`)
32+
expect(resp.status).toBe(200)
33+
34+
const content = await resp.text()
35+
expect(content).toStrictEqual(testFileContent)
36+
})
37+
38+
it("/static authed", async () => {
39+
process.env.PASSWORD = "test"
40+
codeServer = await integration.setup(["--auth=password"], "")
41+
let resp = await codeServer.fetch("/static")
42+
expect(resp.status).toBe(404)
43+
44+
resp = await codeServer.fetch(`/static/-${testFile}`)
45+
expect(resp.status).toBe(401)
46+
})
47+
})

0 commit comments

Comments
 (0)