Skip to content

Commit c634518

Browse files
test: fix
1 parent 844c453 commit c634518

File tree

3 files changed

+49
-51
lines changed

3 files changed

+49
-51
lines changed

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

+27-30
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,7 @@ const os = require("os");
22
const path = require("path");
33
const { mkdirSync, existsSync, readFileSync } = require("fs");
44
const { join, resolve } = require("path");
5-
const {
6-
createPathDependentUtils,
7-
uniqueDirectoryForTest,
8-
isWindows,
9-
nodeVersion,
10-
} = require("../test.utils.js");
5+
const { createPathDependentUtils, uniqueDirectoryForTest, isWindows } = require("../test.utils.js");
116
const { run, runPromptWithAnswers } = createPathDependentUtils("create-webpack-app");
127

138
jest.setTimeout(480000);
@@ -64,7 +59,7 @@ const readFromPkgJSON = (path) => {
6459
// Helper to read from webpack.config.js in a given path
6560
const readFromWebpackConfig = (path) => readFileSync(join(path, "webpack.config.js"), "utf8");
6661

67-
(nodeVersion >= 18 ? describe : describe.skip)("create-webpack-app cli", () => {
62+
describe("create-webpack-app cli", () => {
6863
it("should generate default project when nothing is passed", async () => {
6964
const assetsPath = await uniqueDirectoryForTest();
7065
const { stdout } = await run(assetsPath, ["init", "--force"]);
@@ -94,7 +89,7 @@ const readFromWebpackConfig = (path) => readFileSync(join(path, "webpack.config.
9489
// Check if the generated package.json file content matches the snapshot
9590
expect(readFromPkgJSON(assetsPath)).toMatchSnapshot();
9691
});
97-
//
92+
9893
it("should generate folders if non existing generation path is given", async () => {
9994
const assetsPath = path.resolve(os.tmpdir(), Date.now().toString());
10095
const { stdout } = await run(__dirname, ["init", assetsPath, "--force"]);
@@ -111,7 +106,7 @@ const readFromWebpackConfig = (path) => readFileSync(join(path, "webpack.config.
111106
//Check if the generated package.json file content matches the snapshot
112107
expect(readFromPkgJSON(assetsPath)).toMatchSnapshot();
113108
});
114-
// //
109+
115110
it("should configure assets modules by default", async () => {
116111
const assetsPath = await uniqueDirectoryForTest();
117112
const { stdout } = await run(assetsPath, ["init", "--force"]);
@@ -129,7 +124,7 @@ const readFromWebpackConfig = (path) => readFileSync(join(path, "webpack.config.
129124
// Check if the generated webpack configuration matches the snapshot
130125
expect(readFromWebpackConfig(assetsPath)).toMatchSnapshot();
131126
});
132-
//
127+
133128
it("should ask question when wrong template is supplied", async () => {
134129
const assetsPath = await uniqueDirectoryForTest();
135130
const { stdout, stderr } = await runPromptWithAnswers(
@@ -150,7 +145,7 @@ const readFromWebpackConfig = (path) => readFileSync(join(path, "webpack.config.
150145
// Check if the generated package.json file content matches the snapshot
151146
expect(readFromPkgJSON(assetsPath)).toMatchSnapshot();
152147
});
153-
//
148+
154149
it("should generate typescript project correctly", async () => {
155150
const assetsPath = await uniqueDirectoryForTest();
156151
const { stdout } = await runPromptWithAnswers(
@@ -180,7 +175,7 @@ const readFromWebpackConfig = (path) => readFileSync(join(path, "webpack.config.
180175
// Check if the generated webpack configuration matches the snapshot
181176
expect(readFromWebpackConfig(assetsPath)).toMatchSnapshot();
182177
});
183-
// //
178+
184179
it("should generate ES6 project correctly", async () => {
185180
const assetsPath = await uniqueDirectoryForTest();
186181
const { stdout } = await runPromptWithAnswers(
@@ -206,7 +201,7 @@ const readFromWebpackConfig = (path) => readFileSync(join(path, "webpack.config.
206201
// Check if the generated webpack configuration matches the snapshot
207202
expect(readFromWebpackConfig(assetsPath)).toMatchSnapshot();
208203
});
209-
//
204+
210205
it("should use sass in project when selected", async () => {
211206
const assetsPath = await uniqueDirectoryForTest();
212207
const { stdout } = await runPromptWithAnswers(
@@ -239,7 +234,7 @@ const readFromWebpackConfig = (path) => readFileSync(join(path, "webpack.config.
239234
// Check if the generated webpack configuration matches the snapshot
240235
expect(readFromWebpackConfig(assetsPath)).toMatchSnapshot();
241236
});
242-
//
237+
243238
it("should use sass with postcss in project when selected", async () => {
244239
const assetsPath = await uniqueDirectoryForTest();
245240
const { stdout } = await runPromptWithAnswers(
@@ -274,7 +269,7 @@ const readFromWebpackConfig = (path) => readFileSync(join(path, "webpack.config.
274269
// Check if the generated webpack configuration matches the snapshot
275270
expect(readFromWebpackConfig(assetsPath)).toMatchSnapshot();
276271
});
277-
//
272+
278273
it("should use mini-css-extract-plugin when selected", async () => {
279274
const assetsPath = await uniqueDirectoryForTest();
280275
const { stdout } = await runPromptWithAnswers(
@@ -307,7 +302,7 @@ const readFromWebpackConfig = (path) => readFileSync(join(path, "webpack.config.
307302
// Check if the generated webpack configuration matches the snapshot
308303
expect(readFromWebpackConfig(assetsPath)).toMatchSnapshot();
309304
});
310-
//
305+
311306
it("should use sass and css with postcss in project when selected", async () => {
312307
const assetsPath = await uniqueDirectoryForTest();
313308
const { stdout } = await runPromptWithAnswers(
@@ -342,7 +337,7 @@ const readFromWebpackConfig = (path) => readFileSync(join(path, "webpack.config.
342337
// Check if the generated webpack configuration matches the snapshot
343338
expect(readFromWebpackConfig(assetsPath)).toMatchSnapshot();
344339
});
345-
//
340+
346341
it("should use less in project when selected", async () => {
347342
const assetsPath = await uniqueDirectoryForTest();
348343
const { stdout } = await runPromptWithAnswers(
@@ -375,7 +370,7 @@ const readFromWebpackConfig = (path) => readFileSync(join(path, "webpack.config.
375370
// Check if the generated webpack configuration matches the snapshot
376371
expect(readFromWebpackConfig(assetsPath)).toMatchSnapshot();
377372
});
378-
// //
373+
379374
it("should use stylus in project when selected", async () => {
380375
const assetsPath = await uniqueDirectoryForTest();
381376
const { stdout } = await runPromptWithAnswers(
@@ -408,7 +403,7 @@ const readFromWebpackConfig = (path) => readFileSync(join(path, "webpack.config.
408403
// Check if the generated webpack configuration matches the snapshot
409404
expect(readFromWebpackConfig(assetsPath)).toMatchSnapshot();
410405
});
411-
// //
406+
412407
it("should configure WDS as opted", async () => {
413408
const assetsPath = await uniqueDirectoryForTest();
414409
const { stdout } = await runPromptWithAnswers(
@@ -432,7 +427,7 @@ const readFromWebpackConfig = (path) => readFileSync(join(path, "webpack.config.
432427
// Check if the generated webpack configuration matches the snapshot
433428
expect(readFromWebpackConfig(assetsPath)).toMatchSnapshot();
434429
});
435-
// //
430+
436431
it("should use postcss in project when selected", async () => {
437432
const assetsPath = await uniqueDirectoryForTest();
438433
const { stdout } = await runPromptWithAnswers(
@@ -466,7 +461,7 @@ const readFromWebpackConfig = (path) => readFileSync(join(path, "webpack.config.
466461
// Check if the generated webpack configuration matches the snapshot
467462
expect(readFromWebpackConfig(assetsPath)).toMatchSnapshot();
468463
});
469-
//
464+
470465
it("should configure html-webpack-plugin as opted", async () => {
471466
const assetsPath = await uniqueDirectoryForTest();
472467
const { stdout } = await runPromptWithAnswers(
@@ -490,7 +485,7 @@ const readFromWebpackConfig = (path) => readFileSync(join(path, "webpack.config.
490485
// Check if the generated webpack configuration matches the snapshot
491486
expect(readFromWebpackConfig(assetsPath)).toMatchSnapshot();
492487
});
493-
//
488+
494489
it("should configure workbox-webpack-plugin as opted", async () => {
495490
const assetsPath = await uniqueDirectoryForTest();
496491
const { stdout } = await runPromptWithAnswers(
@@ -514,7 +509,7 @@ const readFromWebpackConfig = (path) => readFileSync(join(path, "webpack.config.
514509
// Check if the generated webpack configuration matches the snapshot
515510
expect(readFromWebpackConfig(assetsPath)).toMatchSnapshot();
516511
});
517-
//
512+
518513
it("should throw if the current path is not writable", async () => {
519514
if (isWindows) {
520515
return;
@@ -530,7 +525,7 @@ const readFromWebpackConfig = (path) => readFileSync(join(path, "webpack.config.
530525
expect(stderr).toContain("Failed to initialize the project with webpack!");
531526
expect(exitCode).toBe(2);
532527
});
533-
//
528+
534529
it("should work with 'new' alias", async () => {
535530
const assetsPath = await uniqueDirectoryForTest();
536531
const { stdout } = await run(assetsPath, ["new", "--force"]);
@@ -546,7 +541,7 @@ const readFromWebpackConfig = (path) => readFileSync(join(path, "webpack.config.
546541
// Check if the generated package.json file content matches the snapshot
547542
expect(readFromPkgJSON(assetsPath)).toMatchSnapshot();
548543
});
549-
//
544+
550545
it("should work with 'create' alias", async () => {
551546
const assetsPath = await uniqueDirectoryForTest();
552547
const { stdout } = await run(assetsPath, ["create", "--force"]);
@@ -562,7 +557,7 @@ const readFromWebpackConfig = (path) => readFileSync(join(path, "webpack.config.
562557
// Check if the generated package.json file content matches the snapshot
563558
expect(readFromPkgJSON(assetsPath)).toMatchSnapshot();
564559
});
565-
//
560+
566561
it("should work with 'c' alias", async () => {
567562
const assetsPath = await uniqueDirectoryForTest();
568563
const { stdout } = await run(assetsPath, ["c", "--force"]);
@@ -578,7 +573,7 @@ const readFromWebpackConfig = (path) => readFileSync(join(path, "webpack.config.
578573
// Check if the generated package.json file content matches the snapshot
579574
expect(readFromPkgJSON(assetsPath)).toMatchSnapshot();
580575
});
581-
//
576+
582577
it("should work with 'n' alias", async () => {
583578
const assetsPath = await uniqueDirectoryForTest();
584579
const { stdout } = await run(assetsPath, ["n", "--force"]);
@@ -626,7 +621,7 @@ const readFromWebpackConfig = (path) => readFileSync(join(path, "webpack.config.
626621
// Check if the generated package.json file content matches the snapshot
627622
expect(readFromPkgJSON(assetsPath)).toMatchSnapshot();
628623
});
629-
//
624+
630625
it("uses yarn as the package manager when opted", async () => {
631626
const assetsPath = await uniqueDirectoryForTest();
632627
const { stdout } = await runPromptWithAnswers(
@@ -651,7 +646,7 @@ const readFromWebpackConfig = (path) => readFileSync(join(path, "webpack.config.
651646
// Check if the generated package.json file content matches the snapshot
652647
expect(readFromPkgJSON(assetsPath)).toMatchSnapshot();
653648
});
654-
//
649+
655650
it("should generate react template with state and routing support with prompt answers", async () => {
656651
const assetsPath = await uniqueDirectoryForTest();
657652
const { stdout } = await runPromptWithAnswers(
@@ -674,7 +669,7 @@ const readFromWebpackConfig = (path) => readFileSync(join(path, "webpack.config.
674669
// Check if the generated webpack configuration matches the snapshot
675670
expect(readFromWebpackConfig(assetsPath)).toMatchSnapshot();
676671
});
677-
//
672+
678673
it("should generate react template with --force", async () => {
679674
const assetsPath = await uniqueDirectoryForTest();
680675
const { stdout } = await run(assetsPath, ["init", "--template=react", "--force"]);
@@ -737,6 +732,7 @@ const readFromWebpackConfig = (path) => readFileSync(join(path, "webpack.config.
737732
// Check if the generated webpack configuration matches the snapshot
738733
expect(readFromWebpackConfig(assetsPath)).toMatchSnapshot();
739734
});
735+
740736
it("should generate svelte template with prompt answers", async () => {
741737
const assetsPath = await uniqueDirectoryForTest();
742738
const { stdout } = await runPromptWithAnswers(
@@ -759,6 +755,7 @@ const readFromWebpackConfig = (path) => readFileSync(join(path, "webpack.config.
759755
// Check if the generated webpack configuration matches the snapshot
760756
expect(readFromWebpackConfig(assetsPath)).toMatchSnapshot();
761757
});
758+
762759
it("should generate svelte template with --force", async () => {
763760
const assetsPath = await uniqueDirectoryForTest();
764761
const { stdout } = await run(assetsPath, ["init", "--template=svelte", "--force"]);

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

+14-13
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const dataForTests = (rootAssetsPath) => ({
3232
],
3333
});
3434

35-
describe.skip("loader command", () => {
35+
describe("loader command", () => {
3636
it("should ask the loader name when invoked", async () => {
3737
const assetsPath = await uniqueDirectoryForTest();
3838
const { stdout, stderr } = await runPromptWithAnswers(assetsPath, ["loader", "."]);
@@ -41,6 +41,7 @@ describe.skip("loader command", () => {
4141
expect(normalizeStderr(stderr)).toBeFalsy();
4242
expect(normalizeStdout(stdout)).toContain(firstPrompt);
4343
});
44+
4445
it("should scaffold loader with default name if no loader name provided", async () => {
4546
const assetsPath = await uniqueDirectoryForTest();
4647
const { defaultLoaderPath, defaultTemplateFiles } = dataForTests(assetsPath);
@@ -58,10 +59,10 @@ describe.skip("loader command", () => {
5859

5960
// All test files are scaffolded
6061
defaultTemplateFiles.forEach((file) => {
61-
expect(existsSync(defaultLoaderPath, file)).toBeTruthy();
62+
expect(existsSync(resolve(defaultLoaderPath, file))).toBeTruthy();
6263
});
6364

64-
// Check if the the generated loader works successfully
65+
// Check if the generated loader works successfully
6566
const path = resolve(defaultLoaderPath, "./examples/simple/");
6667

6768
({ stdout } = await run(path, []));
@@ -90,10 +91,10 @@ describe.skip("loader command", () => {
9091

9192
// All test files are scaffolded
9293
defaultTemplateFiles.forEach((file) => {
93-
expect(existsSync(loaderPath, file)).toBeTruthy();
94+
expect(existsSync(resolve(loaderPath, file))).toBeTruthy();
9495
});
9596

96-
// Check if the the generated loader works successfully
97+
// Check if the generated loader works successfully
9798
const path = resolve(loaderPath, "./examples/simple/");
9899

99100
({ stdout } = await run(path, []));
@@ -122,10 +123,10 @@ describe.skip("loader command", () => {
122123

123124
// All test files are scaffolded
124125
defaultTemplateFiles.forEach((file) => {
125-
expect(existsSync(customLoaderPath, file)).toBeTruthy();
126+
expect(existsSync(resolve(customLoaderPath, file))).toBeTruthy();
126127
});
127128

128-
// Check if the the generated loader works successfully
129+
// Check if the generated loader works successfully
129130
const path = resolve(customLoaderPath, "./examples/simple/");
130131

131132
({ stdout } = await run(path, []));
@@ -155,10 +156,10 @@ describe.skip("loader command", () => {
155156

156157
// All test files are scaffolded
157158
defaultTemplateFiles.forEach((file) => {
158-
expect(existsSync(customLoaderPath, file)).toBeTruthy();
159+
expect(existsSync(resolve(customLoaderPath, file))).toBeTruthy();
159160
});
160161

161-
// Check if the the generated loader works successfully
162+
// Check if the generated loader works successfully
162163
const path = resolve(customLoaderPath, "./examples/simple/");
163164

164165
({ stdout } = await run(path, []));
@@ -198,10 +199,10 @@ describe.skip("loader command", () => {
198199

199200
// All test files are scaffolded
200201
defaultTemplateFiles.forEach((file) => {
201-
expect(existsSync(defaultLoaderPath, file)).toBeTruthy();
202+
expect(existsSync(resolve(defaultLoaderPath, file))).toBeTruthy();
202203
});
203204

204-
// Check if the the generated loader works successfully
205+
// Check if the generated loader works successfully
205206
const path = resolve(assetsPath, "./my-loader/examples/simple/");
206207

207208
({ stdout } = await run(path, []));
@@ -235,10 +236,10 @@ describe.skip("loader command", () => {
235236
];
236237

237238
files.forEach((file) => {
238-
expect(existsSync(defaultLoaderPath, file)).toBeTruthy();
239+
expect(existsSync(resolve(defaultLoaderPath, file))).toBeTruthy();
239240
});
240241

241-
// Check if the the generated loader works successfully
242+
// Check if the generated loader works successfully
242243
const path = resolve(assetsPath, "./my-loader/examples/simple/");
243244

244245
({ stdout } = await run(path, []));

0 commit comments

Comments
 (0)