-
Notifications
You must be signed in to change notification settings - Fork 272
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add test for CJS, MJS, and ESM support
- Loading branch information
1 parent
020286c
commit e52feef
Showing
12 changed files
with
211 additions
and
7 deletions.
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
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,50 @@ | ||
import { resolve, dirname } from "node:path"; | ||
import { renderPlop } from "./render.js"; | ||
|
||
import { fileURLToPath } from "node:url"; | ||
|
||
const __dirname = dirname(fileURLToPath(import.meta.url)); | ||
|
||
test("should load ESM file", async () => { | ||
const { findByText, fireEvent } = await renderPlop([], { | ||
cwd: resolve(__dirname, "./examples/esm"), | ||
}); | ||
expect(await findByText("What is your name?")).toBeTruthy(); | ||
fireEvent.type("Joe"); | ||
expect(await findByText("Joe")).toBeTruthy(); | ||
fireEvent.enter(); | ||
fireEvent.sigterm(); | ||
}); | ||
|
||
test("should load MJS file", async () => { | ||
const { findByText, fireEvent } = await renderPlop([], { | ||
cwd: resolve(__dirname, "./examples/mjs"), | ||
}); | ||
expect(await findByText("What is your name?")).toBeTruthy(); | ||
fireEvent.type("Joe"); | ||
expect(await findByText("Joe")).toBeTruthy(); | ||
fireEvent.enter(); | ||
fireEvent.sigterm(); | ||
}); | ||
|
||
test.only("should load CJS file", async () => { | ||
const { findByText, fireEvent } = await renderPlop([], { | ||
cwd: resolve(__dirname, "./examples/cjs"), | ||
}); | ||
expect(await findByText("What is your name?")).toBeTruthy(); | ||
fireEvent.type("Joe"); | ||
expect(await findByText("Joe")).toBeTruthy(); | ||
fireEvent.enter(); | ||
fireEvent.sigterm(); | ||
}); | ||
|
||
test("should load JS module='commonjs' file", async () => { | ||
const { findByText, fireEvent } = await renderPlop([], { | ||
cwd: resolve(__dirname, "./examples/cjs-js"), | ||
}); | ||
expect(await findByText("What is your name?")).toBeTruthy(); | ||
fireEvent.type("Joe"); | ||
expect(await findByText("Joe")).toBeTruthy(); | ||
fireEvent.enter(); | ||
fireEvent.sigterm(); | ||
}); |
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-prompts-only", | ||
"type": "commonjs", | ||
"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,30 @@ | ||
module.exports = function (plop) { | ||
plop.setGenerator("test", { | ||
description: "this is a test", | ||
prompts: [ | ||
{ | ||
type: "input", | ||
name: "name", | ||
message: "What is your name?", | ||
validate: function (value) { | ||
if (/.+/.test(value)) { | ||
return true; | ||
} | ||
return "name is required"; | ||
}, | ||
}, | ||
{ | ||
type: "checkbox", | ||
name: "toppings", | ||
message: "What pizza toppings do you like?", | ||
choices: [ | ||
{ name: "Cheese", value: "cheese", checked: true }, | ||
{ name: "Pepperoni", value: "pepperoni" }, | ||
{ name: "Pineapple", value: "pineapple" }, | ||
{ name: "Mushroom", value: "mushroom" }, | ||
{ name: "Bacon", value: "bacon", checked: true }, | ||
], | ||
}, | ||
], | ||
}); | ||
}; |
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-prompts-only", | ||
"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,30 @@ | ||
module.exports = function (plop) { | ||
plop.setGenerator("test", { | ||
description: "this is a test", | ||
prompts: [ | ||
{ | ||
type: "input", | ||
name: "name", | ||
message: "What is your name?", | ||
validate: function (value) { | ||
if (/.+/.test(value)) { | ||
return true; | ||
} | ||
return "name is required"; | ||
}, | ||
}, | ||
{ | ||
type: "checkbox", | ||
name: "toppings", | ||
message: "What pizza toppings do you like?", | ||
choices: [ | ||
{ name: "Cheese", value: "cheese", checked: true }, | ||
{ name: "Pepperoni", value: "pepperoni" }, | ||
{ name: "Pineapple", value: "pineapple" }, | ||
{ name: "Mushroom", value: "mushroom" }, | ||
{ name: "Bacon", value: "bacon", checked: true }, | ||
], | ||
}, | ||
], | ||
}); | ||
} |
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-prompts-only", | ||
"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,30 @@ | ||
export default function (plop) { | ||
plop.setGenerator("test", { | ||
description: "this is a test", | ||
prompts: [ | ||
{ | ||
type: "input", | ||
name: "name", | ||
message: "What is your name?", | ||
validate: function (value) { | ||
if (/.+/.test(value)) { | ||
return true; | ||
} | ||
return "name is required"; | ||
}, | ||
}, | ||
{ | ||
type: "checkbox", | ||
name: "toppings", | ||
message: "What pizza toppings do you like?", | ||
choices: [ | ||
{ name: "Cheese", value: "cheese", checked: true }, | ||
{ name: "Pepperoni", value: "pepperoni" }, | ||
{ name: "Pineapple", value: "pineapple" }, | ||
{ name: "Mushroom", value: "mushroom" }, | ||
{ name: "Bacon", value: "bacon", checked: true }, | ||
], | ||
}, | ||
], | ||
}); | ||
} |
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-prompts-only", | ||
"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,30 @@ | ||
export default function (plop) { | ||
plop.setGenerator("test", { | ||
description: "this is a test", | ||
prompts: [ | ||
{ | ||
type: "input", | ||
name: "name", | ||
message: "What is your name?", | ||
validate: function (value) { | ||
if (/.+/.test(value)) { | ||
return true; | ||
} | ||
return "name is required"; | ||
}, | ||
}, | ||
{ | ||
type: "checkbox", | ||
name: "toppings", | ||
message: "What pizza toppings do you like?", | ||
choices: [ | ||
{ name: "Cheese", value: "cheese", checked: true }, | ||
{ name: "Pepperoni", value: "pepperoni" }, | ||
{ name: "Pineapple", value: "pineapple" }, | ||
{ name: "Mushroom", value: "mushroom" }, | ||
{ name: "Bacon", value: "bacon", checked: true }, | ||
], | ||
}, | ||
], | ||
}); | ||
} |
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 |
---|---|---|
@@ -1,12 +1,12 @@ | ||
module.exports = function (wallaby) { | ||
return { | ||
files: ["bin/**/*.js", "src/**/*.js", "!tests/**/*.ava.js"], | ||
tests: ["tests/**/*.ava.js"], | ||
files: ["bin/**/*.js", "src/**/*.js", "!tests/**/*.spec.js"], | ||
tests: ["tests/**/*.spec.js"], | ||
env: { | ||
type: "node", | ||
runner: "node", | ||
}, | ||
testFramework: "ava", | ||
testFramework: "jest", | ||
debug: true, | ||
}; | ||
}; |