File size: 2,086 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
import { nextTestSetup } from 'e2e-utils'
import { readFileSync } from 'fs'
import { nextLint } from 'next-test-utils'

describe('next-lint-eslint-formatter-compact', () => {
  const { next } = nextTestSetup({
    files: __dirname,
    dependencies: { eslint: '^8', 'eslint-config-next': 'canary' },
  })

  it('should format flag "compact" creates a file respecting the chosen format', async () => {
    const filePath = `${next.testDir}/output/output.txt`
    const { stdout, stderr } = await nextLint(
      next.testDir,
      ['--format', 'compact', '--output-file', filePath],
      {
        stdout: true,
        stderr: true,
      }
    )

    const cliOutput = stdout + stderr
    const fileOutput = readFileSync(filePath, 'utf8')

    expect(cliOutput).toContain(`The output file has been created: ${filePath}`)

    expect(fileOutput).toContain(`${next.testDir}/pages/bar.js`)
    expect(fileOutput).toContain(
      'img elements must have an alt prop, either with meaningful text, or an empty string for decorative images.'
    )
    expect(fileOutput).toContain(
      'Using `<img>` could result in slower LCP and higher bandwidth. Consider using `<Image />` from `next/image` or a custom image loader to automatically optimize images. This may incur additional usage or cost from your provider. See: https://nextjs.org/docs/messages/no-img-element'
    )

    expect(fileOutput).toContain(`${next.testDir}/pages/index.js`)
    expect(fileOutput).toContain(
      'Synchronous scripts should not be used. See: https://nextjs.org/docs/messages/no-sync-scripts'
    )
  })

  it('should show error message when the file path is a directory', async () => {
    const filePath = next.testDir
    const { stdout, stderr } = await nextLint(
      next.testDir,
      ['--format', 'compact', '--output-file', filePath],
      {
        stdout: true,
        stderr: true,
      }
    )

    const cliOutput = stdout + stderr
    console.log({ cliOutput })
    expect(cliOutput).toContain(
      `Cannot write to output file path, it is a directory: ${filePath}`
    )
  })
})