11import { afterEach , describe , expect , it , vi } from 'vitest' ;
22
3+ import { resolveModulePath } from 'exsolve' ;
4+
35import { validateFrameworkName } from './validate-config' ;
46
7+ // mock exsolve to spy
8+ vi . mock ( 'exsolve' , { spy : true } ) ;
9+
510describe ( 'validateFrameworkName' , ( ) => {
611 afterEach ( ( ) => {
712 vi . resetAllMocks ( ) ;
@@ -20,21 +25,20 @@ describe('validateFrameworkName', () => {
2025 } ) ;
2126
2227 it ( 'should not throw if framework is unknown (community) but can be resolved' , ( ) => {
23- // mock require.resolve to return a value
24- vi . spyOn ( require , 'resolve' ) . mockReturnValue ( 'some-community-framework' ) ;
25- expect ( ( ) => validateFrameworkName ( 'some-community-framework' ) ) . toThrow ( ) ;
28+ vi . mocked ( resolveModulePath ) . mockImplementation ( ( ) => { } ) ;
29+
30+ expect ( ( ) => validateFrameworkName ( 'some-community-framework' ) ) . not . toThrow ( ) ;
2631 } ) ;
2732
2833 it ( 'should not throw if scoped framework is unknown (community) but can be resolved' , ( ) => {
29- // mock require.resolve to return a value
30- vi . spyOn ( require , 'resolve' ) . mockReturnValue ( '@some-community/framework' ) ;
34+ vi . mocked ( resolveModulePath ) . mockImplementation ( ( ) => { } ) ;
35+
3136 expect ( ( ) => validateFrameworkName ( '@some-community/framework' ) ) . not . toThrow ( ) ;
32- } ) ;
37+ } ) ;
3338
3439 it ( 'should throw if framework is unknown and cannot be resolved' , ( ) => {
35- // mock require.resolve to fail
36- vi . spyOn ( require , 'resolve' ) . mockImplementation ( ( ) => {
37- throw new Error ( 'Cannot resolve' ) ;
40+ vi . mocked ( resolveModulePath ) . mockImplementation ( ( ) => {
41+ throw new Error ( 'cannot resolve' ) ;
3842 } ) ;
3943
4044 expect ( ( ) => validateFrameworkName ( 'foo' ) ) . toThrow ( ) ;
0 commit comments