@@ -57,6 +57,11 @@ const urlIssues = new URL('issues/', pathRepoTestFixturesURL);
57
57
const oc = < T > ( obj : T ) => expect . objectContaining ( obj ) ;
58
58
const sm = ( m : string | RegExp ) => expect . stringMatching ( m ) ;
59
59
60
+ function expectError ( err : string | Error ) {
61
+ const message = typeof err === 'string' ? err : err . message ;
62
+ return expect . objectContaining ( { message } ) ;
63
+ }
64
+
60
65
vi . mock ( '../../../util/logger' ) ;
61
66
62
67
const mockedLogError = vi . mocked ( logError ) ;
@@ -488,9 +493,9 @@ describe('Validate search/load config files', () => {
488
493
489
494
test . each `
490
495
file | expectedConfig
491
- ${ samplesSrc } | ${ readError ( samplesSrc ) . error }
492
- ${ s ( 'bug-fixes' ) } | ${ readError ( s ( 'bug-fixes' ) ) . error }
493
- ${ s ( 'js-config/cspell-bad.js' ) } | ${ readError ( s ( 'js-config/cspell-bad.js' ) ) . error }
496
+ ${ samplesSrc } | ${ expectError ( readError ( samplesSrc ) . error ) }
497
+ ${ s ( 'bug-fixes' ) } | ${ expectError ( readError ( s ( 'bug-fixes' ) ) . error ) }
498
+ ${ s ( 'js-config/cspell-bad.js' ) } | ${ expectError ( readError ( s ( 'js-config/cspell-bad.js' ) ) . error ) }
494
499
` ( 'readConfigFile with error $file' , async ( { file, expectedConfig } : TestLoadConfig ) => {
495
500
await expect ( readConfigFile ( file ) ) . rejects . toEqual ( expectedConfig ) ;
496
501
expect ( mockedLogWarning ) . toHaveBeenCalledTimes ( 0 ) ;
@@ -502,9 +507,9 @@ describe('Validate search/load config files', () => {
502
507
${ samplesSrc } | ${ readError ( samplesSrc ) . error }
503
508
${ s ( 'bug-fixes' ) } | ${ readError ( s ( 'bug-fixes' ) ) . error }
504
509
${ s ( 'js-config/cspell-bad.js' ) } | ${ readError ( s ( 'js-config/cspell-bad.js' ) ) . error }
505
- ` ( 'ReadRawSettings with error $file' , async ( { file, expectedConfig } : TestLoadConfig ) => {
510
+ ` ( 'ReadRawSettings with error $file' , async ( { file, expectedConfig } ) => {
506
511
const result = await readRawSettings ( file ) ;
507
- expect ( result ) . toEqual ( oc ( { __importRef : oc ( { error : expectedConfig } ) } ) ) ;
512
+ expect ( result ) . toEqual ( oc ( { __importRef : oc ( { error : expectError ( expectedConfig ) } ) } ) ) ;
508
513
expect ( mockedLogWarning ) . toHaveBeenCalledTimes ( 0 ) ;
509
514
expect ( mockedLogError ) . toHaveBeenCalledTimes ( 0 ) ;
510
515
} ) ;
@@ -517,9 +522,9 @@ describe('Validate search/load config files', () => {
517
522
518
523
test . each `
519
524
file | relativeTo | expectedConfig
520
- ${ samplesSrc } | ${ undefined } | ${ readError ( samplesSrc ) . error }
521
- ${ s ( 'bug-fixes' ) } | ${ undefined } | ${ readError ( s ( 'bug-fixes' ) ) . error }
522
- ${ s ( 'bug-fixes/not-found/cspell.json' ) } | ${ undefined } | ${ readError ( s ( 'bug-fixes/not-found/cspell.json' ) ) . error }
525
+ ${ samplesSrc } | ${ undefined } | ${ expectError ( readError ( samplesSrc ) . error ) }
526
+ ${ s ( 'bug-fixes' ) } | ${ undefined } | ${ expectError ( readError ( s ( 'bug-fixes' ) ) . error ) }
527
+ ${ s ( 'bug-fixes/not-found/cspell.json' ) } | ${ undefined } | ${ expectError ( readError ( s ( 'bug-fixes/not-found/cspell.json' ) ) . error ) }
523
528
${ s ( 'dot-config/.config/cspell.config.yaml' ) } | ${ undefined } | ${ oc ( cf ( s ( 'dot-config/.config/cspell.config.yaml' ) , oc ( { name : 'Nested in .config' } ) ) ) }
524
529
${ rp ( 'cspell.config.json' ) } | ${ undefined } | ${ oc ( cf ( rp ( 'cspell.config.json' ) , oc ( { id : 'cspell-package-config' } ) ) ) }
525
530
${ s ( 'linked/cspell.config.js' ) } | ${ undefined } | ${ cf ( s ( 'linked/cspell.config.js' ) , oc ( { description : 'cspell.config.js file in samples/linked' } ) ) }
@@ -768,7 +773,7 @@ describe('ConfigLoader with VirtualFS', () => {
768
773
769
774
expect ( configFile ) . toBeInstanceOf ( Error ) ;
770
775
assert ( configFile instanceof Error ) ;
771
- expect ( configFile . cause ) . toEqual ( new Error ( `Untrusted URL: "${ location ?. href } "` ) ) ;
776
+ expect ( configFile . cause ) . toEqual ( expectError ( `Untrusted URL: "${ location ?. href } "` ) ) ;
772
777
} ) ;
773
778
} ) ;
774
779
0 commit comments