11import * as fs from 'node:fs' ;
2- import { dirname , join } from 'node:path' ;
32
43import { expect , it , vi } from 'vitest' ;
54
65import { logger } from 'storybook/internal/node-logger' ;
76
7+ import { dirname , join , normalize } from 'pathe' ;
8+
89import * as m from './common-preset' ;
910
1011// mock src/core-server/utils/constants.ts:8:27
@@ -75,67 +76,73 @@ it('with no staticDirs favicon should return default', async () => {
7576it ( 'with staticDirs referencing a favicon.ico directly should return the found favicon' , async ( ) => {
7677 const location = 'favicon.ico' ;
7778 existsSyncMock . mockImplementation ( ( p ) => {
78- return p === createPath ( location ) ;
79+ return normalize ( String ( p ) ) === normalize ( createPath ( location ) ) ;
7980 } ) ;
8081 statSyncMock . mockImplementation ( ( p ) => {
8182 return {
82- isFile : ( ) => p === createPath ( 'favicon.ico' ) ,
83+ isFile : ( ) => normalize ( String ( p ) ) === normalize ( createPath ( 'favicon.ico' ) ) ,
8384 } as any ;
8485 } ) ;
8586 const options = createOptions ( [ location ] ) ;
8687
87- expect ( await m . favicon ( undefined , options ) ) . toBe ( createPath ( 'favicon.ico' ) ) ;
88+ expect ( normalize ( await m . favicon ( undefined , options ) ) ) . toBe ( normalize ( createPath ( 'favicon.ico' ) ) ) ;
8889} ) ;
8990
9091it ( 'with staticDirs containing a single favicon.ico should return the found favicon' , async ( ) => {
9192 const location = 'static' ;
9293 existsSyncMock . mockImplementation ( ( p ) => {
93- if ( p === createPath ( location ) ) {
94+ if ( normalize ( String ( p ) ) === normalize ( createPath ( location ) ) ) {
9495 return true ;
9596 }
96- if ( p === createPath ( location , 'favicon.ico' ) ) {
97+ if ( normalize ( String ( p ) ) === normalize ( createPath ( location , 'favicon.ico' ) ) ) {
9798 return true ;
9899 }
99100 return false ;
100101 } ) ;
101102 const options = createOptions ( [ location ] ) ;
102103
103- expect ( await m . favicon ( undefined , options ) ) . toBe ( createPath ( location , 'favicon.ico' ) ) ;
104+ expect ( normalize ( await m . favicon ( undefined , options ) ) ) . toBe (
105+ normalize ( createPath ( location , 'favicon.ico' ) )
106+ ) ;
104107} ) ;
105108
106109it ( 'with staticDirs containing a single favicon.svg should return the found favicon' , async ( ) => {
107110 const location = 'static' ;
108111 existsSyncMock . mockImplementation ( ( p ) => {
109- if ( p === createPath ( location ) ) {
112+ if ( normalize ( String ( p ) ) === normalize ( createPath ( location ) ) ) {
110113 return true ;
111114 }
112- if ( p === createPath ( location , 'favicon.svg' ) ) {
115+ if ( normalize ( String ( p ) ) === normalize ( createPath ( location , 'favicon.svg' ) ) ) {
113116 return true ;
114117 }
115118 return false ;
116119 } ) ;
117120 const options = createOptions ( [ location ] ) ;
118121
119- expect ( await m . favicon ( undefined , options ) ) . toBe ( createPath ( location , 'favicon.svg' ) ) ;
122+ expect ( normalize ( await m . favicon ( undefined , options ) ) ) . toBe (
123+ normalize ( createPath ( location , 'favicon.svg' ) )
124+ ) ;
120125} ) ;
121126
122127it ( 'with staticDirs containing a multiple favicons should return the first favicon and warn' , async ( ) => {
123128 const location = 'static' ;
124129 existsSyncMock . mockImplementation ( ( p ) => {
125- if ( p === createPath ( location ) ) {
130+ if ( normalize ( String ( p ) ) === normalize ( createPath ( location ) ) ) {
126131 return true ;
127132 }
128- if ( p === createPath ( location , 'favicon.ico' ) ) {
133+ if ( normalize ( String ( p ) ) === normalize ( createPath ( location , 'favicon.ico' ) ) ) {
129134 return true ;
130135 }
131- if ( p === createPath ( location , 'favicon.svg' ) ) {
136+ if ( normalize ( String ( p ) ) === normalize ( createPath ( location , 'favicon.svg' ) ) ) {
132137 return true ;
133138 }
134139 return false ;
135140 } ) ;
136141 const options = createOptions ( [ location ] ) ;
137142
138- expect ( await m . favicon ( undefined , options ) ) . toBe ( createPath ( location , 'favicon.svg' ) ) ;
143+ expect ( normalize ( await m . favicon ( undefined , options ) ) ) . toBe (
144+ normalize ( createPath ( location , 'favicon.svg' ) )
145+ ) ;
139146
140147 expect ( logger . warn ) . toHaveBeenCalledWith ( expect . stringContaining ( 'multiple favicons' ) ) ;
141148} ) ;
@@ -144,23 +151,25 @@ it('with multiple staticDirs containing a multiple favicons should return the fi
144151 const locationA = 'static-a' ;
145152 const locationB = 'static-b' ;
146153 existsSyncMock . mockImplementation ( ( p ) => {
147- if ( p === createPath ( locationA ) ) {
154+ if ( normalize ( String ( p ) ) === normalize ( createPath ( locationA ) ) ) {
148155 return true ;
149156 }
150- if ( p === createPath ( locationB ) ) {
157+ if ( normalize ( String ( p ) ) === normalize ( createPath ( locationB ) ) ) {
151158 return true ;
152159 }
153- if ( p === createPath ( locationA , 'favicon.ico' ) ) {
160+ if ( normalize ( String ( p ) ) === normalize ( createPath ( locationA , 'favicon.ico' ) ) ) {
154161 return true ;
155162 }
156- if ( p === createPath ( locationB , 'favicon.svg' ) ) {
163+ if ( normalize ( String ( p ) ) === normalize ( createPath ( locationB , 'favicon.svg' ) ) ) {
157164 return true ;
158165 }
159166 return false ;
160167 } ) ;
161168 const options = createOptions ( [ locationA , locationB ] ) ;
162169
163- expect ( await m . favicon ( undefined , options ) ) . toBe ( createPath ( locationA , 'favicon.ico' ) ) ;
170+ expect ( normalize ( await m . favicon ( undefined , options ) ) ) . toBe (
171+ normalize ( createPath ( locationA , 'favicon.ico' ) )
172+ ) ;
164173
165174 expect ( logger . warn ) . toHaveBeenCalledWith ( expect . stringContaining ( 'multiple favicons' ) ) ;
166175} ) ;
0 commit comments