|
| 1 | +import { describe, expect, it } from 'vitest' |
| 2 | +import { linkifyModuleSpecifiers } from '../../../../server/utils/code-highlight' |
| 3 | + |
| 4 | +describe('linkifyModuleSpecifiers', () => { |
| 5 | + const dependencies = { |
| 6 | + 'vue': { version: '3.4.0' }, |
| 7 | + '@unocss/webpack': { version: '0.65.3' }, |
| 8 | + } |
| 9 | + |
| 10 | + it('should linkify import ... from "package"', () => { |
| 11 | + // Shiki output for: import { ref } from "vue" |
| 12 | + const html = |
| 13 | + '<span class="line">' + |
| 14 | + '<span style="color:#F97583">import</span>' + |
| 15 | + '<span style="color:#E1E4E8"> { ref }</span>' + |
| 16 | + '<span style="color:#F97583">from</span>' + |
| 17 | + '<span style="color:#9ECBFF"> "vue"</span>' + |
| 18 | + '</span>' |
| 19 | + |
| 20 | + const result = linkifyModuleSpecifiers(html, { dependencies }) |
| 21 | + expect(result).toContain('<a href="/package-code/vue/v/3.4.0" class="import-link">') |
| 22 | + }) |
| 23 | + |
| 24 | + it('should linkify export * from "package"', () => { |
| 25 | + // Shiki output for: export * from "@unocss/webpack" |
| 26 | + // Note: Shiki puts a leading space before "from" in the same span |
| 27 | + const html = |
| 28 | + '<span class="line">' + |
| 29 | + '<span style="color:#F97583">export</span>' + |
| 30 | + '<span style="color:#E1E4E8"> *</span>' + |
| 31 | + '<span style="color:#F97583"> from</span>' + |
| 32 | + '<span style="color:#9ECBFF"> "@unocss/webpack"</span>' + |
| 33 | + '<span style="color:#E1E4E8">;</span>' + |
| 34 | + '</span>' |
| 35 | + |
| 36 | + const result = linkifyModuleSpecifiers(html, { dependencies }) |
| 37 | + expect(result).toContain( |
| 38 | + '<a href="/package-code/@unocss/webpack/v/0.65.3" class="import-link">', |
| 39 | + ) |
| 40 | + }) |
| 41 | +}) |
0 commit comments