Skip to content

Commit cfec6f1

Browse files
committed
added cypress and connection to DB
1 parent 9494b44 commit cfec6f1

File tree

8 files changed

+356
-2
lines changed

8 files changed

+356
-2
lines changed

cypress.config.js

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
const { defineConfig } = require("cypress");
2+
const clientConfig = require('./cypress/support/clientconfig');
3+
const { Client } = require('pg')
4+
5+
module.exports = defineConfig({
6+
e2e: {
7+
setupNodeEvents(on, config) {
8+
on("task", {
9+
async connectDB(query) {
10+
const client = new Client(clientConfig)
11+
await client.connect()
12+
const res = await client.query(query)
13+
await client.end()
14+
return res.rows;
15+
}
16+
})
17+
},
18+
},
19+
});

cypress/e2e/postgres.cy.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
describe('empty spec', () => {
2+
it('passes', () => {
3+
cy.task('connectDB','SELECT NOW()').then((res)=>{
4+
cy.log(res[0].now);
5+
})
6+
})
7+
})

cypress/fixtures/example.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "Using fixtures to represent data",
3+
"email": "[email protected]",
4+
"body": "Fixtures are a great way to mock data for responses to routes"
5+
}

cypress/support/clientconfig.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
var config = {
2+
user: "cypress_admin",
3+
password: "cypressrules",
4+
host: "localhost",
5+
database: "cypress",
6+
ssl: false,
7+
port: 5432
8+
}
9+
10+
module.exports = config;

cypress/support/commands.js

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// ***********************************************
2+
// This example commands.js shows you how to
3+
// create various custom commands and overwrite
4+
// existing commands.
5+
//
6+
// For more comprehensive examples of custom
7+
// commands please read more here:
8+
// https://on.cypress.io/custom-commands
9+
// ***********************************************
10+
//
11+
//
12+
// -- This is a parent command --
13+
// Cypress.Commands.add('login', (email, password) => { ... })
14+
//
15+
//
16+
// -- This is a child command --
17+
// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
18+
//
19+
//
20+
// -- This is a dual command --
21+
// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
22+
//
23+
//
24+
// -- This will overwrite an existing command --
25+
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })

cypress/support/e2e.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// ***********************************************************
2+
// This example support/e2e.js is processed and
3+
// loaded automatically before your test files.
4+
//
5+
// This is a great place to put global configuration and
6+
// behavior that modifies Cypress.
7+
//
8+
// You can change the location of this file or turn off
9+
// automatically serving support files with the
10+
// 'supportFile' configuration option.
11+
//
12+
// You can read more here:
13+
// https://on.cypress.io/configuration
14+
// ***********************************************************
15+
16+
// Import commands.js using ES2015 syntax:
17+
import './commands'
18+
19+
// Alternatively you can use CommonJS syntax:
20+
// require('./commands')

0 commit comments

Comments
 (0)