Skip to content

Commit

Permalink
chore(zui): refactor testing + speed up some important tests (#382)
Browse files Browse the repository at this point in the history
  • Loading branch information
franklevasseur authored Sep 27, 2024
1 parent 5a77496 commit 0acfad9
Show file tree
Hide file tree
Showing 4 changed files with 278 additions and 264 deletions.
13 changes: 10 additions & 3 deletions zui/src/setup.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { expect } from 'vitest'
import { Project, Diagnostic } from 'ts-morph'
import { format } from 'prettier'

export function isValidTypescript(
code: string,
Expand Down Expand Up @@ -31,11 +32,17 @@ expect.extend({
},
})

const formatTs = async (code: string): Promise<string> => {
code = code.replace(/\s+/g, ' ')
code = await format(code, { parser: 'typescript' })
return code
}

expect.extend({
toMatchWithoutFormatting(received: string, expected: string, _) {
async toMatchWithoutFormatting(received: string, expected: string, _) {
const { isNot } = this
const transformedReceived = received.replace(/\s+/g, '')
const transformedExpected = expected.replace(/\s+/g, '')
const transformedReceived = await formatTs(received)
const transformedExpected = await formatTs(expected)

return {
pass: transformedExpected === transformedReceived,
Expand Down
Loading

0 comments on commit 0acfad9

Please sign in to comment.