Skip to content

Commit a3b56d3

Browse files
fix: do not log the No commands message in the dev mode (#41)
1 parent 50260b3 commit a3b56d3

File tree

5 files changed

+337
-60
lines changed

5 files changed

+337
-60
lines changed

__tests__/__snapshots__/index.test.js.snap

Lines changed: 141 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ Array [
147147
"ExecaPlugin",
148148
"warn",
149149
Array [
150-
"No commands found for \\"compile\\" hook",
150+
"No commands found for the \\"compile\\" hook",
151151
],
152152
],
153153
Array [
@@ -164,7 +164,7 @@ exports[`execa-webpack-plugin should throw error invalid 'onFooBar' option (no h
164164

165165
exports[`execa-webpack-plugin should throw error invalid 'onFooBar' option (no hooks): logs 1`] = `Array []`;
166166

167-
exports[`execa-webpack-plugin should throw error on 'infrastructureLog' hook 1`] = `[Error: Do not use "infrastructureLog" hook]`;
167+
exports[`execa-webpack-plugin should throw error on 'infrastructureLog' hook 1`] = `[Error: Do not use the "infrastructureLog" hook]`;
168168

169169
exports[`execa-webpack-plugin should throw error on 'infrastructureLog' hook: logs 1`] = `Array []`;
170170

@@ -326,6 +326,145 @@ Array [
326326

327327
exports[`execa-webpack-plugin should work and output 'stdout' and 'stderr' (sync hook): warnings 1`] = `Array []`;
328328

329+
exports[`execa-webpack-plugin should work in watch mode when the 'dev' option is 'false': errors 1`] = `Array []`;
330+
331+
exports[`execa-webpack-plugin should work in watch mode when the 'dev' option is 'false': logs 1`] = `
332+
Array [
333+
Array [
334+
"ExecaPlugin",
335+
"log",
336+
Array [
337+
"Running the \\"done\\" hook",
338+
],
339+
],
340+
Array [
341+
"ExecaPlugin",
342+
"log",
343+
Array [
344+
"Run command \\"node /__tests__/resources/nothing.js\\"",
345+
],
346+
],
347+
Array [
348+
"ExecaPlugin",
349+
"log",
350+
Array [
351+
"The \\"done\\" hook completed",
352+
],
353+
],
354+
Array [
355+
"ExecaPlugin",
356+
"log",
357+
Array [
358+
"Running the \\"done\\" hook",
359+
],
360+
],
361+
Array [
362+
"ExecaPlugin",
363+
"log",
364+
Array [
365+
"Run command \\"node /__tests__/resources/nothing.js\\"",
366+
],
367+
],
368+
Array [
369+
"ExecaPlugin",
370+
"log",
371+
Array [
372+
"The \\"done\\" hook completed",
373+
],
374+
],
375+
]
376+
`;
377+
378+
exports[`execa-webpack-plugin should work in watch mode when the 'dev' option is 'false': warnings 1`] = `Array []`;
379+
380+
exports[`execa-webpack-plugin should work in watch mode when the 'dev' option is 'true': errors 1`] = `Array []`;
381+
382+
exports[`execa-webpack-plugin should work in watch mode when the 'dev' option is 'true': logs 1`] = `
383+
Array [
384+
Array [
385+
"ExecaPlugin",
386+
"log",
387+
Array [
388+
"Running the \\"done\\" hook",
389+
],
390+
],
391+
Array [
392+
"ExecaPlugin",
393+
"log",
394+
Array [
395+
"Run command \\"node /__tests__/resources/nothing.js\\"",
396+
],
397+
],
398+
Array [
399+
"ExecaPlugin",
400+
"log",
401+
Array [
402+
"The \\"done\\" hook completed",
403+
],
404+
],
405+
Array [
406+
"ExecaPlugin",
407+
"log",
408+
Array [
409+
"Running the \\"done\\" hook",
410+
],
411+
],
412+
Array [
413+
"ExecaPlugin",
414+
"log",
415+
Array [
416+
"The \\"done\\" hook completed",
417+
],
418+
],
419+
]
420+
`;
421+
422+
exports[`execa-webpack-plugin should work in watch mode when the 'dev' option is 'true': warnings 1`] = `Array []`;
423+
424+
exports[`execa-webpack-plugin should work in watch mode: errors 1`] = `Array []`;
425+
426+
exports[`execa-webpack-plugin should work in watch mode: logs 1`] = `
427+
Array [
428+
Array [
429+
"ExecaPlugin",
430+
"log",
431+
Array [
432+
"Running the \\"done\\" hook",
433+
],
434+
],
435+
Array [
436+
"ExecaPlugin",
437+
"log",
438+
Array [
439+
"Run command \\"node /__tests__/resources/nothing.js\\"",
440+
],
441+
],
442+
Array [
443+
"ExecaPlugin",
444+
"log",
445+
Array [
446+
"The \\"done\\" hook completed",
447+
],
448+
],
449+
Array [
450+
"ExecaPlugin",
451+
"log",
452+
Array [
453+
"Running the \\"done\\" hook",
454+
],
455+
],
456+
Array [
457+
"ExecaPlugin",
458+
"log",
459+
Array [
460+
"The \\"done\\" hook completed",
461+
],
462+
],
463+
]
464+
`;
465+
466+
exports[`execa-webpack-plugin should work in watch mode: warnings 1`] = `Array []`;
467+
329468
exports[`execa-webpack-plugin should work multiple commands and do not overload the system (the number of cores is 1) (async hook): errors 1`] = `Array []`;
330469

331470
exports[`execa-webpack-plugin should work multiple commands and do not overload the system (the number of cores is 1) (async hook): logs 1`] = `

__tests__/index.test.js

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ function compile(options) {
5959
});
6060
}
6161

62+
function watch(options, handler) {
63+
const compiler = webpack(getConfig(options));
64+
65+
return compiler.watch({ poll: true }, handler);
66+
}
67+
6268
/* eslint-disable no-sync */
6369

6470
function mkdirSyncSafe(dir) {
@@ -1026,4 +1032,108 @@ describe("execa-webpack-plugin", () => {
10261032

10271033
spy.mockRestore();
10281034
});
1035+
1036+
it("should work in watch mode", done => {
1037+
let counter = 0;
1038+
1039+
const watching = watch(
1040+
{
1041+
onDone: [
1042+
{
1043+
args: [path.join(resourcesDir, "nothing.js")],
1044+
cmd: "node"
1045+
}
1046+
]
1047+
},
1048+
(error, stats) => {
1049+
counter += 1;
1050+
1051+
if (error) {
1052+
return done(error);
1053+
}
1054+
1055+
if (counter === 1) {
1056+
return watching.invalidate();
1057+
}
1058+
1059+
expect(logs).toMatchSnapshot("logs");
1060+
expect(getErrors(stats)).toMatchSnapshot("errors");
1061+
expect(getWarnings(stats)).toMatchSnapshot("warnings");
1062+
1063+
watching.close();
1064+
1065+
return done();
1066+
}
1067+
);
1068+
});
1069+
1070+
it("should work in watch mode when the 'dev' option is 'false'", done => {
1071+
let counter = 0;
1072+
1073+
const watching = watch(
1074+
{
1075+
dev: false,
1076+
onDone: [
1077+
{
1078+
args: [path.join(resourcesDir, "nothing.js")],
1079+
cmd: "node"
1080+
}
1081+
]
1082+
},
1083+
(error, stats) => {
1084+
counter += 1;
1085+
1086+
if (error) {
1087+
return done(error);
1088+
}
1089+
1090+
if (counter === 1) {
1091+
return watching.invalidate();
1092+
}
1093+
1094+
expect(logs).toMatchSnapshot("logs");
1095+
expect(getErrors(stats)).toMatchSnapshot("errors");
1096+
expect(getWarnings(stats)).toMatchSnapshot("warnings");
1097+
1098+
watching.close();
1099+
1100+
return done();
1101+
}
1102+
);
1103+
});
1104+
1105+
it("should work in watch mode when the 'dev' option is 'true'", done => {
1106+
let counter = 0;
1107+
1108+
const watching = watch(
1109+
{
1110+
dev: true,
1111+
onDone: [
1112+
{
1113+
args: [path.join(resourcesDir, "nothing.js")],
1114+
cmd: "node"
1115+
}
1116+
]
1117+
},
1118+
(error, stats) => {
1119+
counter += 1;
1120+
1121+
if (error) {
1122+
return done(error);
1123+
}
1124+
1125+
if (counter === 1) {
1126+
return watching.invalidate();
1127+
}
1128+
1129+
expect(logs).toMatchSnapshot("logs");
1130+
expect(getErrors(stats)).toMatchSnapshot("errors");
1131+
expect(getWarnings(stats)).toMatchSnapshot("warnings");
1132+
1133+
watching.close();
1134+
1135+
return done();
1136+
}
1137+
);
1138+
});
10291139
});

package-lock.json

Lines changed: 25 additions & 25 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)