Skip to content

Commit 441280d

Browse files
committed
Convert CustomMarkdownEmitter.test.ts to use Jest snapshots instead of the deprecated FileDiffTest API
1 parent 440fc41 commit 441280d

File tree

3 files changed

+60
-59
lines changed

3 files changed

+60
-59
lines changed

apps/api-documenter/src/markdown/test/CustomMarkdownEmitter.test.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
22
// See LICENSE in the project root for license information.
33

4-
import * as path from 'path';
5-
import { FileDiffTest, FileSystem } from '@microsoft/node-core-library';
64
import {
75
DocSection,
86
TSDocConfiguration,
@@ -24,8 +22,7 @@ import { DocTableCell } from '../../nodes/DocTableCell';
2422
import { CustomMarkdownEmitter } from '../CustomMarkdownEmitter';
2523
import { ApiModel, ApiItem } from '@microsoft/api-extractor';
2624

27-
test('render Markdown from TSDoc', done => {
28-
const outputFolder: string = FileDiffTest.prepareFolder(__dirname, 'MarkdownPageRenderer');
25+
test('render Markdown from TSDoc', () => {
2926
const configuration: TSDocConfiguration = CustomDocNodes.configuration;
3027

3128
const output: DocSection = new DocSection({ configuration });
@@ -196,7 +193,6 @@ test('render Markdown from TSDoc', done => {
196193
])
197194
]);
198195

199-
const outputFilename: string = path.join(outputFolder, 'ActualOutput.md');
200196
const stringBuilder: StringBuilder = new StringBuilder();
201197
const apiModel: ApiModel = new ApiModel();
202198
const markdownEmitter: CustomMarkdownEmitter = new CustomMarkdownEmitter(apiModel);
@@ -206,9 +202,6 @@ test('render Markdown from TSDoc', done => {
206202
return '#';
207203
}
208204
});
209-
FileSystem.writeFile(outputFilename, stringBuilder.toString());
210205

211-
FileDiffTest.assertEqual(outputFilename, path.join(__dirname, 'ExpectedOutput.md'));
212-
213-
done();
206+
expect(stringBuilder).toMatchSnapshot();
214207
});

apps/api-documenter/src/markdown/test/ExpectedOutput.md

Lines changed: 0 additions & 50 deletions
This file was deleted.
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`render Markdown from TSDoc 1`] = `
4+
StringBuilder {
5+
"_chunks": Array [
6+
"
7+
## Simple bold test
8+
9+
This is a <b>bold</b> word.
10+
11+
## All whitespace bold
12+
13+
14+
15+
## Newline bold
16+
17+
<b>line 1</b> <b>line 2</b>
18+
19+
## Newline bold with spaces
20+
21+
<b>line 1</b> <b>line 2</b> <b>line 3</b>
22+
23+
## Adjacent bold regions
24+
25+
<b>one</b><b>two</b> <b>three</b> <b>four</b>non-bold<!-- --><b>five</b>
26+
27+
## Adjacent to other characters
28+
29+
[a link](./index.md)<!-- --><b>bold</b>non-boldmore-non-bold
30+
31+
## Bad characters
32+
33+
<b>\\\\*one\\\\*two\\\\*</b><b>three\\\\*four</b>
34+
35+
## Characters that should be escaped
36+
37+
Double-encoded JSON: \\"{ \\\\\\\\\\"A\\\\\\\\\\": 123}\\"
38+
39+
HTML chars: &lt;script&gt;alert(\\"\\\\[You\\\\] are \\\\#1!\\");&lt;/script&gt;
40+
41+
HTML escape: &amp;quot;
42+
43+
3 or more hyphens: - -- \\\\-\\\\-\\\\- \\\\-\\\\-\\\\-- \\\\-\\\\-\\\\--- \\\\-\\\\-\\\\-\\\\-\\\\-\\\\-
44+
45+
## HTML tag
46+
47+
<b>bold</b>
48+
49+
## Table
50+
51+
| Header 1 | Header 2 |
52+
| --- | --- |
53+
| Cell 1 | Cell 2 |
54+
55+
",
56+
],
57+
}
58+
`;

0 commit comments

Comments
 (0)