Files
test-repo/tests_integration/__tests__/multiple-patterns.js
T
Ika c4e5463514 refactor(cli): separate files and make it pure as possible (#2730)
* refactor(bin): resolveConfig

* refactor(bin): getOptionsForFile

* refactor(bin): remove `mapSeries`

* refactor: move content from bin to src/cli

* refactor: wrap content with function

* refactor: move constants to another file

* refactor: move utils to another file

* refactor: move functions

* refactor: extract functions

* refactor: remove unnecessary variable

* refactor: move `src/cli` to `src` with prefix `cli`

* refactor: use template literal

* refactor: remove unnecessary variable

* refactor: extract `listDifferent`

* refactor: extract `format`

* refactor: change error message `Invalid configuration:`

* refactor: bind args with argv

* refactor: extract `getOptionsForFile`

* refactor: extract `formatStdin`

* refactor: extract `eachFilename`

* refactor: extract `formatFiles`

* refactor: remove unnecessary export

* refactor: use `globby.sync()`

* refactor: add `runPrettier.sync()` helper

* refactor: fix linting

* refactor: mock `process.argv`

* chore: use `--forceExit` to avoid process hanging

* refactor: mock `get-stream`

* refactor: remove unnecessary stuff

* refactor: fix linting

* refactor: wrap `run` with `try..catch.finally`

* refactor: restore `process.exitCode` after testing
2017-09-03 19:21:06 +10:00

87 lines
2.1 KiB
JavaScript

"use strict";
const runPrettier = require("../runPrettier");
test("multiple patterns", () => {
const result = runPrettier("cli/multiple-patterns", [
"directory/**/*.js",
"other-directory/**/*.js",
"-l"
]);
expect(result.stdout).toMatchSnapshot();
expect(result.status).toEqual(1);
});
test("multiple patterns with non exists pattern", () => {
const result = runPrettier("cli/multiple-patterns", [
"directory/**/*.js",
"non-existent.js",
"-l"
]);
expect(result.stdout).toMatchSnapshot();
expect(result.status).toEqual(1);
});
test("multiple patterns with ignore nested directories pattern", () => {
const result = runPrettier("cli/multiple-patterns", [
"**/*.js",
"!**/nested-directory/**",
"-l"
]);
expect(result.stdout).toMatchSnapshot();
expect(result.status).toEqual(1);
});
test("multiple patterns by with ignore pattern, ignores node_modules by default", () => {
const result = runPrettier("cli/multiple-patterns", [
"**/*.js",
"!directory/**",
"-l"
]);
expect(result.stdout).toMatchSnapshot();
expect(result.status).toEqual(1);
});
test("multiple patterns by with ignore pattern, ignores node_modules by with ./**/*.js", () => {
const result = runPrettier("cli/multiple-patterns", [
"./**/*.js",
"!./directory/**",
"-l"
]);
expect(result.stdout).toMatchSnapshot();
expect(result.status).toEqual(1);
});
test("multiple patterns by with ignore pattern, doesn't ignore node_modules with --with-node-modules flag", () => {
const result = runPrettier("cli/multiple-patterns", [
"**/*.js",
"!directory/**",
"-l",
"--with-node-modules"
]);
expect(result.stdout).toMatchSnapshot();
expect(result.status).toEqual(1);
});
test("no errors on empty patterns", () => {
const result = runPrettier("cli/multiple-patterns");
expect(result.status).toEqual(0);
});
test("multiple patterns, throw error and exit with non zero code on non existing files", () => {
const result = runPrettier("cli/multiple-patterns", [
"non-existent.js",
"other-non-existent.js",
"-l"
]);
expect(result.stderr).toMatchSnapshot();
expect(result.status).toEqual(2);
});