0

Cannot find module '******\test\cypress\support\component.js'

I am trying to connect to oracle database and send a simple select query as cypress task. Once I run the test got this error:

**An uncaught error was detected outside of a testfailed No commands were issued in this test. Error The following error originated from your test code, not from Cypress.

Cannot find module '************\test\cypress\support\component.js'

When Cypress detects uncaught errors originating from your test code it will automatically fail the current test.

Cypress could not associate this error to any specific test.

Do you have any idea what can be the problem?

You will find bellow: my test file, definition of the method and the db and cypress configurations Thank you in advance for your help!

  • the test file: dbtest.spec.js:
describe('db tests', () => {
    
    it('Verify that there is only one row', function () {
       cy.task('queryDb', `SELECT COUNT(username) as "usernames" FROM app_users`).then((result) => {
            expect(result.rows[0][0]).to.not.equal(0);
        });
    })
    
})

this is my oracle.dbconfig.js:

const oracledb = require('oracledb');
const dbConfig = require('./dbconfig.js');

async function queryTestDb(query, config) {
  debugger;
  const connection = await oracledb.getConnection(config.env.db);
  return new Promise((resolve, reject) => {
    connection.execute(query, (error, results) => {
      if (error) reject(error)
      else {
        connection.close();
        return resolve(results)
      }
    })
  })
};

module.exports = {
  dbConfig: dbConfig,
  queryTestDb: queryTestDb
};
  • the dbconfig.js:
module.exports = {
    user          : "****", 
    password      : "*****", 
  
    host: "******",
    database: "*******",
    connectString : "*************", 
    externalAuth  : false, 
  };
  • the cypress.config.js:
const { defineConfig } = require("cypress");

//For connecting to SQL Server
const db = require('./cypress/support/oracle.dbconfig.js');

module.exports = defineConfig({
  e2e: {
    testIsolation: true,
    baseUrl: "***************p",
    specPattern : [
      //"**/*.{feature/features}",
      //"**/*.cy.js",
      //"**/*.spec.js",
      "**/*.test.run.js",
      "**/*.ts.run.js",
      "**/*.tc.run.js",
      "**/*.tp.run.js"
    ],
  },

  watchForFileChanges : false,
  chromeWebSecurity : false,
  retries : 0,

  component: {
    specPattern : [
      "**/*.spec.js"
    ],
    setupNodeEvents(on, config) {
      on('task', { queryDb: query => { return db.queryTestDb(query, config); } });
    },
    devServer: {
      framework: "react",
      bundler: "webpack",
    },
  },
});

I do have /cypress/support/componen.js in my project

// ***********************************************************
// This example support/component.js is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************

// Import commands.js using ES2015 syntax:
import './commands'

// Alternatively you can use CommonJS syntax:
// require('./commands')

import { mount } from 'cypress/react18'

Cypress.Commands.add('mount', mount)

// Example use:
// cy.mount(<MyComponent />)

In my test.spec.js file, I tried to require the component but it is not helping require('./cypress/support/component');

Amin
  • 1
  • 1

1 Answers1

0

Do you have cypress/support/component.js in your project ? According to this example https://github.com/cypress-io/cypress-component-testing-apps/blob/main/react-webpack5-js/cypress/support/component.js

Jeanbon
  • 61
  • 2
  • yes, I do have cypress/support/component.js in my project. I will attach it to my question – Amin Jul 18 '23 at 21:28