Files
test-repo/tests_integration/__tests__/config-resolution.js
T
Lucas Azzola dcccfed366 Implement cosmiconfig for workspace configuration (#2434)
* Implement cosmiconfig

* Add resolveOptions API and extname support

* Add --resolve-config and --config, rename resolveOptions to resolveConfig

* Move color to top-level CLI options

* Fix unknown param warning

* Change from {} to null when no config is found

* Change override API to emulate eslint

* Add test for eslint-style overrides

* Delete overrides from resolveConfig
2017-07-10 22:26:36 +10:00

76 lines
2.1 KiB
JavaScript

"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);
});
test("resolves configuration file with --resolve-config file", () => {
const output = runPrettier("cli/config/", [
"--resolve-config",
"no-config/file.js"
]);
expect(output.stdout).toMatchSnapshot();
expect(output.status).toEqual(0);
});
test("prints nothing when no file found with --resolve-config", () => {
const output = runPrettier("cli/config/", ["--resolve-config", ".."]);
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();
});
});
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
});
});
});
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
});
});
});