Skip to content

Commit d756ee2

Browse files
authoredJun 20, 2023
fix(browser): correctly print diff (#3627)
1 parent 60c36fa commit d756ee2

File tree

4 files changed

+25
-6
lines changed

4 files changed

+25
-6
lines changed
 

‎packages/utils/src/diff/diffLines.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,9 @@ export function diffLinesRaw(aLines: Array<string>,
184184
}
185185

186186
// @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)
188190

189191
// After the last common subsequence, push remaining change items.
190192
for (; aIndex !== aLength; aIndex += 1)

‎packages/utils/src/diff/diffStrings.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8-
import * as diffSequences from 'diff-sequences'
8+
import * as diff from 'diff-sequences'
99
import { DIFF_DELETE, DIFF_EQUAL, DIFF_INSERT, Diff } from './cleanupSemantic'
1010

1111
function diffStrings(a: string, b: string): Array<Diff> {
@@ -32,7 +32,9 @@ function diffStrings(a: string, b: string): Array<Diff> {
3232
}
3333

3434
// @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)
3638

3739
// After the last common subsequence, push remaining change items.
3840
if (aIndex !== a.length)

‎test/browser/specs/runner.test.mjs

+13-3
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,26 @@ const { stderr, stdout } = await execa('npx', ['vitest', '--run', `--browser.nam
1111
CI: 'true',
1212
NO_COLOR: 'true',
1313
},
14+
reject: false,
1415
})
1516

1617
await test('tests are actually running', async () => {
1718
const browserResult = await readFile('./browser.json', 'utf-8')
1819
const browserResultJson = JSON.parse(browserResult)
1920

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')
2123

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')
2434
})
2535

2636
await test('logs are redirected to stdout', async () => {

‎test/browser/test/failing.test.ts

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { expect, it } from 'vitest'
2+
3+
it('correctly fails and prints a diff', () => {
4+
expect(1).toBe(2)
5+
})

0 commit comments

Comments
 (0)
Please sign in to comment.