11import type { NewPlugin } from '@vitest/pretty-format'
22import { getCurrentTest } from '@vitest/runner'
3+ import { expect , test } from 'vitest'
34
45const AlwaysFailingSnapshotSerializer : NewPlugin = {
56 test : obj => obj && obj . forceFail === true ,
@@ -11,7 +12,7 @@ expect.addSnapshotSerializer(AlwaysFailingSnapshotSerializer)
1112
1213test ( 'expect.soft tracks an error for toMatchSnapshot' , ( ) => {
1314 expect . soft ( { forceFail : true } ) . toMatchSnapshot ( )
14-
15+
1516 expect ( getCurrentTest ( ) ?. result ?. errors ) . toHaveLength ( 1 )
1617 expect ( getCurrentTest ( ) ?. result ?. state ) . toBe ( 'fail' )
1718 passTestIfInFailedStateWithErrors ( )
@@ -20,47 +21,47 @@ test('expect.soft tracks an error for toMatchSnapshot', () => {
2021test ( 'expect.soft tracks multiple errors for toMatchSnapshot' , ( ) => {
2122 expect . soft ( { forceFail : true } ) . toMatchSnapshot ( )
2223 expect . soft ( { forceFail : true } ) . toMatchSnapshot ( )
23-
24+
2425 expect ( getCurrentTest ( ) ?. result ?. errors ) . toHaveLength ( 2 )
2526 expect ( getCurrentTest ( ) ?. result ?. state ) . toBe ( 'fail' )
2627 passTestIfInFailedStateWithErrors ( )
2728} )
2829
2930test ( 'expect.soft tracks errors across successes for toMatchSnapshot' , ( ) => {
30- expect . soft ( 'I have a matching snapshot' ) . toMatchSnapshot ( ) ;
31+ expect . soft ( 'I have a matching snapshot' ) . toMatchSnapshot ( )
3132 expect . soft ( { forceFail : true } ) . toMatchSnapshot ( )
32- expect . soft ( 'I also have a matching snapshot' ) . toMatchSnapshot ( ) ;
33+ expect . soft ( 'I also have a matching snapshot' ) . toMatchSnapshot ( )
3334 expect . soft ( { forceFail : true } ) . toMatchSnapshot ( )
34- expect . soft ( 'Yet another matching snapshot' ) . toMatchSnapshot ( ) ;
35-
35+ expect . soft ( 'Yet another matching snapshot' ) . toMatchSnapshot ( )
36+
3637 expect ( getCurrentTest ( ) ?. result ?. errors ) . toHaveLength ( 2 )
3738 expect ( getCurrentTest ( ) ?. result ?. state ) . toBe ( 'fail' )
3839 passTestIfInFailedStateWithErrors ( )
3940} )
4041
4142test ( 'expect.soft tracks errors for matchSnapshot' , ( ) => {
4243 expect . soft ( { forceFail : true } ) . matchSnapshot ( )
43- expect . soft ( 'I also have a matching snapshot' ) . toMatchSnapshot ( ) ;
44+ expect . soft ( 'I also have a matching snapshot' ) . toMatchSnapshot ( )
4445 expect . soft ( { forceFail : true } ) . matchSnapshot ( )
45-
46+
4647 expect ( getCurrentTest ( ) ?. result ?. errors ) . toHaveLength ( 2 )
4748 expect ( getCurrentTest ( ) ?. result ?. state ) . toBe ( 'fail' )
4849 passTestIfInFailedStateWithErrors ( )
4950} )
5051
51- test ( 'expect.soft tracks errors for toMatchFileSnapshot' , async ( ) => {
52+ test ( 'expect.soft tracks errors for toMatchFileSnapshot' , async ( ) => {
5253 await expect . soft ( { forceFail : true } ) . toMatchFileSnapshot ( 'fake-path/to-non-existent/file' )
53- expect . soft ( 'Another matching snapshot' ) . toMatchSnapshot ( ) ;
54+ expect . soft ( 'Another matching snapshot' ) . toMatchSnapshot ( )
5455 await expect . soft ( { forceFail : true } ) . toMatchFileSnapshot ( 'fake-path/to-non-existent/file' )
55-
56+
5657 expect ( getCurrentTest ( ) ?. result ?. errors ) . toHaveLength ( 2 )
5758 expect ( getCurrentTest ( ) ?. result ?. state ) . toBe ( 'fail' )
5859 passTestIfInFailedStateWithErrors ( )
5960} )
6061
61- test ( 'expect.soft tracks errors for toThrowErrorMatchingSnapshot' , async ( ) => {
62+ test ( 'expect.soft tracks errors for toThrowErrorMatchingSnapshot' , async ( ) => {
6263 expect . soft ( { forceFail : true } ) . toThrowErrorMatchingSnapshot ( )
63- expect . soft ( 'Yet another matching snapshot' ) . toMatchSnapshot ( ) ;
64+ expect . soft ( 'Yet another matching snapshot' ) . toMatchSnapshot ( )
6465 expect . soft ( { forceFail : true } ) . toThrowErrorMatchingSnapshot ( )
6566
6667 expect ( getCurrentTest ( ) ?. result ?. errors ) . toHaveLength ( 2 )
@@ -70,9 +71,8 @@ test('expect.soft tracks errors for toThrowErrorMatchingSnapshot', async() => {
7071
7172function passTestIfInFailedStateWithErrors ( ) {
7273 const result = getCurrentTest ( ) ! . result !
73-
74+
7475 if ( result . errors && result . state === 'fail' ) {
75- result . state = 'pass'
76+ result . state = 'pass'
7677 }
7778}
78-
0 commit comments