Skip to content

Commit a18e736

Browse files
committed
refactor: use flatMap
1 parent 8607e2d commit a18e736

File tree

1 file changed

+34
-48
lines changed

1 file changed

+34
-48
lines changed

packages/markdown/tests/plugins/linksPlugin.spec.ts

+34-48
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ describe('@vuepress/markdown > plugins > linksPlugin', () => {
151151
'[readme1](readme.md)',
152152
'[readme2](../foo/bar/readme.md)',
153153
]
154-
.map((item) => {
154+
.flatMap((item) => {
155155
const link = /([^)]*)/.exec(item)![1]
156156

157157
return [
@@ -162,7 +162,6 @@ describe('@vuepress/markdown > plugins > linksPlugin', () => {
162162
item.replace(link, `${link}?a=1&b=2#hash`),
163163
]
164164
})
165-
.flat()
166165
.join('\n\n')
167166

168167
const expectRelativeLinks = [
@@ -226,15 +225,13 @@ describe('@vuepress/markdown > plugins > linksPlugin', () => {
226225
relative: '../foo/bar/readme.md',
227226
absolute: null,
228227
},
229-
]
230-
.map(({ raw, ...rest }) => [
231-
{ raw, ...rest },
232-
{ raw: `${raw}#hash`, ...rest },
233-
{ raw: `${raw}?a=1&b=2`, ...rest },
234-
{ raw: `${raw}#hash?a=1&b=2`, ...rest },
235-
{ raw: `${raw}?a=1&b=2#hash`, ...rest },
236-
])
237-
.flat()
228+
].flatMap(({ raw, ...rest }) => [
229+
{ raw, ...rest },
230+
{ raw: `${raw}#hash`, ...rest },
231+
{ raw: `${raw}?a=1&b=2`, ...rest },
232+
{ raw: `${raw}#hash?a=1&b=2`, ...rest },
233+
{ raw: `${raw}?a=1&b=2#hash`, ...rest },
234+
])
238235

239236
it('should render to <a> tag correctly', () => {
240237
const md = MarkdownIt({ html: true }).use(linksPlugin, {
@@ -259,7 +256,7 @@ describe('@vuepress/markdown > plugins > linksPlugin', () => {
259256
'<a href="index.html">readme1</a>',
260257
'<a href="../foo/bar/">readme2</a>',
261258
]
262-
.map((item) => {
259+
.flatMap((item) => {
263260
const link = /href="([^"]*)"/.exec(item)![1]
264261

265262
return [
@@ -270,7 +267,6 @@ describe('@vuepress/markdown > plugins > linksPlugin', () => {
270267
item.replace(link, `${link}?a=1&amp;b=2#hash`),
271268
]
272269
})
273-
.flat()
274270
.map((a) => `<p>${a}</p>`)
275271
.join('\n') + '\n',
276272
)
@@ -299,7 +295,7 @@ describe('@vuepress/markdown > plugins > linksPlugin', () => {
299295
'<RouteLink to="index.html">readme1</RouteLink>',
300296
'<RouteLink to="../foo/bar/">readme2</RouteLink>',
301297
]
302-
.map((item) => {
298+
.flatMap((item) => {
303299
const link = /to="([^"]*)"/.exec(item)![1]
304300

305301
return [
@@ -310,7 +306,6 @@ describe('@vuepress/markdown > plugins > linksPlugin', () => {
310306
item.replace(link, `${link}?a=1&amp;b=2#hash`),
311307
]
312308
})
313-
.flat()
314309
.map((a) => `<p>${a}</p>`)
315310
.join('\n') + '\n',
316311
)
@@ -341,7 +336,7 @@ describe('@vuepress/markdown > plugins > linksPlugin', () => {
341336
'<RouteLink to="/path/to/">readme1</RouteLink>',
342337
'<RouteLink to="/path/foo/bar/">readme2</RouteLink>',
343338
]
344-
.map((item) => {
339+
.flatMap((item) => {
345340
const link = /to="([^"]*)"/.exec(item)![1]
346341

347342
return [
@@ -352,7 +347,6 @@ describe('@vuepress/markdown > plugins > linksPlugin', () => {
352347
item.replace(link, `${link}?a=1&amp;b=2#hash`),
353348
]
354349
})
355-
.flat()
356350
.map((a) => `<p>${a}</p>`)
357351
.join('\n') + '\n',
358352
)
@@ -419,15 +413,13 @@ describe('@vuepress/markdown > plugins > linksPlugin', () => {
419413
relative: 'path/foo/bar/readme.md',
420414
absolute: '/path/foo/bar/readme.md',
421415
},
422-
]
423-
.map(({ raw, ...rest }) => [
424-
{ raw, ...rest },
425-
{ raw: `${raw}#hash`, ...rest },
426-
{ raw: `${raw}?a=1&b=2`, ...rest },
427-
{ raw: `${raw}#hash?a=1&b=2`, ...rest },
428-
{ raw: `${raw}?a=1&b=2#hash`, ...rest },
429-
])
430-
.flat(),
416+
].flatMap(({ raw, ...rest }) => [
417+
{ raw, ...rest },
418+
{ raw: `${raw}#hash`, ...rest },
419+
{ raw: `${raw}?a=1&b=2`, ...rest },
420+
{ raw: `${raw}#hash?a=1&b=2`, ...rest },
421+
{ raw: `${raw}?a=1&b=2#hash`, ...rest },
422+
]),
431423
)
432424
})
433425

@@ -456,7 +448,7 @@ describe('@vuepress/markdown > plugins > linksPlugin', () => {
456448
`<RouteLink to="/${encoded中}/${encoded文}/">readme1</RouteLink>`,
457449
`<RouteLink to="/${encoded中}/foo/bar/">readme2</RouteLink>`,
458450
]
459-
.map((item) => {
451+
.flatMap((item) => {
460452
const link = /to="([^"]*)"/.exec(item)![1]
461453

462454
return [
@@ -467,7 +459,6 @@ describe('@vuepress/markdown > plugins > linksPlugin', () => {
467459
item.replace(link, `${link}?a=1&amp;b=2#hash`),
468460
]
469461
})
470-
.flat()
471462
.map((a) => `<p>${a}</p>`)
472463
.join('\n') + '\n',
473464
)
@@ -534,15 +525,13 @@ describe('@vuepress/markdown > plugins > linksPlugin', () => {
534525
relative: `${encoded中}/foo/bar/readme.md`,
535526
absolute: `/${encoded中}/foo/bar/readme.md`,
536527
},
537-
]
538-
.map(({ raw, ...rest }) => [
539-
{ raw, ...rest },
540-
{ raw: `${raw}#hash`, ...rest },
541-
{ raw: `${raw}?a=1&b=2`, ...rest },
542-
{ raw: `${raw}#hash?a=1&b=2`, ...rest },
543-
{ raw: `${raw}?a=1&b=2#hash`, ...rest },
544-
])
545-
.flat(),
528+
].flatMap(({ raw, ...rest }) => [
529+
{ raw, ...rest },
530+
{ raw: `${raw}#hash`, ...rest },
531+
{ raw: `${raw}?a=1&b=2`, ...rest },
532+
{ raw: `${raw}#hash?a=1&b=2`, ...rest },
533+
{ raw: `${raw}?a=1&b=2#hash`, ...rest },
534+
]),
546535
)
547536
})
548537

@@ -570,7 +559,7 @@ describe('@vuepress/markdown > plugins > linksPlugin', () => {
570559
'<RouteLink to="/path/to/">readme1</RouteLink>',
571560
'<RouteLink to="/path/foo/bar/">readme2</RouteLink>',
572561
]
573-
.map((item) => {
562+
.flatMap((item) => {
574563
const link = /to="([^"]*)"/.exec(item)![1]
575564

576565
return [
@@ -581,7 +570,6 @@ describe('@vuepress/markdown > plugins > linksPlugin', () => {
581570
item.replace(link, `${link}?a=1&amp;b=2#hash`),
582571
]
583572
})
584-
.flat()
585573
.map((a) => `<p>${a}</p>`)
586574
.join('\n') + '\n',
587575
)
@@ -648,15 +636,13 @@ describe('@vuepress/markdown > plugins > linksPlugin', () => {
648636
relative: 'path/foo/bar/readme.md',
649637
absolute: '/path/path/foo/bar/readme.md',
650638
},
651-
]
652-
.map(({ raw, ...rest }) => [
653-
{ raw, ...rest },
654-
{ raw: `${raw}#hash`, ...rest },
655-
{ raw: `${raw}?a=1&b=2`, ...rest },
656-
{ raw: `${raw}#hash?a=1&b=2`, ...rest },
657-
{ raw: `${raw}?a=1&b=2#hash`, ...rest },
658-
])
659-
.flat(),
639+
].flatMap(({ raw, ...rest }) => [
640+
{ raw, ...rest },
641+
{ raw: `${raw}#hash`, ...rest },
642+
{ raw: `${raw}?a=1&b=2`, ...rest },
643+
{ raw: `${raw}#hash?a=1&b=2`, ...rest },
644+
{ raw: `${raw}?a=1&b=2#hash`, ...rest },
645+
]),
660646
)
661647
})
662648
})

0 commit comments

Comments
 (0)