File: scaffold-utils.test.js

package info (click to toggle)
node-webpack 5.97.1%2Bdfsg1%2B~cs11.18.27-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 59,064 kB
  • sloc: javascript: 185,073; makefile: 16; sh: 6
file content (65 lines) | stat: -rwxr-xr-x 1,790 bytes parent folder | download | duplicates (2)
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
const {
  Confirm,
  List,
  Input,
  // eslint-disable-next-line node/no-missing-require
} = require("../../../packages/generators/src/utils/scaffold-utils");

describe("utils", () => {
  let mockSelf;

  beforeEach(() => {
    mockSelf = {
      prompt: (arg) => {
        return arg[0];
      },
    };
  });
  describe("Inquirer", () => {
    it("should emulate a prompt for List", () => {
      expect(List(mockSelf, "entry", "does it work?", ["Yes", "Maybe"], "Yes")).toEqual({
        choices: ["Yes", "Maybe"],
        type: "list",
        name: "entry",
        message: "does it work?",
        default: "Yes",
      });
    });

    it("should make default value for a List", () => {
      expect(List(mockSelf, "entry", "does it work?", ["Yes", "Maybe"], "Yes", true)).toEqual({
        entry: "Yes",
      });
    });

    it("should emulate a prompt for list input", () => {
      expect(Input(mockSelf, "plugins", "what is your plugin?", "openJSF")).toEqual({
        type: "input",
        name: "plugins",
        message: "what is your plugin?",
        default: "openJSF",
      });
    });

    it("should return a default Input object value", () => {
      expect(Input(mockSelf, "plugins", "what is your plugin?", "my-plugin", true)).toEqual({
        plugins: "my-plugin",
      });
    });

    it("should emulate a prompt for confirm", () => {
      expect(Confirm(mockSelf, "context", "what is your context?")).toEqual({
        name: "context",
        default: true,
        message: "what is your context?",
        type: "confirm",
      });
    });

    it("should make a Confirm object with yes as default", () => {
      expect(Confirm(mockSelf, "context", "what is your context?", true, true)).toEqual({
        context: true,
      });
    });
  });
});