Files
test-repo/tests_integration/runPrettier.js
T
Michał Pierzchała 7a0df958dc Ignore node_modules when running prettier from CLI (#1683)
* Ignore node_modules by default

* Add integration test suite for --with-node-modules CLI arg

* Refactor tests to snapshots

* Disable eslint for purposely faulty files

* Fix node 4

* Fix prettier

* Gitignore only top-level node_modules
2017-05-23 14:19:04 -07:00

31 lines
798 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/*
* runPrettier – spawns `prettier` process.
* Adopted from Jest's integration tests suite.
*/
"use strict";
const path = require("path");
const spawnSync = require("cross-spawn").sync;
const PRETTIER_PATH = path.resolve(__dirname, "../bin/prettier.js");
// return the result of the spawned process:
// [ 'status', 'signal', 'output', 'pid', 'stdout', 'stderr',
// 'envPairs', 'options', 'args', 'file' ]
function runPrettier(dir, args) {
const isRelative = dir[0] !== "/";
if (isRelative) {
dir = path.resolve(__dirname, dir);
}
const result = spawnSync(PRETTIER_PATH, args || [], { cwd: dir });
result.stdout = result.stdout && result.stdout.toString();
result.stderr = result.stderr && result.stderr.toString();
return result;
}
module.exports = runPrettier;