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

data-testid being stripped in test/local env in latest 12.1.6 #36651

Closed
1 task done
wadehammes opened this issue May 3, 2022 · 6 comments · Fixed by #36922
Closed
1 task done

data-testid being stripped in test/local env in latest 12.1.6 #36651

wadehammes opened this issue May 3, 2022 · 6 comments · Fixed by #36922
Labels
good first issue Easy to fix issues, good for newcomers Testing Related to testing with Next.js.

Comments

@wadehammes
Copy link

wadehammes commented May 3, 2022

Verify canary release

  • I verified that the issue exists in Next.js canary release

Provide environment information

Operating System:
Platform: linux
Arch: x64
Version: #1 SMP Wed Mar 2 00:30:59 UTC 2022
Binaries:
Node: 14.18.1
npm: 6.14.15
Yarn: 1.22.18
pnpm: N/A
Relevant packages:
next: 12.1.6
react: 18.1.0
react-dom: 18.1.0

What browser are you using? (if relevant)

Firefox

How are you deploying your application? (if relevant)

Vercel

Describe the Bug

In the latest 12.1.6, running Jest locally with tests that try to locate elements using the data-testid attr fail, this works fine in 12.1.5.

In my next config I have:

compiler: {
    styledComponents: true,
    reactRemoveProperties: true,
  },

image

Expected Behavior

data-testid should only be removed in production env, not local or preview envs.

To Reproduce

Create a projec with latest next, jest, and a test that looks for a data-testid.

@wadehammes wadehammes added the bug Issue was opened via the bug report template. label May 3, 2022
@wadehammes
Copy link
Author

Maybe related to the issues being experienced in #36647

@wadehammes
Copy link
Author

Confirmed it fails in 12.1.6-canary.15, all canaries before work fine.

@wadehammes wadehammes changed the title data-testid being stripped in test env in latest 12.1.6 data-testid being stripped in test/local env in latest 12.1.6 May 3, 2022
@timneutkens
Copy link
Member

This is because next/jest previously did not apply the opt-in transforms and that was fixed. I guess for reactRemoveProperties we'll want to disable that in the test env when the true option is used.

@timneutkens timneutkens added Testing Related to testing with Next.js. kind: story good first issue Easy to fix issues, good for newcomers and removed bug Issue was opened via the bug report template. labels May 6, 2022
@azeez1776
Copy link

Hey @timneutkens, can I work on the issue? should I change the reactRemoveProperties in the test/integration/telemetry/next.config.swc directory, I'm really new and would like to contrribute.

@SukkaW
Copy link
Contributor

SukkaW commented May 15, 2022

The issue should be fixed by #36922

In the meantime, you can apply a temporary fix in your next.config.js:

// next.config.js
module.exports = {
  compiler: {
-   reactRemoveProperties: true
+   reactRemoveProperties: process.env.NODE_ENV === 'production'
  }
}

@kodiakhq kodiakhq bot closed this as completed in #36922 May 17, 2022
kodiakhq bot pushed a commit that referenced this issue May 17, 2022
## Bug

- [x] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

Fixes #36651.

Always disable `reactRemoveProperties` in `next/jest` transformation.
@github-actions
Copy link
Contributor

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
good first issue Easy to fix issues, good for newcomers Testing Related to testing with Next.js.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants