rsnext/test
Shu Ding 89ec21ed68
Fix wrong source path resolved from the stack frame to not expose internal code (#23203)
Currently Next.js exposes internal code in the error overlay if certain errors were created from the user code. Some examples were attached in #20776.

We can clearly see that the path is wrong (`../next-server`), it should be `./node_modules/next/dist/next-server`:

![CleanShot 2021-03-19 at 01 33 04](https://user-images.githubusercontent.com/3676859/111670728-1ae7e400-8853-11eb-9213-3b359798900e.png)

The root cause is the `__nextjs_original-stack-frame` middleware resolves the file path with the following code:

```js
path.resolve(
  rootDirectory,
  getSourcePath(sourcePosition.source)
)
```

where `rootDirectory` is the **app root**, but `sourcePosition.source` comes from the module path, which is relative to the path of the `next` binary, not the app root. 

That explains why we see `../next-server` from the error above, because it's relative to `./node_modules/next/bin/next`.

Because of that, the resolved result will never have `node_modules` in its path and it won't be filtered by the error overlay in the UI. Here's a screenshot of the frame object in the UI:

![CleanShot 2021-03-18 at 23 01 29@2x](https://user-images.githubusercontent.com/3676859/111670062-65b52c00-8852-11eb-9293-3a6e5b7c4b9b.png)

And the filter we use to determine if a frame is expanded or not only depends on `body.originalStackFrame`:

```js
expanded: !Boolean(
  body.originalStackFrame?.file?.includes('node_modules') ?? true
)
```

So this PR also adds `source.file` check to ensure they will be ignored (not necessary because we fixed the path resolving).

Fixes #20776.
2021-03-20 19:34:45 +00:00
..
.stats-app Add nccing AMP optimizer (#21980) 2021-02-11 09:55:56 +00:00
acceptance Fix wrong source path resolved from the stack frame to not expose internal code (#23203) 2021-03-20 19:34:45 +00:00
eslint-plugin-next Break-up unit tests to separate step (#18992) 2020-11-10 12:25:50 -05:00
integration Experimental feature for allowing importing Typescript files outside of the root directory (#22867) 2021-03-19 16:43:46 +00:00
isolated Load next.config.js async (#22578) 2021-02-27 00:29:32 +00:00
lib Ensure static 500 hydrates correctly with query (#22468) 2021-02-23 22:15:46 +00:00
package-managers/pnpm Add pnpm integration test (#17882) 2021-01-11 17:50:12 +01:00
unit fix(link): cancel idle callback on unmount (#22072) 2021-02-11 13:51:41 -05:00
.babelrc Include all files in Prettier (#17050) 2020-09-14 02:53:19 +00:00
.gitignore Universal Webpack (#3578) 2018-01-30 16:44:44 +01:00
jest-environment.js Upgrade to Prettier 2 (#13061) 2020-05-18 15:24:37 -04:00
jest-global-setup.js Upgrade to Prettier 2 (#13061) 2020-05-18 15:24:37 -04:00
jest-global-teardown.js Update CI/test set up (#9499) 2019-11-25 13:19:45 -05:00
jest-setup-after-env.js Only retry tests on CI (#12998) 2020-05-17 12:10:02 -04:00
test-file.txt Add additional file serving tests (#12479) 2020-05-04 11:58:19 -05:00
tsconfig.json Update tsconfig for tests 2020-01-21 15:29:39 -06:00