-
Notifications
You must be signed in to change notification settings - Fork 184
Expand file tree
/
Copy pathindex.test.ts
More file actions
71 lines (58 loc) · 1.55 KB
/
index.test.ts
File metadata and controls
71 lines (58 loc) · 1.55 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import tsw, { uninstallHacks } from "../index";
import { createServer, get as httpGet } from "http";
/**
* 4000 - 5000 random port
*/
const randomPort = (): number => Math.floor(Math.random() * 1000 + 4000);
let server;
let port;
const RESPONSE_STRING = "success";
beforeAll(() => {
uninstallHacks();
port = randomPort();
server = createServer((req, res) => {
// process.domain in git pipeline is undefined
expect(process.domain).toBeFalsy();
res.statusCode = 200;
res.end(RESPONSE_STRING);
}).listen(port);
});
afterAll(() => {
server.close();
uninstallHacks();
});
describe("tsw index", () => {
it("load normal plugin", async () => {
await tsw(
__dirname,
"./__fixtures__/normal-plugin/index.ts",
"./__fixtures__/normal-plugin/tswconfig.ts"
);
});
it("load no plugin", async () => {
await tsw(
__dirname,
"./__fixtures__/no-plugin/index.ts",
"./__fixtures__/no-plugin/tswconfig.ts"
);
});
it("load error plugin", async () => {
const mockExit = jest
.spyOn<any, any>(process, "exit")
.mockImplementationOnce(() => {});
await tsw(
__dirname,
"./__fixtures__/error-plugin/index.ts",
"./__fixtures__/error-plugin/tswconfig.ts"
);
expect(mockExit).toHaveBeenCalledWith(-1);
});
it("test uninstallHacks", async () => new Promise((resolve) => {
httpGet(`http://127.0.0.1:${port}`, (res) => {
res.on("data", (d) => {
expect(d.toString("utf8")).toBe(RESPONSE_STRING);
resolve(0);
});
}).end();
}));
});