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

fix(nextjs): Add spec files when creating a next app #22079

Merged
merged 1 commit into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion e2e/next-core/src/next-appdir.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe('Next.js App Router', () => {
import React from 'react';
import { ${jsLib} } from '@${proj}/${jsLib}';

export default async function Page() {
export default function Page() {
Copy link
Contributor Author

@ndcunningham ndcunningham Feb 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Next.js by default generates functions/pages that are not async, for pages/ and app/ routing conventions. We should follow the same assumption.

return (
<p>{${jsLib}()}</p>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
exports[`app --style styled-jsx should use <style jsx> in index page 1`] = `
"'use client';

export default async function Index() {
export default function Index() {
/*
* Replace the elements below with your own.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,8 @@ describe('app', () => {
});
});

describe('--style @emotion/styled', () => {
// Support for emotion is still being worked on disable for now: https://nextjs.org/docs/app/building-your-application/styling/css-in-js
xdescribe('--style @emotion/styled', () => {
it('should generate @emotion/styled styles', async () => {
const name = uniq();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
const StyledPage = styled.div`<%- pageStyleContent %>`;
<% }%>
<% } %>
export default async function Index() {
export default function Index() {
/*
* Replace the elements below with your own.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import React from 'react';
import { render } from '@testing-library/react';
<% if (src) { %>
<% if (src && !appDir) { %>
import Index from '../src/pages/index';
<% } else { %>
<% } else if (!appDir) { %>
import Index from '../pages/index';
<% } else if (appDir && src) {%>
import Page from '../src/app/page';
<% } else { %>
import Page from '../app/page';
<% } %>
describe('Index', () => {

describe(<%- appDir ? `'Page'` : `'Index'` %>, () => {
it('should render successfully', () => {
const { baseElement } = render(<Index />);
const { baseElement } = render(<%- appDir ? `<Page />` : `<Index />` %>);
expect(baseElement).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,15 @@ export function createApplicationFiles(host: Tree, options: NormalizedSchema) {
templateVariables
);

// RSC is not possible to unit test without extra helpers for data fetching. Leaving it to the user to figure out.
host.delete(
joinPathFragments(
options.appProjectRoot,
'specs',
`index.spec.${options.js ? 'jsx' : 'tsx'}`
)
);
if (options.unitTestRunner === 'none') {
host.delete(
joinPathFragments(
options.appProjectRoot,
'specs',
`index.spec.${options.js ? 'jsx' : 'tsx'}`
)
);
}

if (options.style === 'styled-components') {
generateFiles(
Expand Down