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

Mock Next.js in page router tests #1489

Merged
merged 3 commits into from
Oct 12, 2023
Merged

Mock Next.js in page router tests #1489

merged 3 commits into from
Oct 12, 2023

Conversation

adamjmcgrath
Copy link
Contributor

@adamjmcgrath adamjmcgrath commented Oct 12, 2023

📋 Changes

Mock out the next test app for page router tests - since standing up a next app for every test is too expensive for the CI (didn't work in GH actions and was flakey on CircleCI)

Before:
image

After:
image

🎯 Testing

Tested on GH actions https://github.com/auth0/nextjs-auth0/actions/runs/6494889625/job/17638727581

@adamjmcgrath adamjmcgrath requested a review from a team as a code owner October 12, 2023 11:29
@vercel
Copy link

vercel bot commented Oct 12, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
nextjs-auth0 ⬜️ Ignored (Inspect) Visit Preview Oct 12, 2023 1:01pm

@@ -170,15 +170,6 @@ describe('with-page-auth-required ssr', () => {
delete process.env.NEXT_PUBLIC_AUTH0_LOGIN;
});

test('is a no-op when invoked as a client-side protection from the server', async () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We don't need this test anymore since the same withPageAuthRequired import isn't used for SSR and CSR since v3

const parseJson = (req: IncomingMessage, res: ServerResponse): Promise<IncomingMessage> =>
new Promise((resolve, reject) => {
export const parseJson = async (req: IncomingMessage, res: ServerResponse): Promise<IncomingMessage> => {
const { default: bodyParser } = await import('body-parser');
Copy link
Contributor

Choose a reason for hiding this comment

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

Just curious, what is the reason we need a dynamic import here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added a dependency on this file in tests/fixtures/server.ts which some test files that run edge tests depend on and body-parser can't be imported on the edge runtime (it must use eval or something)

@adamjmcgrath adamjmcgrath merged commit 71ec088 into main Oct 12, 2023
3 checks passed
@adamjmcgrath adamjmcgrath deleted the mock-next-page-router branch October 12, 2023 13:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants