MCPcopy Create free account
hub / github.com/webpack/webpack-cli / createPathDependentUtils

Function createPathDependentUtils

test/create-webpack-app/test.utils.js:11–55  ·  view source on GitHub ↗

@typedef {Record } TestOptions

(cli)

Source from the content-addressed store, hash-verified

9/** @typedef {Record<string, any>} TestOptions */
10
11function createPathDependentUtils(cli) {
12 const CLI_PATH = path.resolve(__dirname, `../../packages/${cli}/bin/cli.js`);
13
14 /**
15 * Run the webpack CLI for a test case.
16 * @param {string} cwd The path to folder that contains test
17 * @param {string[]} args Array of arguments
18 * @param {TestOptions} options Options for tests
19 * @returns {Promise<import("execa").Result>} child process
20 */
21 const run = async (cwd, args = [], options = {}) =>
22 testUtilsPkg.run(cwd, args, {
23 ...options,
24 executorPath: CLI_PATH,
25 });
26
27 /**
28 * Run the webpack CLI in watch mode for a test case.
29 * @param {string} cwd The path to folder that contains test
30 * @param {string[]} args Array of arguments
31 * @param {TestOptions} options Options for tests
32 * @returns {Promise<import("execa").Result>} The webpack output or Promise when nodeOptions are present
33 */
34 const runWatch = async (cwd, args = [], options = {}) =>
35 testUtilsPkg.runWatch(cwd, args, {
36 ...options,
37 executorPath: CLI_PATH,
38 });
39
40 /**
41 * runPromptWithAnswers
42 * @param {string} cwd The path to folder that contains test
43 * @param {string[]} args CLI args to pass in
44 * @param {string[]} answers answers to be passed to stdout for inquirer question
45 * @param {TestOptions} options Options for tests
46 * @returns {Promise<{ stdout: string, stderr: string }>} result
47 */
48 const runPromptWithAnswers = async (cwd, args, answers = [], options = {}) =>
49 testUtilsPkg.runPromptWithAnswers(cwd, args, answers, {
50 ...options,
51 executorPath: CLI_PATH,
52 });
53
54 return { run, runWatch, runPromptWithAnswers };
55}
56
57module.exports = {
58 createPathDependentUtils,

Callers 5

init.test.jsFile · 0.85
plugin.test.jsFile · 0.85
loader.test.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected