-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcypress.config.js
More file actions
53 lines (51 loc) · 1.75 KB
/
cypress.config.js
File metadata and controls
53 lines (51 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import cypress, { defineConfig } from "cypress";
import mongoose from 'mongoose';
import { MONGODB_URI } from "./cypress-constants.js";
import User from "./server/models/userModel.js";
//import { connect, clear, close, findUserEntry } from './cypress/e2e/mongodb-test-db.js'
// import dotenv from 'dotenv';
// dotenv.config({path: ".env.test-cy"});
export default defineConfig({
e2e: {
baseUrl: 'http://localhost:5173/',
setupNodeEvents(on, config) {
on('task', {
async connect() {
await mongoose.connect(MONGODB_URI)
.then(() => { console.log("Connected") })
.catch((error) => console.log(`Error connecting to DB: ${error}`))
//cy.log(mongoose.connection.readyState);
return mongoose.connection.readyState;
},
async disconnect() {
await mongoose.connection.close();
return null;
},
async clearUsers(){
await mongoose.connection.collection('users').deleteMany({});
//cy.log(mongoose.connection.readyState);
return null;
// await User.deleteMany();
// return null;
},
async clearFavourites(){
await mongoose.connection.collection('favourites').deleteMany({});
return null;
},
async clearRatings(){
await mongoose.connection.collection('mealRatings').deleteMany({});
return null;
},
async findUser(email){
const user = await mongoose.connection.collection('users').findOne({email: email});
//cy.log(mongoose.connection.readyState);
return user;
},
async checkConnection(){
return mongoose.connection.readyState;
}
});
return config;
},
},
});