question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Component Testing] New test code is not being bundled using NextJS 11.1 and Webpack 5

See original GitHub issue

Current behavior

When creating a new *.spec.{tsx, jsx} file in the specified component folder, these tests cannot be run.
Screen Shot 2021-08-27 at 1 04 58 PM

Similarly, if you delete a spec file the compiler will complain that the file {file}.spec.tsx cannot be found.

The only work around I’ve found is to manually delete the .next folder so that it actually bundles the code when I run cypress open-ct.

Desired behavior

No response

Test code to reproduce

  1. clone https://github.com/drj17/cypress-component-test-bug
  2. run yarn install && yarn cypress open-ct
  3. Duplicate existing cypress/pages/index.spec.jsx file
  4. Try to run it, see “No tests found error”
  5. Delete .next folder, re-run yarn cypress open-ct, tests now show show up.

Cypress Version

8.3.1

Other

package.json

{
  "name": "cypress-test",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start",
    "lint": "next lint"
  },
  "dependencies": {
    "next": "11.1.0",
    "react": "17.0.2",
    "react-dom": "17.0.2"
  },
  "devDependencies": {
    "@cypress/react": "^5.9.4",
    "@cypress/webpack-dev-server": "^1.4.0",
    "@types/react": "^17.0.19",
    "cypress": "^8.3.1",
    "eslint": "7.32.0",
    "eslint-config-next": "11.1.0",
    "html-webpack-plugin": "5",
    "webpack": "5",
    "webpack-dev-server": "3"
  }
}

plugins/index.js

/// <reference types="cypress" />
// ***********************************************************
// This example plugins/index.js can be used to load plugins
//
// You can change the location of this file or turn off loading
// the plugins file with the 'pluginsFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/plugins-guide
// ***********************************************************

// This function is called when a project is opened or re-opened (e.g. due to
// the project's config changing)

/**
 * @type {Cypress.PluginConfig}
 */
// eslint-disable-next-line no-unused-vars
const injectDevServer = require("@cypress/react/plugins/next");

module.exports = (on, config) => {
  injectDevServer(on, config);

  return config;
};

cypress.json:

{
  "testFiles": "**/*.spec.jsx",
  "componentFolder": "cypress/pages"
}

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:4
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
drj17commented, Sep 9, 2021

It does seem related, but in my case it only was fixed when I deleted the .next folder

0reactions
emilyrohrboughcommented, Mar 18, 2022

This was released as @cypress/webpack-dev-server-v1.8.1 on 2022-02-08.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Blog - Next.js 11
Next.js 11 continues our mission to create the best developer experience with a new conformance system and performance improvements.
Read more >
Changelog
Fixed an issue with Angular Component Testing where urls within SASS/SCSS files were not being correctly resolved which could result in incomplete styling....
Read more >
How to fix "FATAL ERROR: Ineffective mark-compacts near ...
That problem is related with large files in your project. I'm using create-react-app, and I got that error, after doing some search, ...
Read more >
How to keep your Lighthouse score high in Next.js ...
Let's talk about one of the most useful technical SEO performance tools that can be used to test web pages. It's automated, and...
Read more >
Migrating from nextjs 10 to 11 @smallcase
Webpack 5 : With next.js 11, webpack 5 is now enabled by default which ... the appropriate CSS was not getting applied to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found