@@ -5,6 +5,100 @@ import { describe, expect, it } from "vitest";
55import { getZipFileContent } from "../../../playgrounds/utils" ;
66
77describe ( "build-frontend" , ( ) => {
8+ it ( "should have README.md file" , async ( ) => {
9+ const zipPath = path . resolve ( __dirname , "../dist/plugin_package.zip" ) ;
10+ const readmeContent = await getZipFileContent ( zipPath , "README.md" ) ;
11+ expect ( readmeContent ) . toBeDefined ( ) ;
12+ expect ( readmeContent ) . toContain ( "Frontend Build Playground" ) ;
13+ } ) ;
14+
15+ it ( "should transform README image links to GitHub raw URLs" , async ( ) => {
16+ const zipPath = path . resolve ( __dirname , "../dist/plugin_package.zip" ) ;
17+ const readmeContent = await getZipFileContent ( zipPath , "README.md" ) ;
18+ expect ( readmeContent ) . toBeDefined ( ) ;
19+ expect ( readmeContent ) . toContain ( "raw.githubusercontent.com" ) ;
20+ expect ( readmeContent ) . toContain ( "assets/test.txt" ) ;
21+ } ) ;
22+
23+ it ( "should remove external image URLs" , async ( ) => {
24+ const zipPath = path . resolve ( __dirname , "../dist/plugin_package.zip" ) ;
25+ const readmeContent = await getZipFileContent ( zipPath , "README.md" ) ;
26+ expect ( readmeContent ) . toBeDefined ( ) ;
27+ // External URLs should be removed (set to empty string)
28+ expect ( readmeContent ) . not . toContain ( "http://example.com/image.png" ) ;
29+ expect ( readmeContent ) . not . toContain ( "https://example.com/image.png" ) ;
30+ // data: URIs should be kept as-is (not removed)
31+ expect ( readmeContent ) . toContain ( "data:image/png;base64,abc123" ) ;
32+ // Image syntax should still exist but with empty URLs (alt text preserved)
33+ expect ( readmeContent ) . toContain ( "![External HTTP]()" ) ;
34+ expect ( readmeContent ) . toContain ( "![External HTTPS]()" ) ;
35+ expect ( readmeContent ) . toContain (
36+ "" ,
37+ ) ;
38+ } ) ;
39+
40+ it ( "should transform local markdown links to GitHub raw URLs" , async ( ) => {
41+ const zipPath = path . resolve ( __dirname , "../dist/plugin_package.zip" ) ;
42+ const readmeContent = await getZipFileContent ( zipPath , "README.md" ) ;
43+ expect ( readmeContent ) . toBeDefined ( ) ;
44+ // [Local Doc](assets/test.txt) should become a GitHub raw URL
45+ expect ( readmeContent ) . toMatch (
46+ / \[ L o c a l D o c \] \( h t t p s : \/ \/ r a w \. g i t h u b u s e r c o n t e n t \. c o m \/ .* \/ a s s e t s \/ t e s t \. t x t \) / ,
47+ ) ;
48+ } ) ;
49+
50+ it ( "should remove external markdown link URLs" , async ( ) => {
51+ const zipPath = path . resolve ( __dirname , "../dist/plugin_package.zip" ) ;
52+ const readmeContent = await getZipFileContent ( zipPath , "README.md" ) ;
53+ expect ( readmeContent ) . toBeDefined ( ) ;
54+ // External link URL should be removed but link text preserved
55+ expect ( readmeContent ) . not . toContain ( "https://example.com/docs" ) ;
56+ expect ( readmeContent ) . toContain ( "[External Link]()" ) ;
57+ } ) ;
58+
59+ it ( "should preserve fragment-only links" , async ( ) => {
60+ const zipPath = path . resolve ( __dirname , "../dist/plugin_package.zip" ) ;
61+ const readmeContent = await getZipFileContent ( zipPath , "README.md" ) ;
62+ expect ( readmeContent ) . toBeDefined ( ) ;
63+ // Same-document anchors should be preserved as-is
64+ expect ( readmeContent ) . toContain ( "[Jump to section](#purpose)" ) ;
65+ } ) ;
66+
67+ it ( "should transform reference-style definition URLs" , async ( ) => {
68+ const zipPath = path . resolve ( __dirname , "../dist/plugin_package.zip" ) ;
69+ const readmeContent = await getZipFileContent ( zipPath , "README.md" ) ;
70+ expect ( readmeContent ) . toBeDefined ( ) ;
71+ // [ref-image]: assets/test.txt should be transformed to a GitHub raw URL
72+ expect ( readmeContent ) . toMatch (
73+ / \[ r e f - i m a g e \] : \s * h t t p s : \/ \/ r a w \. g i t h u b u s e r c o n t e n t \. c o m \/ .* \/ a s s e t s \/ t e s t \. t x t / ,
74+ ) ;
75+ // [ref-link]: https://example.com/docs is external and should be removed
76+ expect ( readmeContent ) . not . toContain ( "https://example.com/docs" ) ;
77+ } ) ;
78+
79+ it ( "should transform local HTML src/href attributes" , async ( ) => {
80+ const zipPath = path . resolve ( __dirname , "../dist/plugin_package.zip" ) ;
81+ const readmeContent = await getZipFileContent ( zipPath , "README.md" ) ;
82+ expect ( readmeContent ) . toBeDefined ( ) ;
83+ // HTML <img src="assets/test.txt"> and <a href="assets/test.txt"> should be transformed
84+ expect ( readmeContent ) . toMatch (
85+ / s r c = " h t t p s : \/ \/ r a w \. g i t h u b u s e r c o n t e n t \. c o m \/ .* \/ a s s e t s \/ t e s t \. t x t " / ,
86+ ) ;
87+ expect ( readmeContent ) . toMatch (
88+ / h r e f = " h t t p s : \/ \/ r a w \. g i t h u b u s e r c o n t e n t \. c o m \/ .* \/ a s s e t s \/ t e s t \. t x t " / ,
89+ ) ;
90+ } ) ;
91+
92+ it ( "should remove external URLs in HTML attributes" , async ( ) => {
93+ const zipPath = path . resolve ( __dirname , "../dist/plugin_package.zip" ) ;
94+ const readmeContent = await getZipFileContent ( zipPath , "README.md" ) ;
95+ expect ( readmeContent ) . toBeDefined ( ) ;
96+ // External URLs in HTML should be emptied
97+ expect ( readmeContent ) . not . toContain ( "https://example.com/image.png" ) ;
98+ expect ( readmeContent ) . not . toContain ( "https://example.com/docs" ) ;
99+ expect ( readmeContent ) . toContain ( 'src=""' ) ;
100+ expect ( readmeContent ) . toContain ( 'href=""' ) ;
101+ } ) ;
8102 it ( "should have manifest.json file" , async ( ) => {
9103 const zipPath = path . resolve ( __dirname , "../dist/plugin_package.zip" ) ;
10104
0 commit comments