-
Notifications
You must be signed in to change notification settings - Fork 27.2k
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
test(cna): split and refactor #63921
Merged
Merged
Changes from 15 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
8b3dc2f
test: split tests and refactor package-managers
devjiwonchoi 749ac73
test: share default files
devjiwonchoi d1a8513
chore: fully replace package-manager test
devjiwonchoi bce8fe4
test: migrate app test
devjiwonchoi cb7e507
test: split pages only tests
devjiwonchoi 1cd8c57
refactor: use no-import-alias for default import alias
devjiwonchoi d1627c7
test: replace templates pages
devjiwonchoi aecf25a
chore: remove unnecessary ansi-escapes
devjiwonchoi 51dbf18
fix: example path to full example path
devjiwonchoi 7e10d48
chore: move base to prompts
devjiwonchoi ed4ff56
test: split index to examples and prompts
devjiwonchoi 1e0677c
fix: tests for default fallback
devjiwonchoi 1bd7abb
Merge branch 'canary' into refactor/test-cna
devjiwonchoi 7c2bb35
fix: pass user agent as env
devjiwonchoi 658357d
chore: add comment for GH#57025
devjiwonchoi 76e77e8
Merge branch 'canary' into refactor/test-cna
ijjk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,256 @@ | ||
import { | ||
EXAMPLE_PATH, | ||
EXAMPLE_REPO, | ||
FULL_EXAMPLE_PATH, | ||
projectFilesShouldExist, | ||
projectFilesShouldNotExist, | ||
shouldBeTemplateProject, | ||
run, | ||
useTempDir, | ||
} from './utils' | ||
|
||
describe('create-next-app --example', () => { | ||
it('should create on valid Next.js example name', async () => { | ||
await useTempDir(async (cwd) => { | ||
const projectName = 'valid-example' | ||
const res = await run([projectName, '--example', 'basic-css'], { | ||
cwd, | ||
}) | ||
expect(res.exitCode).toBe(0) | ||
projectFilesShouldExist({ | ||
cwd, | ||
projectName, | ||
files: [ | ||
'.gitignore', | ||
'package.json', | ||
'app/page.tsx', | ||
'app/layout.tsx', | ||
'node_modules/next', | ||
], | ||
}) | ||
}) | ||
}) | ||
|
||
it('should create with GitHub URL', async () => { | ||
await useTempDir(async (cwd) => { | ||
const projectName = 'github-url' | ||
const res = await run([projectName, '--example', FULL_EXAMPLE_PATH], { | ||
cwd, | ||
}) | ||
|
||
expect(res.exitCode).toBe(0) | ||
projectFilesShouldExist({ | ||
cwd, | ||
projectName, | ||
files: [ | ||
'.gitignore', | ||
'package.json', | ||
'app/page.tsx', | ||
'app/layout.tsx', | ||
'node_modules/next', | ||
], | ||
}) | ||
}) | ||
}) | ||
|
||
it('should create with GitHub URL trailing slash', async () => { | ||
await useTempDir(async (cwd) => { | ||
const projectName = 'github-url-trailing-slash' | ||
const res = await run( | ||
[ | ||
projectName, | ||
'--example', | ||
// since vercel/examples is not a template repo, we use the following | ||
// GH#39665 | ||
'https://github.com/vercel/nextjs-portfolio-starter/', | ||
], | ||
{ | ||
cwd, | ||
} | ||
) | ||
|
||
expect(res.exitCode).toBe(0) | ||
projectFilesShouldExist({ | ||
cwd, | ||
projectName, | ||
files: [ | ||
'.gitignore', | ||
'package.json', | ||
'pages/index.mdx', | ||
'node_modules/next', | ||
], | ||
}) | ||
}) | ||
}) | ||
|
||
it('should create with GitHub URL and --example-path', async () => { | ||
await useTempDir(async (cwd) => { | ||
const projectName = 'github-url-and-example-path' | ||
const res = await run( | ||
[ | ||
projectName, | ||
'--js', | ||
'--no-tailwind', | ||
'--eslint', | ||
'--example', | ||
EXAMPLE_REPO, | ||
'--example-path', | ||
EXAMPLE_PATH, | ||
], | ||
{ | ||
cwd, | ||
} | ||
) | ||
|
||
expect(res.exitCode).toBe(0) | ||
projectFilesShouldExist({ | ||
cwd, | ||
projectName, | ||
files: [ | ||
'.gitignore', | ||
'package.json', | ||
'app/page.tsx', | ||
'app/layout.tsx', | ||
'node_modules/next', | ||
], | ||
}) | ||
}) | ||
}) | ||
|
||
it('should use --example-path over the GitHub URL', async () => { | ||
await useTempDir(async (cwd) => { | ||
const projectName = 'example-path-over-github-url' | ||
const res = await run( | ||
[ | ||
projectName, | ||
'--js', | ||
'--no-tailwind', | ||
'--eslint', | ||
'--example', | ||
FULL_EXAMPLE_PATH, | ||
'--example-path', | ||
EXAMPLE_PATH, | ||
], | ||
{ | ||
cwd, | ||
} | ||
) | ||
|
||
expect(res.exitCode).toBe(0) | ||
projectFilesShouldExist({ | ||
cwd, | ||
projectName, | ||
files: [ | ||
'.gitignore', | ||
'package.json', | ||
'app/page.tsx', | ||
'app/layout.tsx', | ||
'node_modules/next', | ||
], | ||
}) | ||
}) | ||
}) | ||
|
||
// TODO: investigate why this test stalls on yarn install when | ||
// stdin is piped instead of inherited on windows | ||
if (process.platform !== 'win32') { | ||
it('should fall back to default template if failed to download', async () => { | ||
await useTempDir(async (cwd) => { | ||
const projectName = 'fallback-to-default' | ||
const res = await run( | ||
[ | ||
projectName, | ||
'--js', | ||
'--no-tailwind', | ||
'--eslint', | ||
'--app', | ||
'--example', | ||
'__internal-testing-retry', | ||
'--import-alias=@/*', | ||
], | ||
{ | ||
cwd, | ||
input: '\n', // 'Yes' to retry | ||
stdio: 'pipe', | ||
} | ||
) | ||
|
||
expect(res.exitCode).toBe(0) | ||
shouldBeTemplateProject({ | ||
cwd, | ||
projectName, | ||
template: 'app', | ||
mode: 'js', | ||
}) | ||
}) | ||
}) | ||
} | ||
|
||
it('should create if --example value is default', async () => { | ||
await useTempDir(async (cwd) => { | ||
const projectName = 'example-default' | ||
const res = await run( | ||
[ | ||
projectName, | ||
'--js', | ||
'--no-tailwind', | ||
'--eslint', | ||
'--example', | ||
'default', | ||
'--import-alias=@/*', | ||
], | ||
{ | ||
cwd, | ||
} | ||
) | ||
|
||
expect(res.exitCode).toBe(0) | ||
shouldBeTemplateProject({ | ||
cwd, | ||
projectName, | ||
template: 'default', | ||
mode: 'js', | ||
}) | ||
}) | ||
}) | ||
|
||
it('should not create if --example flag value is invalid', async () => { | ||
await useTempDir(async (cwd) => { | ||
const projectName = 'invalid-example' | ||
const res = await run([projectName, '--example', 'not a real example'], { | ||
cwd, | ||
reject: false, | ||
}) | ||
|
||
expect(res.exitCode).toBe(1) | ||
projectFilesShouldNotExist({ | ||
cwd, | ||
projectName, | ||
files: ['package.json'], | ||
}) | ||
}) | ||
}) | ||
|
||
it('should not create if --example flag value is absent', async () => { | ||
await useTempDir(async (cwd) => { | ||
const projectName = 'no-example' | ||
const res = await run( | ||
[ | ||
projectName, | ||
'--ts', | ||
'--app', | ||
'--eslint', | ||
'--no-src-dir', | ||
'--no-tailwind', | ||
'--example', | ||
], | ||
{ | ||
cwd, | ||
reject: false, | ||
} | ||
) | ||
|
||
expect(res.exitCode).toBe(1) | ||
}) | ||
}) | ||
}) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed unused ansi-escapes