cypress: webpack 5 custom react project throwing error Cypress could not detect tests in this file

Hi Team , I have test file in specified test folder: image

Test code:

import React from "react";
import { mount } from "@cypress/react";
import App from "./App";

describe("App component", () => {
  it("works", () => {
    mount(<App />);
    // now use standard Cypress commands
    cy.contains("Hello World!").should("be.visible");
  });
});

done installation using cypress cli webpack config:

plugin / index.js:

const path = require("path");

const { startDevServer } = require("@cypress/webpack-dev-Server");

/**
 * @type {Cypress.PluginConfig}
 */
// eslint-disable-next-line no-unused-vars
module.exports = (on, config) => {
  // `on` is used to hook into various events Cypress emits
  // `config` is the resolved Cypress config

  if (config.testingType === "component") {
    /** @type import("webpack").Configuration */
    const webpackConfig = {
      resolve: {
        extensions: [".js", ".ts", ".jsx", ".tsx"],
      },
      mode: "development",
      devtool: false,
      output: {
        publicPath: "/",
        chunkFilename: "[name].bundle.js",
      },
      // TODO: update with valid configuration for your components
      module: {
        rules: [
          {
            test: /\.(js|jsx|mjs|ts|tsx)$/,
            loader: "babel-loader",
            options: {
              cacheDirectory: path.resolve(__dirname, ".babel-cache"),
            },
          },
        ],
      },
    };
    on("dev-server:start", (options) =>
      startDevServer({
        options,
        webpackConfig,
      })
    );
  }
};

still getting following issue: image

if i use create-react-app then setup works fine only i am facing issue with webpack configuration option . Kindly let me know any fix for same

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 16 (9 by maintainers)

Most upvoted comments

@farmstrong8 I encountered this error as well. What fixed it for me was deleting the nextjs cache before running my component tests. The next.js cache was located in .next/cache. This error would only occur when I created a new test file.

package.json

  "scripts": {
    "precy:components": "rm -rf ./.next/cache",
    "cy:components": "cypress open-ct",
  },

@workforbala You need to return the config object from your plugins function? That’s required.

There is one other problem, that’s on our end, but it’ll be fixed in the next hour or so: https://github.com/cypress-io/cypress/pull/16813

A lot of things related to webpack are mysterious, but as long as it’s working that’s the important thing 🎉

If you are using the latest nextjs (11.0.2) there is a bug, that will be fixed when this is merged.

Please tell me if you find a bug - CT is still in alpha, but the sooner we find and fix all the bugs, the sooner it won’t be alpha!