版博士V2.0程序
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 

167 строки
5.3 KiB

  1. import { resolve, dirname } from "node:path";
  2. import { renderPlop } from "./render.js";
  3. import { fileURLToPath } from "node:url";
  4. const __dirname = dirname(fileURLToPath(import.meta.url));
  5. test("should report a missing plopfile when not copied", async () => {
  6. // The directory above this repo. We look up towards `plopfile.js` and found one at root otherwise.
  7. const cwd = resolve(__dirname, "../../../..");
  8. const { findByError } = await renderPlop([], { cwd });
  9. expect(await findByError(/\[PLOP\] No plopfile found/)).toBeInTheConsole();
  10. });
  11. test("should show help information on help flag", async () => {
  12. const { findByText } = await renderPlop(["--help"]);
  13. const { stdoutArr } = await findByText("Usage:");
  14. expect(stdoutArr.join("\n")).toMatchSnapshot();
  15. });
  16. test("should show version on version flag", async () => {
  17. const { findByText } = await renderPlop(["--version"]);
  18. expect(await findByText(/^[\w\.-]+$/)).toBeInTheConsole();
  19. });
  20. test("should show version on v flag", async () => {
  21. const { findByText } = await renderPlop(["-v"]);
  22. expect(await findByText(/^[\w\.-]+$/)).toBeInTheConsole();
  23. });
  24. test("should display inquirer prompts", async () => {
  25. const { findByText, userEvent } = await renderPlop([], {
  26. cwd: resolve(__dirname, "./examples/prompt-only"),
  27. });
  28. expect(await findByText("What is your name?")).toBeInTheConsole();
  29. userEvent.keyboard("Joe");
  30. expect(await findByText("Joe")).toBeInTheConsole();
  31. userEvent.keyboard("[Enter]");
  32. });
  33. test("Should handle generator prompt", async () => {
  34. const { findByText, clear, userEvent } = await renderPlop([""], {
  35. cwd: resolve(__dirname, "./examples/javascript"),
  36. });
  37. await findByText("Please choose a generator");
  38. clear();
  39. userEvent.keyboard("[ArrowUp]");
  40. userEvent.keyboard("[ArrowDown]");
  41. userEvent.keyboard("[Enter]");
  42. expect(await findByText("this is a test")).toBeInTheConsole();
  43. });
  44. test("Should bypass generator prompt", async () => {
  45. const { findByText } = await renderPlop(["test"], {
  46. cwd: resolve(__dirname, "./examples/javascript"),
  47. });
  48. expect(await findByText("What is your name?")).toBeInTheConsole();
  49. });
  50. test("Should bypass input prompt with input", async () => {
  51. const { queryByText, findByText } = await renderPlop(["Frank"], {
  52. cwd: resolve(__dirname, "./examples/prompt-only"),
  53. });
  54. expect(await queryByText("What is your name?")).not.toBeInTheConsole();
  55. expect(
  56. await findByText("What pizza toppings do you like?")
  57. ).toBeInTheConsole();
  58. });
  59. test("Should bypass input prompt with placeholder", async () => {
  60. const { queryByText, findByText, userEvent } = await renderPlop(
  61. ["_", "Cheese"],
  62. {
  63. cwd: resolve(__dirname, "./examples/prompt-only"),
  64. }
  65. );
  66. expect(await findByText("What is your name?")).toBeInTheConsole();
  67. userEvent.keyboard("[Enter]");
  68. expect(
  69. await queryByText("What pizza toppings do you like?")
  70. ).not.toBeInTheConsole();
  71. });
  72. test("Should bypass input prompt with name", async () => {
  73. const { queryByText, findByText } = await renderPlop(
  74. ["--", "--name", "Frank"],
  75. {
  76. cwd: resolve(__dirname, "./examples/prompt-only"),
  77. }
  78. );
  79. expect(await queryByText("What is your name?")).not.toBeInTheConsole();
  80. expect(
  81. await findByText("What pizza toppings do you like?")
  82. ).toBeInTheConsole();
  83. });
  84. test("Should bypass input prompt with empty string", async () => {
  85. const { queryByText, findByText } = await renderPlop(["--", "--name", `""`], {
  86. cwd: resolve(__dirname, "./examples/prompt-only"),
  87. });
  88. expect(await queryByText("What is your name?")).not.toBeInTheConsole();
  89. expect(
  90. await findByText("What pizza toppings do you like?")
  91. ).toBeInTheConsole();
  92. });
  93. test("Should bypass checkbox prompt with input", async () => {
  94. const { queryByText } = await renderPlop(["Frank", "Cheese"], {
  95. cwd: resolve(__dirname, "./examples/prompt-only"),
  96. });
  97. expect(await queryByText("What is your name?")).not.toBeInTheConsole();
  98. expect(
  99. await queryByText("What pizza toppings do you like?")
  100. ).not.toBeInTheConsole();
  101. });
  102. test("Should bypass checkbox prompt with placeholder", async () => {
  103. const { queryByText, findByText } = await renderPlop(["Frank", "_"], {
  104. cwd: resolve(__dirname, "./examples/prompt-only"),
  105. });
  106. expect(await queryByText("What is your name?")).not.toBeInTheConsole();
  107. expect(
  108. await findByText("What pizza toppings do you like?")
  109. ).toBeInTheConsole();
  110. });
  111. test("Should bypass checkbox prompt with name", async () => {
  112. const { queryByText, findByText, userEvent } = await renderPlop(
  113. ["--", "--toppings", "Cheese"],
  114. {
  115. cwd: resolve(__dirname, "./examples/prompt-only"),
  116. }
  117. );
  118. expect(await findByText("What is your name?")).toBeInTheConsole();
  119. userEvent.keyboard("[Enter]");
  120. expect(
  121. await queryByText("What pizza toppings do you like?")
  122. ).not.toBeInTheConsole();
  123. });
  124. test("Should bypass checkbox prompt with empty string", async () => {
  125. const { queryByText, findByText, userEvent } = await renderPlop(
  126. ["--", "--toppings", `""`],
  127. {
  128. cwd: resolve(__dirname, "./examples/prompt-only"),
  129. }
  130. );
  131. expect(await findByText("What is your name?")).toBeInTheConsole();
  132. userEvent.keyboard("[Enter]");
  133. expect(
  134. await queryByText("What pizza toppings do you like?")
  135. ).not.toBeInTheConsole();
  136. });
  137. test.todo("Dynamic actions");