-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Expand file tree
/
Copy pathprocess-readme.test.mjs
More file actions
76 lines (71 loc) · 2.8 KB
/
process-readme.test.mjs
File metadata and controls
76 lines (71 loc) · 2.8 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
import processReadme from './process-readme.mjs';
describe('processReadme', () => {
const url =
'https://raw.githubusercontent.com/webpack/html-loader/master/README.md';
it('links with the site', () => {
const options = { source: url };
const loaderMDData =
'- [file-loader](https://github.com/webpack/file-loader)';
const pluginMDData =
'- [eslint-webpack-plugin](https://github.com/webpack-contrib/eslint-webpack-plugin)';
expect(processReadme(loaderMDData, options)).toEqual(
'- [file-loader](/loaders/file-loader/)'
);
expect(processReadme(pluginMDData, options)).toEqual(
'- [eslint-webpack-plugin](/plugins/eslint-webpack-plugin/)'
);
});
it('links without the site', () => {
const options = { source: url };
const loaderMDData =
'- [extract-loader](https://github.com/peerigon/extract-loader)';
const pluginMDData =
'- [html-webpack-plugin](https://github.com/jantimon/html-webpack-plugin)';
expect(processReadme(loaderMDData, options)).toEqual(
'- [extract-loader](https://github.com/peerigon/extract-loader)'
);
expect(processReadme(pluginMDData, options)).toEqual(
'- [html-webpack-plugin](https://github.com/jantimon/html-webpack-plugin)'
);
});
it('rewrite relative url', () => {
const options = {
source:
'https://raw.githubusercontent.com/webpack/postcss-loader/main/README.md',
};
const loaderMDData =
'See the file [`./src/config.d.ts`](./src/config.d.ts).';
expect(processReadme(loaderMDData, options)).toEqual(
'See the file [`https://github.com/webpack/postcss-loader/main/src/config.d.ts`](https://github.com/webpack/postcss-loader/main/src/config.d.ts).'
);
});
it('should preserve comments inside code blocks', () => {
const options = {
source:
'https://raw.githubusercontent.com/webpack/postcss-loader/main/README.md',
};
const loaderMDData = `
<!-- some comment that should be dropped -->
### Disable url resolving using the \`<!-- webpackIgnore: true -->\` comment
\`\`\`html
<!-- Disabled url handling for the src attribute -->
<!-- webpackIgnore: true -->
<img src="image.png" />
<!-- Disabled url handling for the src and srcset attributes -->
<!-- webpackIgnore: true -->
<img
srcset="image.png 480w, image.png 768w"
src="image.png"
alt="Elva dressed as a fairy"
/>
<!-- Disabled url handling for the content attribute -->
<!-- webpackIgnore: true -->
<meta itemprop="image" content="./image.png" />
<!-- Disabled url handling for the href attribute -->
<!-- webpackIgnore: true -->
<link rel="icon" type="image/png" sizes="192x192" href="./image.png" />
\`\`\`
`;
expect(processReadme(loaderMDData, options)).toMatchSnapshot();
});
});