rsnext/test/unit/write-app-declarations.test.ts
JJ Kasper 7bb247ca8f
Move styled-jsx type reference (#37964)
Follow-up to https://github.com/vercel/next.js/pull/37902 this moves the reference to avoid a change in `next-env.d.ts`. Also updates our doc note on the `next-env.d.ts` file to be more explicit about it being ignored.

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [x] Make sure the linting passes by running `pnpm lint`
- [ ] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)
2022-06-23 19:26:08 +00:00

74 lines
2.3 KiB
TypeScript

/* eslint-env jest */
import os from 'os'
import fs from 'fs-extra'
import { join } from 'path'
import { writeAppTypeDeclarations } from 'next/dist/lib/typescript/writeAppTypeDeclarations'
const fixtureDir = join(__dirname, 'fixtures/app-declarations')
const declarationFile = join(fixtureDir, 'next-env.d.ts')
const imageImportsEnabled = false
describe('find config', () => {
afterEach(() => fs.remove(declarationFile))
it('should preserve CRLF EOL', async () => {
const eol = '\r\n'
const content =
'/// <reference types="next" />' +
eol +
(imageImportsEnabled
? '/// <reference types="next/image-types/global" />' + eol
: '') +
eol +
'// NOTE: This file should not be edited' +
eol +
'// see https://nextjs.org/docs/basic-features/typescript for more information.' +
eol
await fs.ensureDir(fixtureDir)
await fs.writeFile(declarationFile, content)
await writeAppTypeDeclarations(fixtureDir, imageImportsEnabled)
expect(await fs.readFile(declarationFile, 'utf8')).toBe(content)
})
it('should preserve LF EOL', async () => {
const eol = '\n'
const content =
'/// <reference types="next" />' +
eol +
(imageImportsEnabled
? '/// <reference types="next/image-types/global" />' + eol
: '') +
eol +
'// NOTE: This file should not be edited' +
eol +
'// see https://nextjs.org/docs/basic-features/typescript for more information.' +
eol
await fs.ensureDir(fixtureDir)
await fs.writeFile(declarationFile, content)
await writeAppTypeDeclarations(fixtureDir, imageImportsEnabled)
expect(await fs.readFile(declarationFile, 'utf8')).toBe(content)
})
it('should use OS EOL by default', async () => {
const eol = os.EOL
const content =
'/// <reference types="next" />' +
eol +
(imageImportsEnabled
? '/// <reference types="next/image-types/global" />' + eol
: '') +
eol +
'// NOTE: This file should not be edited' +
eol +
'// see https://nextjs.org/docs/basic-features/typescript for more information.' +
eol
await fs.ensureDir(fixtureDir)
await writeAppTypeDeclarations(fixtureDir, imageImportsEnabled)
expect(await fs.readFile(declarationFile, 'utf8')).toBe(content)
})
})