MCPcopy
hub / github.com/webpack/webpack-dev-server / testBin

Function testBin

test/helpers/test-bin.js:31–110  ·  view source on GitHub ↗
(testArgs = [], options = {})

Source from the content-addressed store, hash-verified

29};
30
31export const testBin = (testArgs = [], options = {}) => {
32 const cwd = process.cwd();
33 const env = {
34 WEBPACK_CLI_HELP_WIDTH: 2048,
35 NODE_ENV: process.env.NODE_ENV,
36 };
37
38 if (typeof testArgs === "string") {
39 testArgs = testArgs.split(" ");
40 }
41
42 let args;
43
44 if (testArgs.includes("--help")) {
45 args = [webpackDevServerPath, ...testArgs];
46 } else {
47 const configOptions = testArgs.includes("--config")
48 ? []
49 : ["--config", basicConfigPath];
50
51 args = [webpackDevServerPath, ...configOptions, ...testArgs];
52 }
53
54 return new Promise((resolve, reject) => {
55 const outputKillStr =
56 options.outputKillStr ||
57 /Content not from webpack is served|For using 'serve' command you need to install/;
58 const subprocess = execa("node", args, {
59 cwd,
60 env,
61 stdio: "pipe",
62 maxBuffer: Infinity,
63 reject: false,
64 ...options,
65 });
66
67 subprocess.stdout.pipe(
68 new Writable({
69 write(chunk, encoding, callback) {
70 const str = chunk.toString();
71 const output = util.stripVTControlCharacters(str);
72
73 if (outputKillStr.test(output)) {
74 processKill(subprocess);
75 }
76
77 callback();
78 },
79 }),
80 );
81
82 subprocess.stderr.pipe(
83 new Writable({
84 write(chunk, encoding, callback) {
85 const str = chunk.toString();
86 const output = util.stripVTControlCharacters(str);
87
88 if (outputKillStr.test(output)) {

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…