Unverified Commit 21e4c3f0 authored by James George's avatar James George Committed by GitHub

tests(create-next-app): leverage execa (#19008)

Leverage [execa](https://github.com/sindresorhus/execa) for writing to `stdin`.
parent 60951199
...@@ -187,31 +187,20 @@ describe('create next app', () => { ...@@ -187,31 +187,20 @@ describe('create next app', () => {
if (process.platform !== 'win32') { if (process.platform !== 'win32') {
it('should fall back to default template', async () => { it('should fall back to default template', async () => {
await usingTempDir(async (cwd) => { await usingTempDir(async (cwd) => {
const runExample = (...args) => { const projectName = 'fail-example'
const res = run(args, { cwd }) const res = await run(
[projectName, '--example', '__internal-testing-retry'],
function fallbackToTemplate(data) { {
if ( cwd,
/Do you want to use the default template instead/.test( input: '\n',
data.toString()
)
) {
res.stdout.removeListener('data', fallbackToTemplate)
res.stdin.write('\n')
}
} }
res.stdout.on('data', fallbackToTemplate)
return res
}
const res = await runExample(
'fail-example',
'--example',
'__internal-testing-retry'
) )
expect(res.exitCode).toBe(0) expect(res.exitCode).toBe(0)
const files = ['package.json', 'pages/index.js', '.gitignore']
files.forEach((file) =>
expect(fs.existsSync(path.join(cwd, projectName, file))).toBeTruthy()
)
}) })
}) })
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment