Skip to content

Commit

Permalink
feat: make jest snapshots easier to read/compare
Browse files Browse the repository at this point in the history
  • Loading branch information
beeman committed Nov 9, 2023
1 parent 495aca4 commit f011912
Show file tree
Hide file tree
Showing 7 changed files with 5,940 additions and 1,058 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ describe('application generator', () => {

const config = readProjectConfiguration(tree, options.name)
const contents = getRecursiveFileContents(tree, config.root)
const stringified = JSON.stringify(contents, null, 2)
expect(stringified).toMatchSnapshot()
expect(contents).toMatchSnapshot()

const rootTsConfig = tree.read('tsconfig.base.json').toString()
expect(rootTsConfig).toMatchSnapshot()
Expand Down
11 changes: 9 additions & 2 deletions packages/preset-common/src/utils/get-gecursive-file-contents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Tree } from '@nx/devkit'

export interface FileContents {
path: string
content?: string
content?: string | string[]
isBinary?: boolean
children?: Record<string, FileContents>
}
Expand Down Expand Up @@ -40,7 +40,7 @@ export function getRecursiveFileContents(tree: Tree, path: string, includeBinari
contents[file] = {
path: `${path}/${file}`,
isBinary,
content: isBinary ? binaryContent : content.toString('utf-8'),
content: isBinary ? binaryContent : formatOutput(content.toString('utf-8')),
}
} else {
contents[file] = {
Expand All @@ -52,3 +52,10 @@ export function getRecursiveFileContents(tree: Tree, path: string, includeBinari

return contents
}

export function formatOutput(value: string) {
return value
.split('\n')
.map((line) => line.trim())
.filter((line) => line.length > 0)
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ describe('application generator', () => {
expect(anchorConfig).toBeDefined()

const contents = getRecursiveFileContents(tree, '.')
const stringified = JSON.stringify(contents, null, 2)
expect(stringified).toMatchSnapshot()
expect(contents).toMatchSnapshot()
})
})

Expand Down
Loading

0 comments on commit f011912

Please sign in to comment.