-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: description start with markdown
issue: #201
- Loading branch information
Showing
8 changed files
with
186 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Description start with markdown 1`] = ` | ||
"/** | ||
* Just a simple test | ||
* | ||
* @remarks | ||
* - Remark 1 | ||
* - Remark 2 | ||
* - Remark 3 | ||
*/ | ||
" | ||
`; | ||
|
||
exports[`Description start with markdown 2`] = ` | ||
"/** | ||
* Just a simple test | ||
* | ||
* @remarks | ||
* - Remark 1 | ||
* - Remark 2 | ||
* - Remark 3 | ||
*/ | ||
" | ||
`; | ||
|
||
exports[`JS code should be formatted as usuall 1`] = ` | ||
"/** | ||
* Just a simple test | ||
* | ||
* @remarks | ||
* - Remark 1 | ||
* - Remark 2 | ||
* - Remark 3 | ||
*/ | ||
" | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
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, | ||
}, | ||
}, | ||
]; | ||
|
||
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`, | ||
); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { format } from "prettier"; | ||
import { AllOptions } from "../src/types"; | ||
|
||
function subject(code: string, options: Partial<AllOptions> = {}) { | ||
return format(code, { | ||
parser: "babel", | ||
plugins: ["prettier-plugin-jsdoc"], | ||
...options, | ||
} as AllOptions); | ||
} | ||
|
||
test("Description start with markdown", async () => { | ||
const result = await subject( | ||
` | ||
/** | ||
* Just a simple test | ||
* | ||
* @remarks | ||
* - Remark 1 | ||
* - Remark 2 | ||
* - Remark 3 | ||
*/ | ||
`, | ||
{ | ||
tsdoc: true, | ||
}, | ||
); | ||
|
||
expect(result).toMatchSnapshot(); | ||
|
||
const result2 = await subject( | ||
` | ||
/** | ||
* Just a simple test | ||
* | ||
* @remarks | ||
* - Remark 1 | ||
* - Remark 2 | ||
* - Remark 3 | ||
*/ | ||
`, | ||
{ | ||
tsdoc: false, | ||
}, | ||
); | ||
|
||
expect(result2).toMatchSnapshot(); | ||
}); |