Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update CNA tests on windows for further investigating #11779

Merged
merged 2 commits into from
Apr 9, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 49 additions & 41 deletions test/integration/create-next-app/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const runStarter = (...args) => {

describe('create next app', () => {
beforeAll(async () => {
jest.setTimeout(1000 * 60 * 3)
jest.setTimeout(1000 * 60 * 2)
await fs.mkdirp(cwd)
})

Expand All @@ -47,18 +47,22 @@ describe('create next app', () => {
}
})

it('empty directory', async () => {
const projectName = 'empty-directory'
const res = await runStarter(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()
})
// TODO: investigate why this test stalls on yarn install when
// stdin is piped instead of inherited on windows
if (process.platform !== 'win32') {
it('empty directory', async () => {
const projectName = 'empty-directory'
const res = await runStarter(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'
Expand Down Expand Up @@ -163,41 +167,45 @@ describe('create next app', () => {
).toBeTruthy()
})

it('should allow to manually select an example', async () => {
const runExample = (...args) => {
const res = run(...args)

function pickExample(data) {
if (/hello-world/.test(data.toString())) {
res.stdout.removeListener('data', pickExample)
res.stdin.write('\n')
// TODO: investigate why this test stalls on yarn install when
// stdin is piped instead of inherited on windows
if (process.platform !== 'win32') {
it('should allow to manually select an example', async () => {
const runExample = (...args) => {
const res = run(...args)

function pickExample(data) {
if (/hello-world/.test(data.toString())) {
res.stdout.removeListener('data', pickExample)
res.stdin.write('\n')
}
}
}

function searchExample(data) {
if (/Pick an example/.test(data.toString())) {
res.stdout.removeListener('data', searchExample)
res.stdin.write('hello-world')
res.stdout.on('data', pickExample)
function searchExample(data) {
if (/Pick an example/.test(data.toString())) {
res.stdout.removeListener('data', searchExample)
res.stdin.write('hello-world')
res.stdout.on('data', pickExample)
}
}
}

function selectExample(data) {
if (/Pick a template/.test(data.toString())) {
res.stdout.removeListener('data', selectExample)
res.stdin.write('\u001b[B\n') // Down key and enter
res.stdout.on('data', searchExample)
function selectExample(data) {
if (/Pick a template/.test(data.toString())) {
res.stdout.removeListener('data', selectExample)
res.stdin.write('\u001b[B\n') // Down key and enter
res.stdout.on('data', searchExample)
}
}
}

res.stdout.on('data', selectExample)
res.stdout.on('data', selectExample)

return res
}
return res
}

const res = await runExample('no-example')
const res = await runExample('no-example')

expect(res.exitCode).toBe(0)
expect(res.stdout).toMatch(/Downloading files for example hello-world/)
})
expect(res.exitCode).toBe(0)
expect(res.stdout).toMatch(/Downloading files for example hello-world/)
})
}
})