-
Notifications
You must be signed in to change notification settings - Fork 0
/
cypress.config.js
74 lines (70 loc) · 2.11 KB
/
cypress.config.js
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
const { defineConfig } = require('cypress');
require('dotenv').config();
const { connect, disconnect } = require('./db');
const setupNodeEvents = async (on, config) => {
on('task', {
async insertMany({ collectionName }) {
try {
const db = (await connect()).db('MovieDb');
await db.command({ ping: 1 });
console.log(`Connected successfully to server: ${db.databaseName}`);
const movies = db.collection(collectionName);
const docs = [
{
title: 'Jurassic World: Fallen Kingdom',
genres: ['Action', 'Sci-Fi'],
runtime: 130,
rated: 'PG-13',
year: 2018,
directors: ['J. A. Bayona'],
cast: ['Chris Pratt', 'Bryce Dallas Howard', 'Rafe Spall'],
type: 'movie',
},
{
title: 'Tag',
genres: ['Comedy', 'Action'],
runtime: 105,
rated: 'R',
year: 2018,
directors: ['Jeff Tomsic'],
cast: ['Annabelle Wallis', 'Jeremy Renner', 'Jon Hamm'],
type: 'movie',
},
];
const options = { ordered: true };
const result = await movies.insertMany(docs, options);
if ((await movies.countDocuments()) === 0) {
throw new Error('No documents found!');
}
console.log(`${result.insertedCount} documents were inserted`);
return result;
} finally {
await disconnect();
}
},
async findMovieByTitle({ titleName }) {
try {
const db = (await connect()).db('MovieDb');
const collection = db.collection('Movies');
if ((await collection.countDocuments()) === 0) {
throw new Error('No documents found!');
}
const cursor = collection.find({ title: { $eq: titleName } });
return await cursor.next();
} finally {
await disconnect();
}
},
});
return config;
};
module.exports = defineConfig({
env: {
mongo_uri: process.env.MONGO_URI,
},
e2e: {
setupNodeEvents,
responseTimeout: 10000,
video: false,
},
});