/
support-info.js
68 lines (63 loc) · 1.67 KB
/
support-info.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
"use strict";
const prettier = require("prettier/local");
const runPrettier = require("../runPrettier");
const snapshotDiff = require("snapshot-diff");
describe("API getSupportInfo()", () => {
const testVersions = [
"0.0.0",
"1.0.0",
"1.4.0",
"1.5.0",
"1.7.1",
"1.8.0",
"1.8.2",
"1.16.0",
undefined
];
testVersions.forEach((version, index) => {
const info = getCoreInfo(version);
if (index === 0) {
test(`with version ${version}`, () => {
expect(info).toMatchSnapshot();
});
} else {
const previousVersion = testVersions[index - 1];
const previousInfo = getCoreInfo(previousVersion);
test(`with version ${previousVersion} -> ${version}`, () => {
expect(snapshotDiff(previousInfo, info)).toMatchSnapshot();
});
}
});
});
describe("CLI --support-info", () => {
runPrettier("cli", "--support-info").test({ status: 0 });
});
function getCoreInfo(version) {
const supportInfo = prettier.getSupportInfo(version);
const languages = supportInfo.languages.reduce(
(obj, language) =>
Object.assign({ [language.name]: language.parsers }, obj),
{}
);
const options = supportInfo.options.reduce(
(obj, option) =>
Object.assign(
{
[option.name]: Object.assign(
{
type: option.type,
default: option.default
},
option.type === "int"
? { range: option.range }
: option.type === "choice"
? { choices: option.choices.map(choice => choice.value) }
: null
)
},
obj
),
{}
);
return { languages, options };
}