fix(nextjs): Adding styles to nextjs cypress should not fail. (#22170)
This commit is contained in:
parent
bf1dcdc986
commit
391f3ab8e6
@ -90,6 +90,14 @@ describe('NextJs Component Testing', () => {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should test a NextJs server component that uses router', async () => {
|
||||||
|
const lib = uniq('next-lib');
|
||||||
|
createLibWithCtCypress(lib);
|
||||||
|
if (runE2ETests()) {
|
||||||
|
expect(runCLI(`component-test ${lib}`)).toContain('All specs passed!');
|
||||||
|
}
|
||||||
|
}, 600_000);
|
||||||
});
|
});
|
||||||
|
|
||||||
function addBabelSupport(path: string) {
|
function addBabelSupport(path: string) {
|
||||||
@ -203,6 +211,49 @@ export default Button;
|
|||||||
`generate @nx/next:cypress-component-configuration --project=${libName} --generate-tests --no-interactive`
|
`generate @nx/next:cypress-component-configuration --project=${libName} --generate-tests --no-interactive`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function createLibWithCtCypress(libName: string) {
|
||||||
|
runCLI(
|
||||||
|
`generate @nx/next:lib ${libName} --no-interactive --projectNameAndRootFormat=as-provided`
|
||||||
|
);
|
||||||
|
|
||||||
|
runCLI(
|
||||||
|
`generate @nx/next:cypress-component-configuration --project=${libName} --no-interactive`
|
||||||
|
);
|
||||||
|
|
||||||
|
updateFile(`${libName}/src/lib/hello-server.tsx`, () => {
|
||||||
|
return `import { useRouter } from 'next/router';
|
||||||
|
|
||||||
|
export function HelloServer() {
|
||||||
|
useRouter();
|
||||||
|
|
||||||
|
return <h1>Hello Server</h1>;
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
});
|
||||||
|
// Add cypress component test
|
||||||
|
createFile(
|
||||||
|
`${libName}/src/lib/hello-server.cy.tsx`,
|
||||||
|
`import * as Router from 'next/router';
|
||||||
|
import { HelloServer } from './hello-server';
|
||||||
|
|
||||||
|
describe('HelloServer', () => {
|
||||||
|
context('stubbing out \`useRouter\` hook', () => {
|
||||||
|
let router;
|
||||||
|
beforeEach(() => {
|
||||||
|
router = cy.stub();
|
||||||
|
|
||||||
|
cy.stub(Router, 'useRouter').returns(router);
|
||||||
|
});
|
||||||
|
it('should work', () => {
|
||||||
|
cy.mount(<HelloServer />);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
`
|
||||||
|
);
|
||||||
|
}
|
||||||
function addTailwindToLib(libName: string) {
|
function addTailwindToLib(libName: string) {
|
||||||
createFile(`libs/${libName}/src/lib/styles.css`, ``);
|
createFile(`libs/${libName}/src/lib/styles.css`, ``);
|
||||||
runCLI(
|
runCLI(
|
||||||
|
|||||||
@ -97,6 +97,7 @@ function normalizeOptions(
|
|||||||
return {
|
return {
|
||||||
addPlugin,
|
addPlugin,
|
||||||
...options,
|
...options,
|
||||||
|
framework: options.framework ?? null,
|
||||||
directory: options.directory ?? 'cypress',
|
directory: options.directory ?? 'cypress',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,7 +5,10 @@
|
|||||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||||
<meta name="viewport" content="width=device-width,initial-scale=1.0">
|
<meta name="viewport" content="width=device-width,initial-scale=1.0">
|
||||||
<title><%= project %> Components App</title>
|
<title><%= project %> Components App</title>
|
||||||
|
<% if(framework === 'next') { %>
|
||||||
|
<!-- Used by Next.js to inject CSS. -->
|
||||||
|
<div id="__next_css__DO_NOT_USE__"></div>
|
||||||
|
<% } %>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div data-cy-root></div>
|
<div data-cy-root></div>
|
||||||
|
|||||||
@ -10,4 +10,5 @@ export interface CypressComponentConfigurationSchema {
|
|||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
addExplicitTargets?: boolean;
|
addExplicitTargets?: boolean;
|
||||||
|
framework?: 'next';
|
||||||
}
|
}
|
||||||
|
|||||||
@ -39,6 +39,7 @@ export async function cypressComponentConfigurationInternal(
|
|||||||
await baseCyCtConfig(tree, {
|
await baseCyCtConfig(tree, {
|
||||||
project: options.project,
|
project: options.project,
|
||||||
skipFormat: true,
|
skipFormat: true,
|
||||||
|
framework: 'next',
|
||||||
jsx: true,
|
jsx: true,
|
||||||
addPlugin: options.addPlugin,
|
addPlugin: options.addPlugin,
|
||||||
})
|
})
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user