rsnext/test/integration/create-next-app/index.test.js
Joe Haddad 104d18c607
Rewrite Create Next App (#8030)
* Completely rewrite Create Next App

* Sort imports

* Show what package manager is being used

* Fix project name suggestion

* Update tests for new implementation

* Use normal prepublish command for on-install

* Upgrade Node version

* Switch to 8.16

* Disable v8 cache

* Swap out update check package and fix CLI boot
2019-07-19 15:55:30 -04:00

80 lines
2 KiB
JavaScript

/* eslint-env jest */
import mkdirpModule from 'mkdirp'
import path from 'path'
import fs from 'fs'
import execa from 'execa'
import os from 'os'
import { promisify } from 'util'
const mkdirp = promisify(mkdirpModule)
const cli = require.resolve('create-next-app/dist/index.js')
const cwd = path.join(
os.tmpdir(),
Math.random()
.toString(36)
.substring(2)
)
const run = (...args) => execa('node', [cli, ...args], { cwd })
describe('create next app', () => {
beforeAll(async () => {
jest.setTimeout(1000 * 30)
await mkdirp(cwd)
})
it('non-empty directory', async () => {
const projectName = 'non-empty-directory'
await mkdirp(path.join(cwd, projectName))
const pkg = path.join(cwd, projectName, 'package.json')
fs.writeFileSync(pkg, '{ "foo": "bar" }')
expect.assertions(1)
try {
await run(projectName)
} catch (e) {
expect(e.stdout).toMatch(/contains files that could conflict/)
}
})
it('empty directory', async () => {
const projectName = 'empty-directory'
const res = await run(projectName)
expect(res.exitCode).toBe(0)
expect(
fs.existsSync(path.join(cwd, projectName, 'package.json'))
).toBeTruthy()
expect(
fs.existsSync(path.join(cwd, projectName, 'pages/index.js'))
).toBeTruthy()
})
it('invalid example name', async () => {
const projectName = 'invalid-example-name'
expect.assertions(2)
try {
await run(projectName, '--example', 'not a real example')
} catch (e) {
expect(e.stderr).toMatch(/Could not locate an example named/i)
}
expect(
fs.existsSync(path.join(cwd, projectName, 'package.json'))
).toBeFalsy()
})
it('valid example', async () => {
const projectName = 'valid-example'
const res = await run(projectName, '--example', 'basic-css')
expect(res.exitCode).toBe(0)
expect(
fs.existsSync(path.join(cwd, projectName, 'package.json'))
).toBeTruthy()
expect(
fs.existsSync(path.join(cwd, projectName, 'pages/index.js'))
).toBeTruthy()
})
})