-
-
Notifications
You must be signed in to change notification settings - Fork 794
/
accessHost.test.js
52 lines (51 loc) · 1.36 KB
/
accessHost.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import assert from "node:assert"
import { env } from "node:process"
import { Server } from "@hapi/hapi"
import { join } from "desm"
import { setup, teardown } from "../../../_testHelpers/index.js"
import installNpmModules from "../../../installNpmModules.js"
import { BASE_URL } from "../../../config.js"
describe("Access host with Docker tests", function desc() {
let server
beforeEach(async () => {
await installNpmModules(join(import.meta.url, "src"))
})
beforeEach(async () => {
server = new Server({ port: 8080 })
server.route({
handler() {
return "Hello Node.js!"
},
method: "GET",
path: "/hello",
})
await server.start()
await setup({
servicePath: join(import.meta.url),
})
})
afterEach(async () => {
await server.stop()
await teardown()
})
;[
{
description: "should access host in docker container",
expected: {
message: "Hello Node.js!",
},
path: "/dev/hello",
},
].forEach(({ description, expected, path }) => {
it(description, async function it() {
// "Could not find 'Docker', skipping tests."
if (!env.DOCKER_DETECTED) {
this.skip()
}
const url = new URL(path, BASE_URL)
const response = await fetch(url)
const json = await response.json()
assert.deepEqual(json, expected)
})
})
})