Skip to content

Commit

Permalink
test(snapshot): allow snapshot test not invalidate with --turbo
Browse files Browse the repository at this point in the history
  • Loading branch information
kwonoj committed Dec 5, 2022
1 parent fa42c34 commit 1148815
Show file tree
Hide file tree
Showing 9 changed files with 842 additions and 163 deletions.
Expand Up @@ -2,6 +2,7 @@ import { sandbox } from './helpers'
import { createNext, FileRef } from 'e2e-utils'
import { NextInstance } from 'test/lib/next-modes/base'
import path from 'path'
import { shouldRunTurboDevTest } from 'next-test-utils'

// TODO-APP: Investigate snapshot mismatch
describe('ReactRefreshLogBox app', () => {
Expand Down Expand Up @@ -59,7 +60,20 @@ describe('ReactRefreshLogBox app', () => {
`
)
expect(await session.hasRedbox(true)).toBe(true)
expect(await session.getRedboxSource()).toMatchSnapshot()
if (!shouldRunTurboDevTest()) {
expect(await session.getRedboxSource()).toMatchSnapshot()
} else {
expect(await session.getRedboxSource()).toMatchInlineSnapshot(`
"./node_modules/my-package/index.js:2:0
Module not found: Can't resolve 'dns'
Import trace for requested module:
./index.js
./app/page.js
https://nextjs.org/docs/messages/module-not-found"
`)
}

await cleanup()
})
Expand All @@ -83,7 +97,23 @@ describe('ReactRefreshLogBox app', () => {
expect(await session.hasRedbox(true)).toBe(true)

const source = await session.getRedboxSource()
expect(source).toMatchSnapshot()
if (!shouldRunTurboDevTest()) {
expect(source).toMatchSnapshot()
} else {
expect(source).toMatchInlineSnapshot(`
"./index.js:1:0
Module not found: Can't resolve 'b'
> 1 | import Comp from 'b'
2 | export default function Oops() {
3 | return (
4 | <div>
Import trace for requested module:
./app/page.js
https://nextjs.org/docs/messages/module-not-found"
`)
}

await cleanup()
})
Expand All @@ -108,7 +138,22 @@ describe('ReactRefreshLogBox app', () => {
expect(await session.hasRedbox(true)).toBe(true)

const source = await session.getRedboxSource()
expect(source).toMatchSnapshot()
if (!shouldRunTurboDevTest()) {
expect(source).toMatchSnapshot()
} else {
expect(source).toMatchInlineSnapshot(`
"./app/page.js:2:6
Module not found: Can't resolve 'b'
1 | 'use client'
> 2 | import Comp from 'b'
| ^
3 | export default function Oops() {
4 | return (
5 | <div>
https://nextjs.org/docs/messages/module-not-found"
`)
}

await cleanup()
})
Expand All @@ -131,7 +176,22 @@ describe('ReactRefreshLogBox app', () => {
expect(await session.hasRedbox(true)).toBe(true)

const source = await session.getRedboxSource()
expect(source).toMatchSnapshot()
if (!shouldRunTurboDevTest()) {
expect(source).toMatchSnapshot()
} else {
expect(source).toMatchInlineSnapshot(`
"./app/page.js:2:10
Module not found: Can't resolve './non-existent.css'
1 | 'use client'
> 2 | import './non-existent.css'
| ^
3 | export default function Page(props) {
4 | return <p>index page</p>
5 | }
https://nextjs.org/docs/messages/module-not-found"
`)
}

await session.patch(
'app/page.js',
Expand Down
13 changes: 11 additions & 2 deletions test/development/acceptance-app/ReactRefreshLogBox-scss.test.ts
Expand Up @@ -3,6 +3,7 @@ import { sandbox } from './helpers'
import { createNext, FileRef } from 'e2e-utils'
import { NextInstance } from 'test/lib/next-modes/base'
import path from 'path'
import { shouldRunTurboDevTest } from 'next-test-utils'

// TODO: figure out why snapshots mismatch on GitHub actions
// specifically but work in docker and locally
Expand Down Expand Up @@ -51,13 +52,21 @@ describe.skip('ReactRefreshLogBox app', () => {
await session.patch('index.module.scss', `.button { font-size: :5px; }`)
expect(await session.hasRedbox(true)).toBe(true)
const source = await session.getRedboxSource()
expect(source).toMatchSnapshot()
if (!shouldRunTurboDevTest()) {
expect(source).toMatchSnapshot()
} else {
expect(source).toMatchInlineSnapshot()
}

// Not local error
await session.patch('index.module.scss', `button { font-size: 5px; }`)
expect(await session.hasRedbox(true)).toBe(true)
const source2 = await session.getRedboxSource()
expect(source2).toMatchSnapshot()
if (!shouldRunTurboDevTest()) {
expect(source2).toMatchSnapshot()
} else {
expect(source2).toMatchInlineSnapshot()
}

await cleanup()
})
Expand Down

0 comments on commit 1148815

Please sign in to comment.