Skip to content

Commit

Permalink
Improve add action tests
Browse files Browse the repository at this point in the history
  • Loading branch information
crutchcorn committed Nov 23, 2021
1 parent d4ff82c commit 4a14c4d
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 3 deletions.
31 changes: 29 additions & 2 deletions tests/actions.spec.js
Expand Up @@ -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,
});
Expand All @@ -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();
});
20 changes: 19 additions & 1 deletion 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: [
{
Expand All @@ -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",
},
],
});
};
1 change: 1 addition & 0 deletions tests/examples/add-action/templates/to-add-change.txt
@@ -0,0 +1 @@
Hi {{name}}!

0 comments on commit 4a14c4d

Please sign in to comment.