webpack 5 custom react project throwing error Cypress could not detect tests in this file
See original GitHub issueHi Team , I have test file in specified test folder:
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:
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:
- Created 2 years ago
- Comments:16 (9 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub 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
@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