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

Next.js integration tests for Server and Browser #3632

Merged
merged 17 commits into from Jun 2, 2021
Merged

Conversation

kamilogorek
Copy link
Contributor

Completely custom test runner and integration tests for Next.js application. Covers both, server and browser environments.
Currently implements the most common use cases of error handling, tracing, and sessions, but the suites are definitely non-exhaustive.

Application has to be pre-built using yarn build (covered by the npm run test:integration) and tests can be run using node directly or through npm scripts. The runner allows for filtering specific test cases and provides debug mode for logging intercepted requests and enabling console logs.

$ npm run test:integration
$ npm run test:integration:server
$ npm run test:integration:browser
Usage: node test/integration/[server|browser].js <filename>

ENV Variables:
DEBUG=[bool] - enable request and application logs
DEBUG_DEPTH=[int] - set logging depth

Arguments:
<filename> - filter tests based on filename partial match

Only the second commit is reviewable. The first one is completely isolated example app and it doesn't require a review, although feel free to do so if you feel like it.

@kamilogorek kamilogorek requested review from a team, AbhiPrasad and iker-barriocanal and removed request for a team June 1, 2021 12:42
@github-actions
Copy link
Contributor

github-actions bot commented Jun 1, 2021

size-limit report

Path Size
@sentry/browser - CDN Bundle (gzipped) 20.83 KB (-0.01% 🔽)
@sentry/browser - Webpack 22.07 KB (0%)
@sentry/react - Webpack 22.11 KB (0%)
@sentry/browser + @sentry/tracing - CDN Bundle (gzipped) 28.23 KB (0%)

@kamilogorek kamilogorek force-pushed the nextjs-tests branch 2 times, most recently from b694ec3 to 7ac9d4c Compare June 1, 2021 13:27
packages/nextjs/.prettierignore Outdated Show resolved Hide resolved
packages/nextjs/test/integration/README.md Outdated Show resolved Hide resolved
packages/nextjs/test/integration/test/browser.js Outdated Show resolved Hide resolved
packages/nextjs/test/integration/test/browser.js Outdated Show resolved Hide resolved
packages/nextjs/test/integration/test/browser.js Outdated Show resolved Hide resolved
packages/nextjs/test/integration/test/browser.js Outdated Show resolved Hide resolved
packages/nextjs/test/integration/test/browser.js Outdated Show resolved Hide resolved
packages/nextjs/package.json Outdated Show resolved Hide resolved
packages/nextjs/package.json Outdated Show resolved Hide resolved
packages/nextjs/test/integration/pages/crashed.tsx Outdated Show resolved Hide resolved
let scenarios = await fs.readdir(path.resolve(__dirname, './server'));

if (FILES_FILTER) {
scenarios = scenarios.filter(file => file.toLowerCase().includes(FILES_FILTER));
Copy link
Member

Choose a reason for hiding this comment

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

Why filtering without considering the case? Also, any condition that's not the exact same (partial) match should be documented on line 19.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Purely for convinience. It just annoyed me that I typed node server.js api and it didn't find the test ¯_(ツ)_/¯
I dont understand the second part of your feedback. Line 19 states that it'll match on partials 🤔

Copy link
Member

Choose a reason for hiding this comment

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

What I understand from "partial match" is it can be a substring, not that we're not considering the case. I'm good for not considering it, but I feel we should not that.

packages/nextjs/test/integration/test/server.js Outdated Show resolved Hide resolved
packages/nextjs/test/integration/test/server.js Outdated Show resolved Hide resolved
packages/nextjs/test/integration/test/browser.js Outdated Show resolved Hide resolved
packages/nextjs/test/integration/test/browser.js Outdated Show resolved Hide resolved
if (
isSentryRequest(request) ||
// Used for testing http tracing
request.url().includes('example.com')
Copy link
Member

Choose a reason for hiding this comment

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

example.com (http://example.com in other places) is required, or can any URL be used? If it has to be this one, is there any other way to use (or modify) it, instead of hardcoding it everywhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added missing protocol. Any URL can be used, but it has to match, that's why I used the same one everywhere.

Copy link
Member

@iker-barriocanal iker-barriocanal left a comment

Choose a reason for hiding this comment

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

LGTM.

return true;
};

// Misc
Copy link
Member

Choose a reason for hiding this comment

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

I'd separate this misc stuff from the server stuff into two separate files, but this is a minor thing.

@kamilogorek kamilogorek merged commit 17b12e1 into master Jun 2, 2021
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.

None yet

3 participants