haim-io / cypress-image-diff

Visual regression test with cypress
MIT License
251 stars 62 forks source link

Cannot find module cypress-image-diff-js/dist/plugin #194

Closed CaiqueCoelho closed 9 months ago

CaiqueCoelho commented 9 months ago

I'm trying to run the plugin for the first time and I encounter the following problem, could you help me, please?

Error:

Error: Cannot find module '/Users/caiquecoelho/Documents/Projects/openid_server_code/node_modules/cypress-image-diff-js/dist/plugin'
    at createEsmNotFoundErr (node:internal/modules/cjs/loader:1098:15)
    at finalizeEsmResolution (node:internal/modules/cjs/loader:1091:15)
    at resolveExports (node:internal/modules/cjs/loader:567:14)
    at Function.Module._findPath (node:internal/modules/cjs/loader:636:31)
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:1063:27)
    at Function.Module._resolveFilename.sharedData.moduleResolveFilenameHook.installedValue [as _resolveFilename] (/Users/caiquecoelho/Library/Caches/Cypress/13.6.0/Cypress.app/Contents/Resources/app/node_modules/@cspotcode/source-map-support/source-map-support.js:811:30)
    at Function.Module._load (node:internal/modules/cjs/loader:922:27)
    at Module.require (node:internal/modules/cjs/loader:1143:19)
    at require (node:internal/modules/cjs/helpers:119:18)
    at Object.<anonymous> (/Users/caiquecoelho/Documents/Projects/openid_server_code/cypress.config.ts:3:1)
    at Module._compile (node:internal/modules/cjs/loader:1256:14)
    at Module.m._compile (/Users/caiquecoelho/Library/Caches/Cypress/13.6.0/Cypress.app/Contents/Resources/app/node_modules/ts-node/dist/index.js:857:29)
    at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
    at Object.require.extensions.<computed> [as .ts] (/Users/caiquecoelho/Library/Caches/Cypress/13.6.0/Cypress.app/Contents/Resources/app/node_modules/ts-node/dist/index.js:859:16)
    at Module.load (node:internal/modules/cjs/loader:1119:32)
    at Function.Module._load (node:internal/modules/cjs/loader:960:12)
    at Module.require (node:internal/modules/cjs/loader:1143:19)
    at require (node:internal/modules/cjs/helpers:119:18)
    at loadFile (/Users/caiquecoelho/Library/Caches/Cypress/13.6.0/Cypress.app/Contents/Resources/app/packages/server/lib/plugins/child/run_require_async_child.js:89:14)
    at EventEmitter.<anonymous> (/Users/caiquecoelho/Library/Caches/Cypress/13.6.0/Cypress.app/Contents/Resources/app/packages/server/lib/plugins/child/run_require_async_child.js:116:38)
    at EventEmitter.emit (node:events:517:28)
    at EventEmitter.emit (node:domain:489:12)

cypress.config.ts

import { defineConfig } from 'cypress';
import getCompareSnapshotsPlugin from 'cypress-image-diff-js/plugin';

export default defineConfig({
  e2e: {
    setupNodeEvents(on, originalConfig) {
      const config = getCompareSnapshotsPlugin(on, originalConfig);
      require('@cypress/grep/src/plugin')(config);
      getCompareSnapshotsPlugin(on, config);
      return require('./cypress/plugins/index.js')(on, config);
    },
    experimentalRunAllSpecs: true,
    specPattern: 'cypress/e2e/**/*.{js,jsx,ts,tsx}',
    baseUrl: 'http://localhost:9000',
    retries: {
      runMode: 1,
      openMode: 0,
    },
    experimentalMemoryManagement: true,
    numTestsKeptInMemory: process.env.CI ? 0 : 10,
  },
  chromeWebSecurity: false,
  defaultCommandTimeout: 10000,
  requestTimeout: 25000,
  responseTimeout: 25000,
  env: {
    grepFilterSpecs: true,
    grepOmitFiltered: true
  }
});

System: Mac Os 14.1 (23B74)

Cypress: 13.6.0

kien-ht commented 9 months ago

@CaiqueCoelho We have just released version 2.1.0, please upgrade your package and see if the error still persists.

Side note: I've noticed you have initialized our plugin twice, can you confirm if it's just a copy and paste problem?

camhost01 commented 9 months ago

Hi @kien-ht I recently updated the plugin and also read the previous issue. I followed the steps but still got an error. Configuration // cypress.config.js const { defineConfig } = require("cypress"); const getCompareSnapshotsPlugin = require('cypress-image-diff-js/plugin'); module.exports = defineConfig({ e2e: { video: false, setupNodeEvents(on, config) {

  return getCompareSnapshotsPlugin(on, config);
},

}, }); // cypress-image-diff.config.cjs const config = { ROOT_DIR: 'cypress/Visua_Test', REPORT_DIR: 'cypress/Report/html-report', SCREENSHOTS_DIR: 'screenshots', FAILURE_THRESHOLD: 0.1, RETRY_OPTIONS: { log: true, limit: 2, // max number of iterations timeout: 30000, // time limit in ms delay: 300, // delay before next iteration, ms }, FAIL_ON_MISSING_BASELINE: true, COMPARISON_OPTIONS: { threshold: 0.2 }, JSON_REPORT: { FILENAME: 'cypress_visual_report', OVERWRITE: false, }, CYPRESS_SCREENSHOT_OPTIONS:{ capture: 'fullPage', disableTimersAndAnimations: true, } }; module.exports = config;

e2e.js const compareSnapshotCommand = require('cypress-image-diff-js/command'); compareSnapshotCommand(); import './commands'

package-lock

image image image
kien-ht commented 9 months ago

@camhost01, I've just created a working integration example here. Please take a look and see if you have any misconfig parts.

camhost01 commented 9 months ago

Hi @kien-ht I checked the Java configuration and they are the same. I notice that in your example, the cypress.config.js is the same compared with TypeScript. Is that correct? the issue that I facing is related in the const definition

image

Look what I have cypress-image-diff.config.cjs

image

cypress.config.js

image

e2e.js

image

dependencies

image

I think I do not need an extra configuration to run the plugin, right?

kien-ht commented 9 months ago

Yes correct. Configuration file is optional, used in case you want to change the default behaviour of this plugin.

May I suggest you two things:

  1. Clean cache the node_modules and reinstall again.
  2. Pull the actual code of the example I provided above, and run it locally to see if you see any problems. I believe I wrote a README.md in the respective example folder, in case you struggle to make it run.
Strezzo06 commented 9 months ago

Hi @kien-ht I checked the Java configuration and they are the same. I notice that in your example, the cypress.config.js is the same compared with TypeScript. Is that correct? the issue that I facing is related in the const definition

image

Look what I have cypress-image-diff.config.cjs image

cypress.config.js image

e2e.js image

dependencies image

I think I do not need an extra configuration to run the plugin, right?

I updated to V2.1.1 and did follow this step but still found error same as you I tried to clean node_modules many times but still found this error

Screen Shot 2023-12-18 at 2 35 35 PM
dominikzogg commented 9 months ago

Same error, using it in a NextJS Typescript project.

kien-ht commented 9 months ago

@Strezzo06

  1. Can you try to run the example locally, see if there's any problems?
  2. I'm assuming that your project type is CommonJs. Can you confirm that?

@dominikzogg, can you provide more details about your project setup please?

Edwardmunn commented 9 months ago

@camhost01, I've just created a working integration example here. Please take a look and see if you have any misconfig parts.

I am seeing the same issue as others within this thread. I have downloaded the example project linked, and ran the following: npm install and npm run test. I am presented with the following error:

Screenshot 2023-12-18 at 11 28 36

Edit: I see you have already started working on a fix while I was fumbling around with a comment — thanks for your swift response.

PippoRaimondiDIT commented 9 months ago

:tada: This issue has been resolved in version 2.1.2 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

Strezzo06 commented 9 months ago

🎉 This issue has been resolved in version 2.1.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

Thank you for the excellent support. I was able to run through that point. However, I encountered another error. #198

CaiqueCoelho commented 9 months ago

Thank you so much @kien-ht @PippoRaimondiDIT now it works :D