diff --git a/src/JestExt.ts b/src/JestExt.ts index 7175c4bfd..26ab0e270 100644 --- a/src/JestExt.ts +++ b/src/JestExt.ts @@ -124,7 +124,7 @@ export class JestExt { } // thanks Qix, http://stackoverflow.com/questions/25245716/remove-all-ansi-colors-styles-from-strings const noANSI = message.replace(/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g, '') - if (noANSI.includes('snapshot test failed')) { + if (/(snapshot failed)|(snapshot test failed)/i.test(noANSI)) { this.detectedSnapshotErrors() } diff --git a/tests/JestExt.test.ts b/tests/JestExt.test.ts index d647957f1..5c542234b 100644 --- a/tests/JestExt.test.ts +++ b/tests/JestExt.test.ts @@ -18,7 +18,7 @@ import { updateCurrentDiagnostics } from '../src/diagnostics' describe('JestExt', () => { const getConfiguration = workspace.getConfiguration as jest.Mock let projectWorkspace: ProjectWorkspace - const channelStub = { appendLine: () => {} } as any + const channelStub = { appendLine: () => {}, clear: () => {} } as any // const mockShowErrorMessage = window.showErrorMessage as jest.Mock // const mockShowWarningMessage = window.showWarningMessage as jest.Mock const extensionSettings = { debugCodeLens: {} } as any @@ -468,4 +468,32 @@ describe('JestExt', () => { expect(mockEditor.setDecorations).toHaveBeenCalledTimes(6) }) }) + + describe('detectedSnapshotErrors()', () => { + let sut: JestExt + const mockEditor: any = { document: { uri: { fsPath: `file://a/b/c.js` } } } + + const settings: any = { + debugCodeLens: {}, + enableSnapshotUpdateMessages: true, + } + + beforeEach(() => { + jest.resetAllMocks() + const projectWorkspace = new ProjectWorkspace(null, null, null, null) + sut = new JestExt(null, projectWorkspace, channelStub, settings) + + mockEditor.setDecorations = jest.fn() + sut.debugCodeLensProvider.didChange = jest.fn() + }) + + it('will trigger snapshot update message when a snapshot test fails', () => { + window.showInformationMessage = jest.fn(async () => null) + const spy = jest.spyOn(sut as any, 'detectedSnapshotErrors') + ;(sut as any).handleStdErr(new Error('Snapshot test failed')) + ;(sut as any).handleStdErr(new Error('Snapshot failed')) + ;(sut as any).handleStdErr(new Error('Failed for some other reason')) + expect(spy).toHaveBeenCalledTimes(2) + }) + }) })