diff --git a/tests/actions.spec.js b/tests/actions.spec.js index 91209c0f..72cc62aa 100644 --- a/tests/actions.spec.js +++ b/tests/actions.spec.js @@ -3,8 +3,8 @@ const { resolve } = require("path"); const { waitFor } = require("cli-testing-library"); const fs = require("fs"); -test("Plop to add files", async () => { - const { findByText, fireEvent } = await renderPlop([""], { +test("Plop to add and rename files", async () => { + const { findByText, fireEvent } = await renderPlop(["addAndNameFile"], { cwd: resolve(__dirname, "./examples/add-action"), debug: true, }); @@ -29,3 +29,30 @@ test("Plop to add files", async () => { fireEvent.sigterm(); }); + +test("Plop to add and change file contents", async () => { + const { findByText, fireEvent } = await renderPlop(["addAndChangeFile"], { + cwd: resolve(__dirname, "./examples/add-action"), + debug: true, + }); + + expect(await findByText("What's your name?")).toBeTruthy(); + + fireEvent.type("Corbin"); + fireEvent.enter(); + + const expectedFilePath = resolve( + __dirname, + "./examples/add-action/output/to-add-change.txt" + ); + + await waitFor(() => fs.promises.stat(expectedFilePath)); + + const data = fs.readFileSync(expectedFilePath, "utf8"); + + expect(data).toMatch(/Hi Corbin!/); + + fs.unlinkSync(expectedFilePath); + + fireEvent.sigterm(); +}); diff --git a/tests/examples/add-action/plopfile.js b/tests/examples/add-action/plopfile.js index c7e5a401..fda6c939 100644 --- a/tests/examples/add-action/plopfile.js +++ b/tests/examples/add-action/plopfile.js @@ -1,5 +1,5 @@ module.exports = function (plop) { - plop.setGenerator("addAndNameFIle", { + plop.setGenerator("addAndNameFile", { description: "Name that file", prompts: [ { @@ -16,4 +16,22 @@ module.exports = function (plop) { }, ], }); + + plop.setGenerator("addAndChangeFile", { + description: "Name that file", + prompts: [ + { + type: "input", + name: "name", + message: "What's your name?", + }, + ], + actions: [ + { + type: "add", + path: "./output/to-add-change.txt", + templateFile: "./templates/to-add-change.txt", + }, + ], + }); }; diff --git a/tests/examples/add-action/templates/to-add-change.txt b/tests/examples/add-action/templates/to-add-change.txt new file mode 100644 index 00000000..e197fad2 --- /dev/null +++ b/tests/examples/add-action/templates/to-add-change.txt @@ -0,0 +1 @@ +Hi {{name}}!