-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathindex.test.ts
More file actions
30 lines (24 loc) · 819 Bytes
/
index.test.ts
File metadata and controls
30 lines (24 loc) · 819 Bytes
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
import test from "ava"
import { strict as esmock } from "esmock"
import { fileURLToPath } from "url"
import type * as indexType from "../index.js"
const expectedHostname = "my-machine"
test("using absolute path", async t => {
const urlFull = fileURLToPath(new URL("../index.js", import.meta.url))
const indexModule = await esmock(urlFull, {
os: {
hostname: () => expectedHostname
}
})
const getHostname: typeof indexType.getHostname = indexModule.getHostname
t.is(getHostname(), expectedHostname)
})
test("using relative path", async t => {
const indexModule = await esmock("../index.js", import.meta.url, {
os: {
hostname: () => expectedHostname
}
})
const getHostname: typeof indexType.getHostname = indexModule.getHostname
t.is(getHostname(), expectedHostname)
})