1
0
mirror of synced 2026-01-18 06:04:45 -05:00
Files
airbyte/airbyte-webapp-e2e-tests/cypress/plugins/index.ts
Vladimir c5e5659ebe 🪟 🚦 E2E: Fix duplicated database object warning (#20926)
* replace "cypress-postgres" with "pg-promise" npm package

* update cypress config

* update userDefineConnection type and naming

* Update airbyte-webapp-e2e-tests/cypress/plugins/index.ts

Co-authored-by: Mark Berger <mark.berger@globallogic.com>

Co-authored-by: Mark Berger <mark.berger@globallogic.com>
2023-01-12 16:01:46 +00:00

47 lines
1.4 KiB
TypeScript

/// <reference types="cypress" />
// ***********************************************************
// This example plugins/index.js can be used to load plugins
//
// You can change the location of this file or turn off loading
// the plugins file with the 'pluginsFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/plugins-guide
// ***********************************************************
// This function is called when a project is opened or re-opened (e.g. due to
// the project's config changing)
import Cypress from "cypress";
const pgp = require("pg-promise")();
const cypressConfig = require(require("path").resolve("cypress.json"));
interface dbConfig {
user: string;
host: string;
database: string;
password: string;
port: number;
}
function dbConnection(query: any, userDefineConnection: dbConfig) {
let connection = cypressConfig.db;
if (userDefineConnection !== undefined) {
connection = userDefineConnection;
}
const db = pgp(connection);
return db.any(query).finally(db.$pool.end);
}
/**
* @type {Cypress.PluginConfig}
*/
module.exports = (on: Cypress.PluginEvents, config: Cypress.PluginConfigOptions) => {
// `on` is used to hook into various events Cypress emits
// `config` is the resolved Cypress config
on("task", {
dbQuery: (query) => dbConnection(query.query, query.connection),
});
};