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

75 строки
2.1 KiB

  1. import fs from "node:fs";
  2. import { resolve, dirname } from "node:path";
  3. import { waitFor } from "cli-testing-library";
  4. import { renderScript } from "./render.js";
  5. import { getFileHelper } from "./file-helper.js";
  6. const { getFilePath } = getFileHelper();
  7. import { fileURLToPath } from "node:url";
  8. const __dirname = dirname(fileURLToPath(import.meta.url));
  9. const renderWrapper = (...props) => {
  10. return renderScript(
  11. resolve(__dirname, "./examples/wrap-plop/index.js"),
  12. ...props
  13. );
  14. };
  15. test("wrapper should show version on v flag", async () => {
  16. const { findByText } = await renderWrapper(["-v"]);
  17. expect(await findByText(/^[\w\.-]+$/)).toBeInTheConsole();
  18. });
  19. test("wrapper should prompts", async () => {
  20. const { findByText, fireEvent } = await renderWrapper([""], {
  21. cwd: resolve(__dirname, "./examples/wrap-plop"),
  22. });
  23. expect(await findByText("What is your name?")).toBeInTheConsole();
  24. });
  25. test("wrapper should bypass prompts with index", async () => {
  26. const { findByText, queryByText, fireEvent } = await renderWrapper(
  27. ["Corbin"],
  28. {
  29. cwd: resolve(__dirname, "./examples/wrap-plop"),
  30. }
  31. );
  32. expect(await queryByText("What is your name?")).not.toBeInTheConsole();
  33. expect(
  34. await findByText("What pizza toppings do you like?")
  35. ).toBeInTheConsole();
  36. });
  37. test("wrapper should bypass prompts with name", async () => {
  38. const { findByText, queryByText, fireEvent } = await renderWrapper(
  39. ["--name", "Corbin"],
  40. {
  41. cwd: resolve(__dirname, "./examples/wrap-plop"),
  42. }
  43. );
  44. expect(await queryByText("What is your name?")).not.toBeInTheConsole();
  45. expect(
  46. await findByText("What pizza toppings do you like?")
  47. ).toBeInTheConsole();
  48. });
  49. test("can run actions (add)", async () => {
  50. const expectedFilePath = await getFilePath(
  51. "./examples/wrap-plop/output/added.txt"
  52. );
  53. const { fireEvent } = await renderWrapper(["Test", "Cheese"], {
  54. cwd: resolve(__dirname, "./examples/wrap-plop"),
  55. });
  56. await waitFor(() => fs.promises.stat(expectedFilePath));
  57. const data = fs.readFileSync(expectedFilePath, "utf8");
  58. expect(data).toMatch(/Hello/);
  59. });