[READ-ONLY] Mirror of https://github.com/vitest-dev/vitest. Next generation testing framework powered by Vite. vitest.dev
test testing-tools vite
12

Configure Feed

Select the types of activity you want to include in your feed.

fix(browser): correctly print diff (#3627)

authored by

Vladimir and committed by
GitHub
(Jun 20, 2023, 10:04 AM +0200) d756ee24 60c36faf

+25 -6
+13 -3
test/browser/specs/runner.test.mjs
··· 11 11 CI: 'true', 12 12 NO_COLOR: 'true', 13 13 }, 14 + reject: false, 14 15 }) 15 16 16 17 await test('tests are actually running', async () => { 17 18 const browserResult = await readFile('./browser.json', 'utf-8') 18 19 const browserResultJson = JSON.parse(browserResult) 19 20 20 - assert.ok(browserResultJson.testResults.length === 7, 'Not all the tests have been run') 21 + const passedTests = browserResultJson.testResults.filter(result => result.status === 'passed') 22 + const failedTests = browserResultJson.testResults.filter(result => result.status === 'failed') 21 23 22 - for (const result of browserResultJson.testResults) 23 - assert.ok(result.status === 'passed', `${result.name} has failed`) 24 + assert.ok(browserResultJson.testResults.length === 8, 'Not all the tests have been run') 25 + assert.ok(passedTests.length === 7, 'Some tests failed') 26 + assert.ok(failedTests.length === 1, 'Some tests have passed but should fail') 27 + 28 + assert.doesNotMatch(stderr, /Unhandled Error/, 'doesn\'t have any unhandled errors') 29 + }) 30 + 31 + await test('correctly prints error', () => { 32 + assert.match(stderr, /expected 1 to be 2/, 'prints failing error') 33 + assert.match(stderr, /- 2\s+\+ 1/, 'prints failing diff') 24 34 }) 25 35 26 36 await test('logs are redirected to stdout', async () => {
+5
test/browser/test/failing.test.ts
··· 1 + import { expect, it } from 'vitest' 2 + 3 + it('correctly fails and prints a diff', () => { 4 + expect(1).toBe(2) 5 + })
+3 -1
packages/utils/src/diff/diffLines.ts
··· 184 184 } 185 185 186 186 // @ts-expect-error wrong bundling 187 - diff.default.default(aLength, bLength, isCommon, foundSubsequence) 187 + const diffSequences = diff.default.default || diff.default 188 + 189 + diffSequences(aLength, bLength, isCommon, foundSubsequence) 188 190 189 191 // After the last common subsequence, push remaining change items. 190 192 for (; aIndex !== aLength; aIndex += 1)
+4 -2
packages/utils/src/diff/diffStrings.ts
··· 5 5 * LICENSE file in the root directory of this source tree. 6 6 */ 7 7 8 - import * as diffSequences from 'diff-sequences' 8 + import * as diff from 'diff-sequences' 9 9 import { DIFF_DELETE, DIFF_EQUAL, DIFF_INSERT, Diff } from './cleanupSemantic' 10 10 11 11 function diffStrings(a: string, b: string): Array<Diff> { ··· 32 32 } 33 33 34 34 // @ts-expect-error wrong bundling 35 - diffSequences.default.default(a.length, b.length, isCommon, foundSubsequence) 35 + const diffSequences = diff.default.default || diff.default 36 + 37 + diffSequences(a.length, b.length, isCommon, foundSubsequence) 36 38 37 39 // After the last common subsequence, push remaining change items. 38 40 if (aIndex !== a.length)