Skip to content

Commit 702c5f2

Browse files
test: more
1 parent b840918 commit 702c5f2

2 files changed

Lines changed: 54 additions & 6 deletions

File tree

test/create-webpack-app/loader/loader.test.js

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,13 +163,35 @@ describe("loader command", () => {
163163

164164
it("should prompt on supplying an invalid template", async () => {
165165
const assetsPath = await uniqueDirectoryForTest();
166-
const { stderr } = await runPromptWithAnswers(assetsPath, [
167-
"loader",
168-
".",
169-
"--template=unknown",
170-
]);
166+
const { defaultLoaderPath, defaultTemplateFiles } = dataForTests(assetsPath);
167+
let { stdout, stderr } = await runPromptWithAnswers(
168+
assetsPath,
169+
["loader", ".", "--template=unknown"],
170+
[ENTER, ENTER, ENTER],
171+
);
171172

172173
expect(stderr).toContain("unknown is not a valid template");
174+
expect(normalizeStdout(stdout)).toContain(firstPrompt);
175+
176+
// Skip test in case installation fails
177+
if (!existsSync(resolve(defaultLoaderPath, "./package-lock.json"))) {
178+
return;
179+
}
180+
181+
// Check if the output directory exists with the appropriate loader name
182+
expect(existsSync(defaultLoaderPath)).toBeTruthy();
183+
184+
// All test files are scaffolded
185+
for (const file of defaultTemplateFiles) {
186+
expect(existsSync(resolve(defaultLoaderPath, file))).toBeTruthy();
187+
}
188+
189+
// Check if the generated loader works successfully
190+
const path = resolve(assetsPath, "./my-loader/examples/simple/");
191+
192+
({ stdout } = await run(path, []));
193+
194+
expect(stdout).toContain("my-loader");
173195
});
174196

175197
it("recognizes '-t' as an alias for '--template'", async () => {

test/create-webpack-app/plugin/plugin.test.js

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,35 @@ describe("plugin command", () => {
164164

165165
it("should prompt on supplying an invalid template", async () => {
166166
const assetsPath = await uniqueDirectoryForTest();
167-
const { stderr } = await runPromptWithAnswers(assetsPath, ["plugin", "--template=unknown"]);
167+
const { defaultPluginPath, defaultTemplateFiles } = dataForTests(assetsPath);
168+
let { stdout, stderr } = await runPromptWithAnswers(
169+
assetsPath,
170+
["plugin", "--template=unknown"],
171+
[ENTER, ENTER, ENTER],
172+
);
168173

169174
expect(stderr).toContain("unknown is not a valid template");
175+
expect(normalizeStdout(stdout)).toContain(firstPrompt);
176+
177+
// Check if the output directory exists with the appropriate plugin name
178+
expect(existsSync(defaultPluginPath)).toBeTruthy();
179+
180+
// Skip test in case installation fails
181+
if (!existsSync(resolve(defaultPluginPath, "./package-lock.json"))) {
182+
return;
183+
}
184+
185+
// Test regressively files are scaffolded
186+
for (const file of defaultTemplateFiles) {
187+
expect(existsSync(join(defaultPluginPath, file))).toBeTruthy();
188+
}
189+
190+
// Check if the generated plugin works successfully
191+
({ stdout } = await run(defaultPluginPath, [
192+
"--config",
193+
"./examples/simple/webpack.config.js",
194+
]));
195+
expect(normalizeStdout(stdout)).toContain("Hello World!");
170196
});
171197

172198
it("recognizes '-t' as an alias for '--template'", async () => {

0 commit comments

Comments
 (0)