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.

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

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:16 (9 by maintainers)

github_iconTop GitHub Comments

9reactions
rob-not-bobcommented, Nov 13, 2021

@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",
  },
2reactions
lmiller1990commented, Jun 4, 2021

@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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cypress returns webpack compilation error for .scss file in ...
(!webpackOptions) { throw new Error('Could not find Webpack in this project'); } const cleanOptions = { reactScripts: true }; findWebpack.
Read more >
TypeScript - Cypress Documentation
Cypress ships with official type declarations for TypeScript. This allows you to write your tests in TypeScript. Install TypeScript To use TypeScript.
Read more >
Invalid Hook Call Warning - React
You are probably here because you got the following error message: Hooks can only be called inside the body of a function component....
Read more >
Setup - Testing Library
React Testing Library does not require any configuration to be used. However, there are some things you can do when configuring your testing...
Read more >
Watch and WatchOptions | webpack
Turn on watch mode. This means that after the initial build, webpack will continue to watch for changes in any of the resolved...
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