diff --git a/packages/utils/src/diff/diffLines.ts b/packages/utils/src/diff/diffLines.ts index 647667d05ae7..d209930dedb6 100644 --- a/packages/utils/src/diff/diffLines.ts +++ b/packages/utils/src/diff/diffLines.ts @@ -184,7 +184,9 @@ export function diffLinesRaw(aLines: Array, } // @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) diff --git a/packages/utils/src/diff/diffStrings.ts b/packages/utils/src/diff/diffStrings.ts index 88d28c023b0c..706f001fee97 100644 --- a/packages/utils/src/diff/diffStrings.ts +++ b/packages/utils/src/diff/diffStrings.ts @@ -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 { @@ -32,7 +32,9 @@ function diffStrings(a: string, b: string): Array { } // @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) diff --git a/test/browser/specs/runner.test.mjs b/test/browser/specs/runner.test.mjs index 976cf0293f00..4670c2908ef8 100644 --- a/test/browser/specs/runner.test.mjs +++ b/test/browser/specs/runner.test.mjs @@ -11,16 +11,24 @@ 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') +}) + +await test('correctly prints error', () => { + assert.match(stderr, /expected 1 to be 2/, 'prints failing error') + assert.match(stderr, /- 1\s+\+ 2/, 'prints failing diff') }) await test('logs are redirected to stdout', async () => { diff --git a/test/browser/test/failing.test.ts b/test/browser/test/failing.test.ts new file mode 100644 index 000000000000..de541b1bf3ac --- /dev/null +++ b/test/browser/test/failing.test.ts @@ -0,0 +1,5 @@ +import { expect, it } from 'vitest' + +it('correctly fails and prints a diff', () => { + expect(1).toBe(2) +})