2017-07-10 15:26:36 +03:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
const path = require("path");
|
|
|
|
|
|
|
|
const runPrettier = require("../runPrettier");
|
|
|
|
const prettier = require("../../");
|
|
|
|
|
|
|
|
test("resolves configuration from external files", () => {
|
|
|
|
const output = runPrettier("cli/config/", ["**/*.js"]);
|
|
|
|
expect(output.stdout).toMatchSnapshot();
|
|
|
|
expect(output.status).toEqual(0);
|
|
|
|
});
|
|
|
|
|
|
|
|
test("resolves configuration from external files and overrides by extname", () => {
|
|
|
|
const output = runPrettier("cli/config/", ["**/*.ts"]);
|
|
|
|
expect(output.stdout).toMatchSnapshot();
|
|
|
|
expect(output.status).toEqual(0);
|
|
|
|
});
|
|
|
|
|
|
|
|
test("accepts configuration from --config", () => {
|
|
|
|
const output = runPrettier("cli/config/", [
|
|
|
|
"--config",
|
|
|
|
".prettierrc",
|
|
|
|
"./js/file.js"
|
|
|
|
]);
|
|
|
|
expect(output.stdout).toMatchSnapshot();
|
|
|
|
expect(output.status).toEqual(0);
|
|
|
|
});
|
|
|
|
|
2017-07-11 16:57:26 +03:00
|
|
|
test("resolves configuration file with --find-config-path file", () => {
|
2017-07-10 15:26:36 +03:00
|
|
|
const output = runPrettier("cli/config/", [
|
2017-07-11 16:57:26 +03:00
|
|
|
"--find-config-path",
|
2017-07-10 15:26:36 +03:00
|
|
|
"no-config/file.js"
|
|
|
|
]);
|
|
|
|
expect(output.stdout).toMatchSnapshot();
|
|
|
|
expect(output.status).toEqual(0);
|
|
|
|
});
|
|
|
|
|
2017-09-16 19:47:53 +03:00
|
|
|
test("resolves json configuration file with --find-config-path file", () => {
|
|
|
|
const output = runPrettier("cli/config/", [
|
|
|
|
"--find-config-path",
|
|
|
|
"rc-json/file.js"
|
|
|
|
]);
|
|
|
|
expect(output.stdout).toMatchSnapshot();
|
|
|
|
expect(output.status).toEqual(0);
|
|
|
|
});
|
|
|
|
|
|
|
|
test("resolves yaml configuration file with --find-config-path file", () => {
|
|
|
|
const output = runPrettier("cli/config/", [
|
|
|
|
"--find-config-path",
|
|
|
|
"rc-yaml/file.js"
|
|
|
|
]);
|
|
|
|
expect(output.stdout).toMatchSnapshot();
|
|
|
|
expect(output.status).toEqual(0);
|
|
|
|
});
|
|
|
|
|
2017-07-11 16:57:26 +03:00
|
|
|
test("prints nothing when no file found with --find-config-path", () => {
|
|
|
|
const output = runPrettier("cli/config/", ["--find-config-path", ".."]);
|
2017-07-10 15:26:36 +03:00
|
|
|
expect(output.stdout).toEqual("");
|
|
|
|
expect(output.status).toEqual(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
test("CLI overrides take precedence", () => {
|
|
|
|
const output = runPrettier("cli/config/", ["--print-width", "1", "**/*.js"]);
|
|
|
|
expect(output.stdout).toMatchSnapshot();
|
|
|
|
expect(output.status).toEqual(0);
|
|
|
|
});
|
|
|
|
|
|
|
|
test("API resolveConfig with no args", () => {
|
|
|
|
return prettier.resolveConfig().then(result => {
|
|
|
|
expect(result).toBeNull();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-09-01 13:17:07 +03:00
|
|
|
test("API resolveConfig.sync with no args", () => {
|
|
|
|
expect(prettier.resolveConfig.sync()).toBeNull();
|
|
|
|
});
|
|
|
|
|
2017-07-10 15:26:36 +03:00
|
|
|
test("API resolveConfig with file arg", () => {
|
|
|
|
const file = path.resolve(path.join(__dirname, "../cli/config/js/file.js"));
|
|
|
|
return prettier.resolveConfig(file).then(result => {
|
|
|
|
expect(result).toMatchObject({
|
|
|
|
tabWidth: 8
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-09-01 13:17:07 +03:00
|
|
|
test("API resolveConfig.sync with file arg", () => {
|
|
|
|
const file = path.resolve(path.join(__dirname, "../cli/config/js/file.js"));
|
|
|
|
expect(prettier.resolveConfig.sync(file)).toMatchObject({
|
|
|
|
tabWidth: 8
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-07-10 15:26:36 +03:00
|
|
|
test("API resolveConfig with file arg and extension override", () => {
|
|
|
|
const file = path.resolve(
|
|
|
|
path.join(__dirname, "../cli/config/no-config/file.ts")
|
|
|
|
);
|
|
|
|
return prettier.resolveConfig(file).then(result => {
|
|
|
|
expect(result).toMatchObject({
|
|
|
|
semi: true
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2017-09-01 13:17:07 +03:00
|
|
|
|
|
|
|
test("API resolveConfig.sync with file arg and extension override", () => {
|
|
|
|
const file = path.resolve(
|
|
|
|
path.join(__dirname, "../cli/config/no-config/file.ts")
|
|
|
|
);
|
|
|
|
expect(prettier.resolveConfig.sync(file)).toMatchObject({
|
|
|
|
semi: true
|
|
|
|
});
|
|
|
|
});
|