-
Notifications
You must be signed in to change notification settings - Fork 274
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #300 from Pike/error-on-failure
Return error code on failures on actions
- Loading branch information
Showing
4 changed files
with
52 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { resolve, dirname } from "node:path"; | ||
import { waitFor } from "cli-testing-library"; | ||
import { renderPlop } from "./render.js"; | ||
|
||
import { fileURLToPath } from "node:url"; | ||
|
||
const __dirname = dirname(fileURLToPath(import.meta.url)); | ||
|
||
test("should exit with code 1 when failed actions", async () => { | ||
const result = await renderPlop([], { | ||
cwd: resolve(__dirname, "./examples/action-failure"), | ||
}); | ||
const { findByText, userEvent } = result; | ||
expect(await findByText("What is your name?")).toBeTruthy(); | ||
userEvent.keyboard("Joe"); | ||
expect(await findByText("Joe")).toBeTruthy(); | ||
userEvent.keyboard("[Enter]"); | ||
const actionOutput = await findByText("Action failed"); | ||
await waitFor(() => | ||
expect(actionOutput.hasExit()).toStrictEqual({ exitCode: 1 }) | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"name": "plop-example-action-failure", | ||
"type": "module", | ||
"engines": { | ||
"node": "^12.20.0 || ^14.13.1 || >=16.0.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
export default function (plop) { | ||
plop.setGenerator("test", { | ||
description: "this is a test", | ||
prompts: [ | ||
{ | ||
type: "input", | ||
name: "name", | ||
message: "What is your name?", | ||
}, | ||
], | ||
actions: [ | ||
() => { | ||
throw new Error("Action failed"); | ||
}, | ||
], | ||
}); | ||
} |