File size: 2,671 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import { createNext, FileRef } from 'e2e-utils'
import { NextInstance } from 'e2e-utils'
import path from 'path'

const appDir = path.join(__dirname, 'app')

// react-relay is not compatible with React 19 and therefore Next.js 15
describe.skip('next/jest', () => {
  let next: NextInstance

  beforeAll(async () => {
    next = await createNext({
      files: {
        components: new FileRef(path.join(appDir, 'components')),
        pages: new FileRef(path.join(appDir, 'pages')),
        'tests/entry.test.tsx': `
        import { render, waitFor } from '@testing-library/react'
        import { RelayEnvironmentProvider } from 'react-relay'
        import { createMockEnvironment, MockPayloadGenerator } from 'relay-test-utils'
        
        import Page from '@/pages'
        
        describe('test graphql tag transformation', () => {
          it('should work', async () => {
            let environment = createMockEnvironment()
        
            const { getByText } = render(
              <RelayEnvironmentProvider environment={environment}>
                <Page />
              </RelayEnvironmentProvider>
            )
        
            environment.mock.resolveMostRecentOperation((operation) => {
              return MockPayloadGenerator.generate(operation)
            })
        
            await waitFor(() => getByText('Data requested:'))
        
            expect(getByText('Data requested:')).not.toBe(null)
          })
        })
        
        `,
        types: new FileRef(path.join(appDir, 'types')),
        'jest.config.js': new FileRef(path.join(appDir, 'jest.config.js')),
        'next.config.js': new FileRef(path.join(appDir, 'next.config.js')),
        'tsconfig.json': new FileRef(path.join(appDir, 'tsconfig.json')),
        'main.graphql': new FileRef(path.join(appDir, 'main.graphql')),
      },
      dependencies: {
        jest: '27.4.7',
        'react-relay': '13.2.0',
        '@testing-library/react': '15.0.2',
        '@types/jest': '27.4.1',
        'babel-jest': '27.5.1',
        'babel-plugin-relay': '13.2.0',
        jsdom: '19.0.0',
        'relay-compiler': '13.0.1',
        'relay-runtime': '13.0.2',
        'relay-test-utils': '13.0.2',
        typescript: '5.2.2',
      },
      packageJson: {
        scripts: {
          // Runs jest and bails if jest fails
          build: 'jest --forceExit tests/entry.test.tsx && next build',
        },
      },
      installCommand: 'pnpm i',
      buildCommand: `pnpm build`,
    })
  })
  afterAll(() => next.destroy())

  it('should work', async () => {
    // Suite fails if `jest` fails during `build`
    expect(typeof '').toBe('string')
  })
})