Skip to content

Commit 85f2fe8

Browse files
authored
fix(nextjs): Small integration test runner fixes (#3801)
Fix a few small bugs in our test runner for nextjs integration tests: - Debug mode failed because of a missing import - Test runner options couldn't be passed except by hard-coding them in the bash script called by yarn - One of our node/nextjs compatibility checks was checking the wrong version of nextjs - Console breadcrumbs caused ever-larger events to be logged, since each time an object including breadcrumbs was logged, the entire object then became a breadcrumb in the next object logged, which itself became a breadcrumb in the next one, and so on and so forth - In the test-runner bash script, our variable keeping track of exit code was reset unnecessarily (if it's anything other than `0` by that point, the script already will have bailed) - Our test filtering was case-sensitive Also a few small changes to make debugging those tests easier: - When comparing objects, the actual value is now stored as a variable, so that the value will be shown inline by the debugger - The default value of the `depth` option is now included in its help text - `console.log(inspect(...))` was changed to `console.dir(...)`, which does both in one, and color is now included in the output
1 parent 778ad8b commit 85f2fe8

File tree

6 files changed

+34
-11
lines changed

6 files changed

+34
-11
lines changed

packages/nextjs/test/integration/sentry.server.config.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,19 @@ import * as Sentry from '@sentry/nextjs';
33
Sentry.init({
44
dsn: 'https://[email protected]/1337',
55
tracesSampleRate: 1,
6-
integrations: [
6+
7+
integrations: defaults => [
8+
...defaults.filter(
9+
integration =>
10+
// filter out `Console` since the tests are happening in the console and we don't need to record what's printed
11+
// there, because we can see it (this makes debug logging much less noisy, since intercepted events which are
12+
// printed to the console no longer create console breadcrumbs, which then get printed, creating even longer
13+
// console breadcrumbs, which get printed, etc, etc)
14+
15+
// filter out `Http` so its options can be changed below (otherwise, default one wins because it's initialized first)
16+
integration.name !== 'Console' && integration.name !== 'Http',
17+
),
18+
719
// Used for testing http tracing
820
new Sentry.Integrations.Http({ tracing: true }),
921
],

packages/nextjs/test/integration/test/client/errorClick.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ const { waitForAll } = require('../utils/common');
22
const { expectRequestCount, isEventRequest, expectEvent } = require('../utils/client');
33

44
module.exports = async ({ page, url, requests }) => {
5-
console.log(page, url, requests);
65
await page.goto(`${url}/errorClick`);
76

87
await waitForAll([page.click('button'), page.waitForRequest(isEventRequest)]);

packages/nextjs/test/integration/test/runner.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const argv = yargs(process.argv.slice(2))
2121
})
2222
.option('depth', {
2323
type: 'number',
24-
description: 'Set the logging depth for intercepted requests',
24+
description: 'Set the logging depth for intercepted requests (default = 4)',
2525
}).argv;
2626

2727
const runScenario = async (scenario, execute, env) => {
@@ -66,7 +66,7 @@ module.exports.run = async ({
6666

6767
let scenarios = await fs.readdir(scenariosDir);
6868
if (argv.filter) {
69-
scenarios = scenarios.filter(file => file.toLowerCase().includes(argv.filter));
69+
scenarios = scenarios.filter(file => file.toLowerCase().includes(argv.filter.toLowerCase()));
7070
}
7171
scenarios = scenarios.map(s => path.resolve(scenariosDir, s));
7272

packages/nextjs/test/integration/test/utils/common.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ const logIf = (condition, message, input, depth = 4) => {
3737
if (condition) {
3838
console.log(message);
3939
if (input) {
40-
console.log(inspect(input, { depth }));
40+
console.dir(input, { depth, colors: true });
4141
}
4242
}
4343
};

packages/nextjs/test/integration/test/utils/server.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,14 @@ const objectMatches = (actual, expected) => {
5757

5858
for (const key in expected) {
5959
const expectedValue = expected[key];
60+
const actualValue = actual[key];
6061

6162
if (Object.prototype.toString.call(expectedValue) === '[object Object]' || Array.isArray(expectedValue)) {
62-
if (!objectMatches(actual[key], expectedValue)) {
63+
if (!objectMatches(actualValue, expectedValue)) {
6364
return false;
6465
}
6566
} else {
66-
if (actual[key] !== expectedValue) {
67+
if (actualValue !== expectedValue) {
6768
return false;
6869
}
6970
}

packages/nextjs/test/run-integration-tests.sh

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ for NEXTJS_VERSION in 10 11; do
2424
fi
2525

2626
# Next.js v11 requires at least Node v12
27-
if [ "$NODE_MAJOR" -lt "12" ] && [ "$NEXTJS_VERSION" -eq "10" ]; then
27+
if [ "$NODE_MAJOR" -lt "12" ] && [ "$NEXTJS_VERSION" -eq "11" ]; then
2828
echo "[nextjs$NEXTJS_VERSION] Not compatible with Node $NODE_VERSION"
2929
exit 0
3030
fi
@@ -53,8 +53,19 @@ for NEXTJS_VERSION in 10 11; do
5353
echo "[nextjs@$NEXTJS_VERSION | webpack@$WEBPACK_VERSION] Building..."
5454
yarn build | grep "Using webpack"
5555

56+
# if no arguments were passed, default to outputting nothing other than success and failure messages ($* gets all
57+
# passed args as a single string)
58+
args=$*
59+
if [[ ! $args ]]; then
60+
args="--silent"
61+
fi
62+
63+
# we keep this updated as we run the tests, so that if it's ever non-zero, we can bail
5664
EXIT_CODE=0
57-
node test/server.js --silent || EXIT_CODE=$?
65+
66+
echo "Running server tests with options: $args"
67+
node test/server.js $args || EXIT_CODE=$?
68+
5869
if [ $EXIT_CODE -eq 0 ]
5970
then
6071
echo "[nextjs@$NEXTJS_VERSION | webpack@$WEBPACK_VERSION] Server integration tests passed"
@@ -63,8 +74,8 @@ for NEXTJS_VERSION in 10 11; do
6374
exit 1
6475
fi
6576

66-
EXIT_CODE=0
67-
node test/client.js --silent || EXIT_CODE=$?
77+
echo "Running client tests with options: $args"
78+
node test/client.js $args || EXIT_CODE=$?
6879
if [ $EXIT_CODE -eq 0 ]
6980
then
7081
echo "[nextjs@$NEXTJS_VERSION | webpack@$WEBPACK_VERSION] Client integration tests passed"

0 commit comments

Comments
 (0)