Skip to content

Commit

Permalink
add test removing react, react-dom
Browse files Browse the repository at this point in the history
  • Loading branch information
devjiwonchoi committed Aug 15, 2024
1 parent 90181d4 commit 1f39cfc
Show file tree
Hide file tree
Showing 5 changed files with 216 additions and 0 deletions.
8 changes: 8 additions & 0 deletions test/e2e/app-dir/no-react/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { ReactNode } from 'react'
export default function Root({ children }: { children: ReactNode }) {
return (
<html>
<body>{children}</body>
</html>
)
}
3 changes: 3 additions & 0 deletions test/e2e/app-dir/no-react/app/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function Page() {
return <p>hello world</p>
}
6 changes: 6 additions & 0 deletions test/e2e/app-dir/no-react/next.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**
* @type {import('next').NextConfig}
*/
const nextConfig = {}

module.exports = nextConfig
13 changes: 13 additions & 0 deletions test/e2e/app-dir/no-react/no-react.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { nextTestSetup } from 'e2e-utils'

describe('no-react', () => {
const { next } = nextTestSetup({
files: __dirname,
installCommand: 'pnpm remove react react-dom',
})

it('should work using cheerio without react, react-dom', async () => {
const $ = await next.render$('/')
expect($('p').text()).toBe('hello world')
})
})
186 changes: 186 additions & 0 deletions test/integration/create-next-app/templates/app-api.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
import { join } from 'node:path'
import {
projectShouldHaveNoGitChanges,
tryNextDev,
run,
useTempDir,
projectFilesShouldExist,
} from '../utils'
import { mapSrcFiles, projectSpecification } from '../lib/specification'
import { projectDepsShouldBe } from '../lib/utils'

function shouldBeApiTemplateProject({
cwd,
projectName,
mode,
srcDir,
}: {
cwd: string
projectName: string
mode: 'js' | 'ts'
srcDir?: boolean
}) {
const template = 'app-api'

projectFilesShouldExist({
cwd,
projectName,
files: mapSrcFiles(projectSpecification[template][mode].files, srcDir),
})

projectDepsShouldBe({
type: 'dependencies',
cwd,
projectName,
deps: mapSrcFiles(projectSpecification[template][mode].deps, srcDir),
})

projectDepsShouldBe({
type: 'devDependencies',
cwd,
projectName,
deps: mapSrcFiles(projectSpecification[template][mode].devDeps, srcDir),
})
}

describe('create-next-app --api (Headless App)', () => {
let nextTgzFilename: string

// beforeAll(() => {
// if (!process.env.NEXT_TEST_PKG_PATHS) {
// throw new Error('This test needs to be run with `node run-tests.js`.')
// }

// const pkgPaths = new Map<string, string>(
// JSON.parse(process.env.NEXT_TEST_PKG_PATHS)
// )

// nextTgzFilename = pkgPaths.get('next')!
// })

it('should create JavaScript project with --js flag', async () => {
await useTempDir(async (cwd) => {
const projectName = 'app-js'
const { exitCode } = await run(
[
projectName,
'--js',
'--api',
'--no-turbo',
'--no-src-dir',
'--no-import-alias',
],
nextTgzFilename,
{
cwd,
}
)

expect(exitCode).toBe(0)
shouldBeApiTemplateProject({
cwd,
projectName,
mode: 'js',
})
await tryNextDev({
cwd,
isApi: true,

Check failure on line 87 in test/integration/create-next-app/templates/app-api.test.ts

View workflow job for this annotation

GitHub Actions / types and precompiled / build

Object literal may only specify known properties, but 'isApi' does not exist in type '{ cwd: string; projectName: string; isApp?: boolean; isEmpty?: boolean; }'. Did you mean to write 'isApp'?
projectName,
})
})
})

it('should create TypeScript project with --ts flag', async () => {
await useTempDir(async (cwd) => {
const projectName = 'app-ts'
const { exitCode } = await run(
[
projectName,
'--ts',
'--api',
'--no-turbo',
'--no-src-dir',
'--no-import-alias',
],
nextTgzFilename,
{
cwd,
}
)

expect(exitCode).toBe(0)
shouldBeApiTemplateProject({
cwd,
projectName,
mode: 'ts',
})
await tryNextDev({ cwd, isApi: true, projectName })

Check failure on line 117 in test/integration/create-next-app/templates/app-api.test.ts

View workflow job for this annotation

GitHub Actions / types and precompiled / build

Object literal may only specify known properties, but 'isApi' does not exist in type '{ cwd: string; projectName: string; isApp?: boolean; isEmpty?: boolean; }'. Did you mean to write 'isApp'?
projectShouldHaveNoGitChanges({ cwd, projectName })
})
})

it('should create project inside "src" directory with --src-dir flag', async () => {
await useTempDir(async (cwd) => {
const projectName = 'app-src-dir'
const { exitCode } = await run(
[
projectName,
'--ts',
'--api',
'--no-turbo',
'--src-dir',
'--no-import-alias',
],
nextTgzFilename,
{
cwd,
stdio: 'inherit',
}
)

expect(exitCode).toBe(0)
shouldBeApiTemplateProject({
cwd,
projectName,
mode: 'ts',
srcDir: true,
})
await tryNextDev({
cwd,
isApi: true,

Check failure on line 150 in test/integration/create-next-app/templates/app-api.test.ts

View workflow job for this annotation

GitHub Actions / types and precompiled / build

Object literal may only specify known properties, but 'isApi' does not exist in type '{ cwd: string; projectName: string; isApp?: boolean; isEmpty?: boolean; }'. Did you mean to write 'isApp'?
projectName,
})
})
})

it('should enable turbopack dev with --turbo flag', async () => {
await useTempDir(async (cwd) => {
const projectName = 'app-turbo'
const { exitCode } = await run(
[
projectName,
'--ts',
'--api',
'--turbo',
'--no-src-dir',
'--no-import-alias',
],
nextTgzFilename,
{
cwd,
}
)

expect(exitCode).toBe(0)
const projectRoot = join(cwd, projectName)
const pkgJson = require(join(projectRoot, 'package.json'))
expect(pkgJson.scripts.dev).toBe('next dev --turbo')

await tryNextDev({
cwd,
isApi: true,

Check failure on line 181 in test/integration/create-next-app/templates/app-api.test.ts

View workflow job for this annotation

GitHub Actions / types and precompiled / build

Object literal may only specify known properties, but 'isApi' does not exist in type '{ cwd: string; projectName: string; isApp?: boolean; isEmpty?: boolean; }'. Did you mean to write 'isApp'?
projectName,
})
})
})
})

0 comments on commit 1f39cfc

Please sign in to comment.