-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathfiles.test.ts
More file actions
91 lines (84 loc) · 1.96 KB
/
files.test.ts
File metadata and controls
91 lines (84 loc) · 1.96 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import * as prettier from "prettier";
import { readFileSync } from "node:fs";
import { resolve } from "node:path";
import { AllOptions } from "../src/types";
import "jest-specific-snapshot";
function subjectFiles(relativePath: string, options: Partial<AllOptions> = {}) {
const filepath = resolve(process.cwd(), "tests", relativePath);
try {
const code = readFileSync(filepath).toString();
return prettier.format(code, {
plugins: ["prettier-plugin-jsdoc"],
jsdocSpaces: 1,
trailingComma: "all",
filepath,
...options,
} as AllOptions);
} catch (error) {
console.error(error);
}
}
const PrismOptions = {
arrowParens: "avoid",
printWidth: 120,
quoteProps: "preserve",
semi: true,
singleQuote: true,
tabWidth: 4,
trailingComma: "none",
useTabs: true,
jsdocKeepUnParseAbleExampleIndent: true,
} as const;
/**
* @type {TestFile[]}
*
* @typedef TestFile
* @property {string} name
* @property {import("prettier").Options} [options]
*/
const files: {
name: string;
options?: Partial<AllOptions>;
}[] = [
{ name: "typeScript.js" },
{ name: "typeScript.js" },
{ name: "typeScript.ts" },
{ name: "types.ts" },
{ name: "order.jsx" },
{ name: "create-ignorer.js" },
{
name: "prism-core.js",
options: PrismOptions,
},
{
name: "prism-dependencies.js",
options: {
jsdocSeparateTagGroups: true,
...PrismOptions,
},
},
{
name: "tsdoc.ts",
options: {
tsdoc: true,
},
},
{
name: "order-custom.jsx",
options: {
jsdocTagsOrder: '{"example":43, "typedef":0, "returns": 46}' as any,
// {
// example: 70,
// } as any,
},
},
];
for (let i = 0; i < files.length; i++) {
const { name, options } = files[i];
test(`File: ${name}`, async () => {
const result = await subjectFiles("./files/" + name, options);
(expect(result) as any).toMatchSpecificSnapshot(
`./__snapshots__/files/${name}.shot`,
);
});
}