Skip to content

Commit

Permalink
fix(nextjs): Add spec files when creating a next app (#22079)
Browse files Browse the repository at this point in the history
  • Loading branch information
ndcunningham authored and jaysoo committed Mar 4, 2024
1 parent c284d3d commit 285a543
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 16 deletions.
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() {
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
3 changes: 2 additions & 1 deletion packages/next/src/generators/application/application.spec.ts
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

0 comments on commit 285a543

Please sign in to comment.