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

57 строки
1.6 KiB

  1. import { resolve, dirname } from "node:path";
  2. import { waitFor } from "cli-testing-library";
  3. import * as fs from "node:fs";
  4. import { renderPlop } 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. test("Plop to add and rename files", async () => {
  10. const expectedFilePath = await getFilePath(
  11. "./examples/add-action/output/new-output.txt"
  12. );
  13. const { findByText, userEvent } = await renderPlop(["addAndNameFile"], {
  14. cwd: resolve(__dirname, "./examples/add-action"),
  15. });
  16. expect(await findByText("What should the file name be?")).toBeInTheConsole();
  17. userEvent.keyboard("new-output");
  18. userEvent.keyboard("[Enter]");
  19. await waitFor(() => fs.promises.stat(expectedFilePath));
  20. const data = fs.readFileSync(expectedFilePath, "utf8");
  21. expect(data).toMatch(/Hello/);
  22. });
  23. test("Plop to add and change file contents", async () => {
  24. const expectedFilePath = await getFilePath(
  25. "./examples/add-action/output/new-output.txt"
  26. );
  27. const { findByText, userEvent } = await renderPlop(["addAndChangeFile"], {
  28. cwd: resolve(__dirname, "./examples/add-action"),
  29. });
  30. expect(await findByText("What's your name?")).toBeInTheConsole();
  31. userEvent.keyboard("Corbin");
  32. userEvent.keyboard("[Enter]");
  33. await waitFor(() => fs.promises.stat(expectedFilePath));
  34. const data = await fs.promises.readFile(expectedFilePath, "utf8");
  35. expect(data).toMatch(/Hi Corbin!/);
  36. });
  37. test.todo("Test modify");
  38. test.todo("Test append");
  39. test.todo("Test built-in helpers");
  40. test.todo("Test custom helpers");