MCPcopy
hub / github.com/prettier/prettier / runCli

Function runCli

tests/integration/run-cli.js:153–214  ·  view source on GitHub ↗

* @param {string} dir * @param {string[]} [args] * @param {CliTestOptions} [options]

(dir, args = [], options = {})

Source from the content-addressed store, hash-verified

151 * @param {CliTestOptions} [options]
152 */
153function runCli(dir, args = [], options = {}) {
154 const promise = runPrettierCli(dir, args, options);
155 const getters = {
156 get status() {
157 return promise.then(({ status }) => status);
158 },
159 get stdout() {
160 return promise.then(({ stdout }) => stdout);
161 },
162 get stderr() {
163 return promise.then(({ stderr }) => stderr);
164 },
165 get write() {
166 return promise.then(({ write }) => write);
167 },
168 test: testResult,
169 then(onFulfilled, onRejected) {
170 return promise.then(onFulfilled, onRejected);
171 },
172 };
173
174 return getters;
175
176 function testResult(testOptions) {
177 test(options.title || "", async () => {
178 const result = await promise;
179
180 let snapshot;
181 for (const name of ["status", "stdout", "stderr", "write"]) {
182 let value = result[name];
183 // \r is trimmed from jest snapshots by default;
184 // manually replacing this character with /*CR*/ to test its true presence
185 // If ignoreLineEndings is specified, \r is simply deleted instead
186 if (name === "stdout" || name === "stderr") {
187 value = result[name].replace(
188 /\r/g,
189 options.ignoreLineEndings ? "" : "/*CR*/",
190 );
191 }
192
193 if (name in testOptions) {
194 if (name === "status" && testOptions[name] === "non-zero") {
195 expect(value).not.toBe(0);
196 } else if (typeof testOptions[name] === "function") {
197 testOptions[name](value);
198 } else {
199 expect(value).toStrictEqual(testOptions[name]);
200 }
201 } else {
202 snapshot = snapshot ?? {};
203 snapshot[name] = value;
204 }
205 }
206
207 if (snapshot) {
208 expect(snapshot).toMatchSnapshot();
209 }
210 });

Callers 15

debug-check.jsFile · 0.85
runCliWithoutGitignoreFunction · 0.85
cursor-offset.jsFile · 0.85
infer-parser.jsFile · 0.85
debug-print-doc.jsFile · 0.85
log-level.jsFile · 0.85
runCliWithLogLevelFunction · 0.85
config-invalid.jsFile · 0.85
with-shebang.jsFile · 0.85

Calls 1

runPrettierCliFunction · 0.85

Tested by 6

runCliWithoutGitignoreFunction · 0.68
runCliWithLogLevelFunction · 0.68
getUnformattedFilesFunction · 0.68
getConfigFileByCliFunction · 0.68
runExperimentalCliFunction · 0.68
runCliWithoutGitignoreFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…