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(browser): correctly print diff #3627

Merged
merged 3 commits into from
Jun 20, 2023
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
4 changes: 3 additions & 1 deletion packages/utils/src/diff/diffLines.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,9 @@ export function diffLinesRaw(aLines: Array<string>,
}

// @ts-expect-error wrong bundling
diff.default.default(aLength, bLength, isCommon, foundSubsequence)
const diffSequences = diff.default.default || diff.default

diffSequences(aLength, bLength, isCommon, foundSubsequence)

// After the last common subsequence, push remaining change items.
for (; aIndex !== aLength; aIndex += 1)
Expand Down
6 changes: 4 additions & 2 deletions packages/utils/src/diff/diffStrings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/

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

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

// @ts-expect-error wrong bundling
diffSequences.default.default(a.length, b.length, isCommon, foundSubsequence)
const diffSequences = diff.default.default || diff.default

diffSequences(a.length, b.length, isCommon, foundSubsequence)

// After the last common subsequence, push remaining change items.
if (aIndex !== a.length)
Expand Down
16 changes: 13 additions & 3 deletions test/browser/specs/runner.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,26 @@ const { stderr, stdout } = await execa('npx', ['vitest', '--run', `--browser.nam
CI: 'true',
NO_COLOR: 'true',
},
reject: false,
})

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

assert.ok(browserResultJson.testResults.length === 7, 'Not all the tests have been run')
const passedTests = browserResultJson.testResults.filter(result => result.status === 'passed')
const failedTests = browserResultJson.testResults.filter(result => result.status === 'failed')

for (const result of browserResultJson.testResults)
assert.ok(result.status === 'passed', `${result.name} has failed`)
assert.ok(browserResultJson.testResults.length === 8, 'Not all the tests have been run')
assert.ok(passedTests.length === 7, 'Some tests failed')
assert.ok(failedTests.length === 1, 'Some tests have passed but should fail')

assert.doesNotMatch(stderr, /Unhandled Error/, 'doesn\'t have any unhandled errors')
})

await test('correctly prints error', () => {
assert.match(stderr, /expected 1 to be 2/, 'prints failing error')
assert.match(stderr, /- 2\s+\+ 1/, 'prints failing diff')
})

await test('logs are redirected to stdout', async () => {
Expand Down
5 changes: 5 additions & 0 deletions test/browser/test/failing.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { expect, it } from 'vitest'

it('correctly fails and prints a diff', () => {
expect(1).toBe(2)
})