forked from fardad-dev/prettier-plugin-jsdoc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtypeScript.test.ts
More file actions
212 lines (190 loc) · 6.02 KB
/
Copy pathtypeScript.test.ts
File metadata and controls
212 lines (190 loc) · 6.02 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
import * as prettier from "prettier";
import { AllOptions } from "../src/types";
function subject(code: string, options: Partial<AllOptions> = {}) {
return prettier.format(code, {
parser: "typescript",
plugins: ["prettier-plugin-jsdoc"],
jsdocSpaces: 1,
...options,
} as AllOptions);
}
test("JS code should be formatted as usuall", async () => {
const result = await subject(`
/**
@typedef {
{
"userId": string,
"title": string,
"profileImageLink": string,
"identityStatus": "None",
"isBusinessUser": boolean,
"isResellerUser": boolean,
"isSubUser": boolean,
"shareCode": number,
"referredBy": string,
"businessName": string,
"businessUserId": string,
"nationalCode": string,
"state": string,
"city": string,
"address": string,
"phoneNumber": string
}
} User
*/
export let User
/**
@typedef {
{
"domainId": 0,
persianName: string,
"englishName": string, // comment
"resellerUserId": string,
"isActive": true,
"logoFileUniqueId": string,
"logoFileName": string,
"logoFileUrl": string,
"domainPersianName": string,
"domainEnglishName": string,
"resellerUserDisplayName": string,
"about": string
}
} SubDomain
*/
/**
@typedef {
() => a.b
} SubDomain
*/
`);
expect(result).toMatchSnapshot();
});
test("hoisted object", async () => {
const result = await subject(`
/**
@typedef {
{
"userId": {
title: string,
"profileImageLink": *,
"identityStatus": "None",
"isBusinessUser": "isResellerUser"|"isBoolean"| "isSubUser" | "isNot",
"shareCode": number,
"referredBy": any,
},
id:number
}
} User
*/
`);
expect(result).toMatchSnapshot();
});
test("max width challenge", async () => {
const result = await subject(
`
class test {
/**
* Replaces text in a string, using a regular expression or search string.
* @param {string | RegExp} searchValue A string to search for.
* @param {string | (substring: string, ...args: any[]) => string} replaceValue A string containing the text to replace for every successful match of searchValue in this string.
* @param {string | (substring: string, ...args: any[]) => string} A_big_string_for_test A string containing the text to replace for every successful match of searchValue in this string.
* @param {string | (substring: string, ...args: any[]) => string} replaceValue A_big_string_for_test string containing the text to replace for every successful match of searchValue in this string.
* @param {string | (substring: string, ...args: any[]) => string} A_big_string_for_test A_big_string_for_test string containing the text to replace for every successful match of searchValue in this string.
* @returns {StarkStringType & NativeString}
*/
replace(searchValue, replaceValue) {
class test{
/**
* Replaces text in a string, using a regular expression or search string.
*
* @param {string | RegExp} searchValue A string to search for.
* @param {string | (substring: string, ...args: any[]) => string} replaceValue
* A string containing the text to replace for every successful match of
* searchValue in this string.
* @param {string | (substring: string, ...args: any[]) => string} A_big_string_for_test
* A string containing the text to replace for every successful match of searchValue
* in this string.
* @param {string | (substring: string, ...args: any[]) => string} replaceValue
* A_big_string_for_test string containing the text to replace for every
* successful match of searchValue in this string.
* @param {string | (substring: string, ...args: any[]) => string} A_big_string_for_test
* A_big_string_for_test string containing the text to replace for every successful
* match of searchValue in this string.
* @returns {StarkStringType & NativeString}
*/
testFunction(){
}
}
this._value = this._value.replace(searchValue, replaceValue);
return this;
}
}
`,
);
expect(result).toMatchSnapshot();
});
test("description in interface", async () => {
const result = await subject(
`
export interface FetchCallbackResponseArray<T, V> {
resource: Resource<T>;
/**
* @deprecated Resolve clear with condition in your fetch api this function will be remove
*/
refetch: (...arg: V[]) => void;
/**
* @deprecated Resolve clear with condition in your fetch api this function will be remove
*/
clear: () => void;
}
`,
);
expect(await subject(await subject(result))).toMatchSnapshot();
});
test("Default export", async () => {
const result = await subject(`
/**
* @typedef {import("Foo")} Foo
*/
`);
expect(result).toMatchSnapshot();
});
test("Union types", async () => {
const result = await subject(`
/**
* @typedef {{ foo: string } | { bar: string; manyMoreLongArguments: object } | { baz: string }} Foo
*/
`);
expect(result).toMatchSnapshot();
});
test("Long type Union types", async () => {
const result = await subject(`
/**
* Gets a configuration object assembled from environment variables and .env configuration files.
*
* @memberof Config
* @function getEnvConfig
* @returns {Config.SomeConfiguration | Config.SomeOtherConfiguration | Config.AnotherConfiguration | Config.YetAnotherConfiguration } The environment configuration
*/
export default () => configurator.config;
`);
expect(result).toMatchSnapshot();
});
test("type imports", async () => {
const result = await subject(
`
/**
* @import BM, { B as B1,
* B2 , B4 } from 'moduleb'
* @typedef {Object} Foo
* @import BMain, {B3 } from "moduleb"
* @import {A} from 'modulea'
*/
/**
* @import BDefault, { B5 } from 'moduleb'
* @import C from "modulec"
*/
`,
);
expect(result).toMatchSnapshot();
});