rsnext/test/integration/create-next-app/index.test.js
JJ Kasper c1cbad0155 Update tests running and add splitting by timings for Azure (#10214)
* Add splitting by timings for Azure

* Add --timings flag for azure

* Update timings API

* Update timings var

* Fix test directory not being reset before re-trying

* Update to re-use CircleCI timing data

* Bump concurrency for Azure

* Remove extra logging

* Update timeout for create-next-app tests

Co-authored-by: Joe Haddad <timer150@gmail.com>
2020-01-23 12:37:01 -05:00

84 lines
2.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 * 60)
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()
// check we copied default `.gitignore`
expect(
fs.existsSync(path.join(cwd, projectName, '.gitignore'))
).toBeTruthy()
})
})