@@ -140,22 +140,35 @@ describe('createOgpElement', () => {
140140} ) ;
141141
142142describe ( 'getBlogEntries' , ( ) => {
143- it ( 'collects md and mdx files, skips underscored entries, and falls back to the slug' , async ( ) => {
144- const readdirImpl = vi . fn ( async ( ) => [
145- { name : 'first-post.mdx' , isFile : ( ) => true } ,
146- { name : 'second-post.md' , isFile : ( ) => true } ,
147- { name : '_draft-post.mdx' , isFile : ( ) => true } ,
148- { name : 'images' , isFile : ( ) => false } ,
149- { name : 'notes.txt' , isFile : ( ) => true } ,
150- ] ) ;
143+ it ( 'collects localized md and mdx files, skips underscored entries, and falls back to the slug' , async ( ) => {
144+ const readdirImpl = vi
145+ . fn ( )
146+ . mockResolvedValueOnce ( [
147+ { name : 'ja' , isFile : ( ) => false , isDirectory : ( ) => true } ,
148+ { name : 'en' , isFile : ( ) => false , isDirectory : ( ) => true } ,
149+ { name : 'notes.txt' , isFile : ( ) => true , isDirectory : ( ) => false } ,
150+ ] )
151+ . mockResolvedValueOnce ( [
152+ { name : 'first-post.mdx' , isFile : ( ) => true } ,
153+ { name : 'second-post.md' , isFile : ( ) => true } ,
154+ { name : '_draft-post.mdx' , isFile : ( ) => true } ,
155+ { name : 'images' , isFile : ( ) => false } ,
156+ { name : 'notes.txt' , isFile : ( ) => true } ,
157+ ] )
158+ . mockResolvedValueOnce ( [
159+ { name : 'first-post.mdx' , isFile : ( ) => true } ,
160+ { name : '_english-draft.mdx' , isFile : ( ) => true } ,
161+ ] ) ;
151162 const readFileImpl = vi
152163 . fn ( )
153164 . mockResolvedValueOnce ( '---\ntitle: First Post\n---' )
154- . mockResolvedValueOnce ( '---\ndescription: No title\n---' ) ;
165+ . mockResolvedValueOnce ( '---\ndescription: No title\n---' )
166+ . mockResolvedValueOnce ( '---\ntitle: First Post in English\n---' ) ;
155167 const matterImpl = vi
156168 . fn ( )
157169 . mockReturnValueOnce ( { data : { title : 'First Post' } } )
158- . mockReturnValueOnce ( { data : { } } ) ;
170+ . mockReturnValueOnce ( { data : { } } )
171+ . mockReturnValueOnce ( { data : { title : 'First Post in English' } } ) ;
159172
160173 await expect (
161174 getBlogEntries ( {
@@ -177,7 +190,16 @@ describe('getBlogEntries', () => {
177190 title : 'second-post' ,
178191 isBasicPage : false ,
179192 } ,
193+ {
194+ slug : 'first-post' ,
195+ filename : 'en/first-post' ,
196+ title : 'First Post in English' ,
197+ isBasicPage : false ,
198+ } ,
180199 ] ) ;
200+
201+ expect ( readFileImpl ) . toHaveBeenCalledWith ( '/virtual/blog/ja/first-post.mdx' , 'utf-8' ) ;
202+ expect ( readFileImpl ) . toHaveBeenCalledWith ( '/virtual/blog/en/first-post.mdx' , 'utf-8' ) ;
181203 } ) ;
182204
183205 it ( 'returns an empty list when reading blog entries fails' , async ( ) => {
@@ -375,18 +397,25 @@ describe('runBuildOgp', () => {
375397 ) ;
376398 } ) ;
377399
378- it ( 'generates default pages and blog entries in normal mode' , async ( ) => {
400+ it ( 'generates default pages and blog entries in normal mode, including nested output paths ' , async ( ) => {
379401 const writeFileImpl = vi . fn ( ) ;
402+ const mkdirImpl = vi . fn ( ) ;
380403 const createOgpImage = vi . fn ( async ( target ) => Buffer . from ( target . filename ) ) ;
381404 const logger = createLogger ( ) ;
382405 const getBlogEntriesMock = vi . fn ( async ( ) => [
383406 { slug : 'first-post' , filename : 'first-post' , title : 'First Post' , isBasicPage : false } ,
407+ {
408+ slug : 'first-post' ,
409+ filename : 'en/first-post' ,
410+ title : 'First Post in English' ,
411+ isBasicPage : false ,
412+ } ,
384413 ] ) ;
385414
386415 const result = await runBuildOgp ( {
387416 argv : [ 'node' , 'scripts/build-ogp.js' ] ,
388417 outputDir : '/virtual/output' ,
389- mkdirImpl : vi . fn ( ) ,
418+ mkdirImpl,
390419 writeFileImpl,
391420 loadFonts : vi . fn ( async ( ) => [ createFont ( ) ] ) ,
392421 createOgpImage,
@@ -395,13 +424,15 @@ describe('runBuildOgp', () => {
395424 } ) ;
396425
397426 expect ( getBlogEntriesMock ) . toHaveBeenCalledOnce ( ) ;
398- expect ( result . generatedCount ) . toBe ( basicPages . length + 1 ) ;
427+ expect ( result . generatedCount ) . toBe ( basicPages . length + 2 ) ;
399428 expect ( result . targets . at ( - 1 ) ) . toEqual ( {
400429 slug : 'first-post' ,
401- filename : 'first-post' ,
402- title : 'First Post' ,
430+ filename : 'en/ first-post' ,
431+ title : 'First Post in English ' ,
403432 isBasicPage : false ,
404433 } ) ;
434+ expect ( mkdirImpl ) . toHaveBeenCalledWith ( '/virtual/output' , { recursive : true } ) ;
435+ expect ( mkdirImpl ) . toHaveBeenCalledWith ( '/virtual/output/en' , { recursive : true } ) ;
405436 expect ( writeFileImpl ) . toHaveBeenCalledWith (
406437 '/virtual/output/default.png' ,
407438 Buffer . from ( 'default' )
@@ -410,5 +441,9 @@ describe('runBuildOgp', () => {
410441 '/virtual/output/first-post.png' ,
411442 Buffer . from ( 'first-post' )
412443 ) ;
444+ expect ( writeFileImpl ) . toHaveBeenCalledWith (
445+ '/virtual/output/en/first-post.png' ,
446+ Buffer . from ( 'en/first-post' )
447+ ) ;
413448 } ) ;
414449} ) ;
0 commit comments