Skip to content

Commit 762f3f5

Browse files
committed
chore: add internal plop generation for tests
1 parent 7a8b0a7 commit 762f3f5

File tree

7 files changed

+71
-29
lines changed

7 files changed

+71
-29
lines changed

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@
55
"workspaces": [
66
"packages/*"
77
],
8+
"type": "module",
89
"scripts": {
910
"bootstrap": "lerna exec yarn install",
1011
"build": "lerna run build",
1112
"test": "lerna run --parallel test",
1213
"format": "eslint -c .eslintrc.cjs --fix ./",
13-
"prepare": "husky install"
14+
"prepare": "husky install",
15+
"plop": "node ./packages/plop/bin/plop.js"
1416
},
1517
"bugs": {
1618
"url": "https://github.com/plopjs/plop/issues"

packages/node-plop/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
"@types/inquirer-autocomplete-prompt": "^1.3.3",
3838
"@types/node": "^16.11.10",
3939
"dtslint": "^4.2.1",
40-
"plop": "^3.0.5",
4140
"plop-pack-fancy-comments": "^0.2.1",
4241
"typescript": "^4.5.2",
4342
"vitest": "^0.5.5"

packages/node-plop/plopfile.js

Lines changed: 0 additions & 26 deletions
This file was deleted.

packages/plop/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"interpret": "^2.2.0",
4444
"liftoff": "^4.0.0",
4545
"minimist": "^1.2.5",
46-
"node-plop": "^0.30.0",
46+
"node-plop": "*",
4747
"ora": "^6.0.1",
4848
"v8flags": "^4.0.0"
4949
},

plop-templates/plop-test.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { resolve, dirname } from "node:path";
2+
import { renderPlop } from "./render.js";
3+
4+
import { fileURLToPath } from "node:url";
5+
6+
const __dirname = dirname(fileURLToPath(import.meta.url));
7+
8+
test("should load ESM file", async () => {
9+
const { findByText, userEvent } = await renderPlop([], {
10+
cwd: resolve(__dirname, "./examples/esm"),
11+
});
12+
expect(await findByText("What is your name?")).toBeInTheConsole();
13+
userEvent.keyboard("Joe");
14+
expect(await findByText("Joe")).toBeInTheConsole();
15+
userEvent.keyboard("[Enter]");
16+
});

plopfile.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
export default function (plop) {
2+
plop.setGenerator("node-plop-test", {
3+
prompts: [
4+
{
5+
type: "input",
6+
name: "name",
7+
message: function () {
8+
return "test name";
9+
},
10+
validate: function (value) {
11+
if (/.+/.test(value)) {
12+
return true;
13+
}
14+
return "test name is required";
15+
},
16+
},
17+
],
18+
actions: [
19+
{
20+
type: "add",
21+
path: "packages/node-plop/tests/{{dashCase name}}/{{dashCase name}}.spec.js",
22+
templateFile: "plop-templates/node-plop-test.js",
23+
},
24+
],
25+
});
26+
27+
plop.setGenerator("plop-test", {
28+
prompts: [
29+
{
30+
type: "input",
31+
name: "name",
32+
message: function () {
33+
return "test name";
34+
},
35+
validate: function (value) {
36+
if (/.+/.test(value)) {
37+
return true;
38+
}
39+
return "test name is required";
40+
},
41+
},
42+
],
43+
actions: [
44+
{
45+
type: "add",
46+
path: "packages/plop/tests/{{dashCase name}}.spec.js",
47+
templateFile: "plop-templates/plop-test.js",
48+
},
49+
],
50+
});
51+
}

0 commit comments

Comments
 (0)