Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix when "update snapshots" message is displayed #trivial #356

Merged
merged 1 commit into from
Jul 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/JestExt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down
30 changes: 29 additions & 1 deletion tests/JestExt.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { updateCurrentDiagnostics } from '../src/diagnostics'
describe('JestExt', () => {
const getConfiguration = workspace.getConfiguration as jest.Mock<any>
let projectWorkspace: ProjectWorkspace
const channelStub = { appendLine: () => {} } as any
const channelStub = { appendLine: () => {}, clear: () => {} } as any
// const mockShowErrorMessage = window.showErrorMessage as jest.Mock<any>
// const mockShowWarningMessage = window.showWarningMessage as jest.Mock<any>
const extensionSettings = { debugCodeLens: {} } as any
Expand Down Expand Up @@ -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)
})
})
})