UNPKG

2.42 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const index_1 = require("./index");
4jest.setTimeout(30000);
5describe("puppet basic run", () => {
6 it("downloads and runs URL", async () => {
7 const result = await index_1.puppet("https://pastebin.com/raw/AeY1MAwF");
8 expect(result).toBeTruthy();
9 });
10 it("runs array of commands", async () => {
11 const result = await index_1.puppet(["go to example.com", "go to example.org"]);
12 expect(result).toBeTruthy();
13 });
14 it("runs a file path", async () => {
15 const result = await index_1.puppet("src/examples/go-to.txt");
16 expect(result).toBeTruthy();
17 });
18 it("throws if no commands", async () => {
19 expect(index_1.puppet()).rejects.toEqual(new Error("Argument must be a string or an array of strings"));
20 });
21});
22describe("cleans commands", () => {
23 it("trims commands", async () => {
24 const result = await index_1.puppet([
25 "go to example.com ",
26 " go to example.org",
27 ]);
28 expect(result.commands).toEqual(["go to example.com", "go to example.org"]);
29 });
30 it("removes empty commands", async () => {
31 const result = await index_1.puppet(["go to example.com", "go to example.org", ""]);
32 expect(result.commands).toEqual(["go to example.com", "go to example.org"]);
33 });
34 it("lowercases commands", async () => {
35 const result = await index_1.puppet(["Go to www.example.com"]);
36 expect(result.commands).toEqual(["go to www.example.com"]);
37 });
38});
39describe("puppet commands", () => {
40 it("throws if invalid commands", async () => {
41 expect(index_1.puppet(["Unknown command"])).rejects.toEqual(new Error("Command not understood: unknown command"));
42 });
43 it("waits for a specific time", async () => {
44 const time = new Date().getTime();
45 await index_1.puppet(["wait for 1 second"]);
46 expect(new Date().getTime() - time).toBeGreaterThan(1000);
47 });
48 it("go to a URL", async () => {
49 const result = await index_1.puppet(["go to example.com"]);
50 expect(result.url).toBe("http://example.com/");
51 });
52 it("go to a full URL", async () => {
53 const result = await index_1.puppet(["go to https://example.com"]);
54 expect(result.url).toBe("https://example.com/");
55 });
56});
57//# sourceMappingURL=index.spec.js.map
\No newline at end of file