cypress-mongodb
Advanced tools
Comparing version 5.5.0 to 6.0.0
@@ -0,0 +0,0 @@ /// <reference types="node" /> |
@@ -0,0 +0,0 @@ "use strict"; |
import Chainable = Cypress.Chainable; | ||
export declare function createCollection(collection: string, options?: any): Chainable; | ||
export declare function dropCollection(collection: string, options?: any): Chainable; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ import { Document } from 'mongodb'; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ import { Document } from 'mongodb'; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ import { Document } from 'mongodb'; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ import { Document } from 'mongodb'; |
@@ -0,0 +0,0 @@ "use strict"; |
/// <reference types="cypress" /> | ||
import { Document } from 'mongodb'; | ||
declare global { | ||
namespace Cypress { | ||
interface Chainable<Subject> { | ||
aggregate(pipeline: Document[], options?: any): Chainable<Subject>; | ||
createCollection(collection: string, options?: any): Chainable<Subject>; | ||
dropCollection(collection: string, options?: any): Chainable<Subject>; | ||
insertOne(document: Document, options?: any): Chainable<Subject>; | ||
insertMany(documents: Document[], options?: any): Chainable<Subject>; | ||
deleteOne(filter: Document, options?: any): Chainable<Subject>; | ||
deleteMany(filter: Document, options?: any): Chainable<Subject>; | ||
findOne(query: Document, options?: any): Chainable<Subject>; | ||
findOneAndUpdate(filter: Document, document: Document, options?: any): Chainable<Subject>; | ||
findOneAndDelete(filter: Document, options?: any): Chainable<Subject>; | ||
findMany(query: Document, options?: any): Chainable<Subject>; | ||
updateOne(filter: Document, document: Document, options?: any): Chainable<Subject>; | ||
updateMany(filter: Document, document: Document, options?: any): Chainable<Subject>; | ||
} | ||
} | ||
} | ||
export declare function configurePlugin(on: Cypress.PluginEvents): void; | ||
export declare function addCommands(): void; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.addCommands = exports.configurePlugin = void 0; | ||
exports.configurePlugin = void 0; | ||
var aggregate_util = require("./utils/aggregation"); | ||
var aggregate_commands = require("./commands/aggregation"); | ||
var collection_util = require("./utils/collection"); | ||
var collection_commands = require("./commands/collection"); | ||
var insert_util = require("./utils/insert"); | ||
var insert_commands = require("./commands/insert"); | ||
var delete_util = require("./utils/delete"); | ||
var delete_commands = require("./commands/delete"); | ||
var find_util = require("./utils/find"); | ||
var find_commands = require("./commands/find"); | ||
var update_util = require("./utils/update"); | ||
var update_commands = require("./commands/update"); | ||
function configurePlugin(on) { | ||
@@ -86,18 +80,1 @@ on('task', { | ||
exports.configurePlugin = configurePlugin; | ||
function addCommands() { | ||
Cypress.Commands.add('aggregate', aggregate_commands.aggregate); | ||
Cypress.Commands.add('createCollection', collection_commands.createCollection); | ||
Cypress.Commands.add('dropCollection', collection_commands.dropCollection); | ||
Cypress.Commands.add('insertOne', insert_commands.insertOne); | ||
Cypress.Commands.add('insertMany', insert_commands.insertMany); | ||
Cypress.Commands.add('deleteOne', delete_commands.deleteOne); | ||
Cypress.Commands.add('deleteMany', delete_commands.deleteMany); | ||
Cypress.Commands.add('findOne', find_commands.findOne); | ||
Cypress.Commands.add('findOneAndUpdate', find_commands.findOneAndUpdate); | ||
Cypress.Commands.add('findOneAndDelete', find_commands.findOneAndDelete); | ||
Cypress.Commands.add('findMany', find_commands.findMany); | ||
Cypress.Commands.add('updateOne', update_commands.updateOne); | ||
Cypress.Commands.add('updateMany', update_commands.updateMany); | ||
console.log('MongoDB plugin configured'); | ||
} | ||
exports.addCommands = addCommands; |
@@ -1,2 +0,1 @@ | ||
/// <reference types="node" /> | ||
export declare function aggregate(args: any): Promise<Buffer>; | ||
export declare function aggregate(args: any): Promise<Uint8Array>; |
@@ -17,3 +17,3 @@ "use strict"; | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (g && (g = 0, op[0] && (_ = 0)), _) try { | ||
while (_) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
@@ -20,0 +20,0 @@ if (y = 0, t) op = [op[0] & 2, t.value]; |
export declare function createCollection(args: any): Promise<unknown>; | ||
export declare function dropCollection(args: any): Promise<unknown>; |
@@ -17,3 +17,3 @@ "use strict"; | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (g && (g = 0, op[0] && (_ = 0)), _) try { | ||
while (_) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
@@ -43,9 +43,10 @@ if (y = 0, t) op = [op[0] & 2, t.value]; | ||
function createCollection(args) { | ||
var _this = this; | ||
return mongodb_1.MongoClient.connect(args.uri).then(function (client) { return __awaiter(_this, void 0, void 0, function () { | ||
var database, failSilently, result, error_1; | ||
var _a; | ||
var _a; | ||
return __awaiter(this, void 0, void 0, function () { | ||
var client, database, failSilently, result, error_1; | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: | ||
case 0: return [4, mongodb_1.MongoClient.connect(args.uri)]; | ||
case 1: | ||
client = _b.sent(); | ||
database = client.db(args.database); | ||
@@ -57,11 +58,20 @@ failSilently = (_a = args.options) === null || _a === void 0 ? void 0 : _a.failSilently; | ||
} | ||
_b.label = 1; | ||
case 1: | ||
_b.trys.push([1, 3, , 4]); | ||
_b.label = 2; | ||
case 2: | ||
_b.trys.push([2, 5, , 6]); | ||
return [4, database.createCollection(args.collection, args.options)]; | ||
case 2: | ||
case 3: | ||
result = _b.sent(); | ||
client.close(); | ||
return [2, 'Collection created']; | ||
case 3: | ||
console.log(result); | ||
return [4, client.close()]; | ||
case 4: | ||
_b.sent(); | ||
if (result) { | ||
return [2, 'Collection created']; | ||
} | ||
else { | ||
return [2, 'Error']; | ||
} | ||
return [3, 6]; | ||
case 5: | ||
error_1 = _b.sent(); | ||
@@ -72,30 +82,39 @@ if (failSilently) | ||
throw error_1; | ||
return [3, 4]; | ||
case 4: return [2]; | ||
return [3, 6]; | ||
case 6: return [2]; | ||
} | ||
}); | ||
}); }); | ||
}); | ||
} | ||
exports.createCollection = createCollection; | ||
function dropCollection(args) { | ||
var _this = this; | ||
return mongodb_1.MongoClient.connect(args.uri).then(function (client) { return __awaiter(_this, void 0, void 0, function () { | ||
var database, failSilently, result, error_2; | ||
var _a; | ||
var _a; | ||
return __awaiter(this, void 0, void 0, function () { | ||
var client, failSilently, database, result, error_2; | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: | ||
database = client.db(args.database); | ||
case 0: return [4, mongodb_1.MongoClient.connect(args.uri)]; | ||
case 1: | ||
client = _b.sent(); | ||
failSilently = (_a = args.options) === null || _a === void 0 ? void 0 : _a.failSilently; | ||
if (args.options) | ||
delete args.options.failSilently; | ||
_b.label = 1; | ||
case 1: | ||
_b.trys.push([1, 3, , 4]); | ||
_b.label = 2; | ||
case 2: | ||
_b.trys.push([2, 5, , 6]); | ||
database = client.db(args.database); | ||
return [4, database.dropCollection(args.collection, args.options)]; | ||
case 2: | ||
case 3: | ||
result = _b.sent(); | ||
client.close(); | ||
return [2, 'Collection dropped']; | ||
case 3: | ||
return [4, client.close()]; | ||
case 4: | ||
_b.sent(); | ||
if (result) { | ||
return [2, 'Collection dropped']; | ||
} | ||
else { | ||
return [2, 'Error']; | ||
} | ||
return [3, 6]; | ||
case 5: | ||
error_2 = _b.sent(); | ||
@@ -106,8 +125,8 @@ if (failSilently) | ||
throw error_2; | ||
return [3, 4]; | ||
case 4: return [2]; | ||
return [3, 6]; | ||
case 6: return [2]; | ||
} | ||
}); | ||
}); }); | ||
}); | ||
} | ||
exports.dropCollection = dropCollection; |
export declare function deleteOne(args: any): Promise<string>; | ||
export declare function deleteMany(args: any): Promise<string>; |
@@ -17,3 +17,3 @@ "use strict"; | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (g && (g = 0, op[0] && (_ = 0)), _) try { | ||
while (_) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
@@ -57,3 +57,5 @@ if (y = 0, t) op = [op[0] & 2, t.value]; | ||
result = _a.sent(); | ||
client.close(); | ||
return [4, client.close()]; | ||
case 2: | ||
_a.sent(); | ||
return [2, result.deletedCount + ' document deleted']; | ||
@@ -79,3 +81,5 @@ } | ||
result = _a.sent(); | ||
client.close(); | ||
return [4, client.close()]; | ||
case 2: | ||
_a.sent(); | ||
return [2, result.deletedCount + ' documents deleted']; | ||
@@ -82,0 +86,0 @@ } |
@@ -1,5 +0,4 @@ | ||
/// <reference types="node" /> | ||
export declare function findOne(args: any): Promise<Buffer | null>; | ||
export declare function findOneAndUpdate(args: any): Promise<Buffer | null>; | ||
export declare function findOneAndDelete(args: any): Promise<Buffer | null>; | ||
export declare function findMany(args: any): Promise<Buffer>; | ||
export declare function findOne(args: any): Promise<Uint8Array | null>; | ||
export declare function findOneAndUpdate(args: any): Promise<Uint8Array | null>; | ||
export declare function findOneAndDelete(args: any): Promise<Uint8Array | null>; | ||
export declare function findMany(args: any): Promise<Uint8Array>; |
@@ -17,3 +17,3 @@ "use strict"; | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (g && (g = 0, op[0] && (_ = 0)), _) try { | ||
while (_) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
@@ -20,0 +20,0 @@ if (y = 0, t) op = [op[0] & 2, t.value]; |
export declare function insertOne(args: any): Promise<any>; | ||
export declare function insertMany(args: any): Promise<any>; |
@@ -17,3 +17,3 @@ "use strict"; | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (g && (g = 0, op[0] && (_ = 0)), _) try { | ||
while (_) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
@@ -49,3 +49,3 @@ if (y = 0, t) op = [op[0] & 2, t.value]; | ||
return [2, mongodb_1.MongoClient.connect(args.uri).then(function (client) { return __awaiter(_this, void 0, void 0, function () { | ||
var res, err_1; | ||
var collection, result, err_1; | ||
return __generator(this, function (_a) { | ||
@@ -55,12 +55,10 @@ switch (_a.label) { | ||
_a.trys.push([0, 3, , 5]); | ||
return [4, client | ||
.db(args.database) | ||
.collection(args.collection) | ||
.insertOne(args.document, args.options)]; | ||
collection = client.db(args.database).collection(args.collection); | ||
return [4, collection.insertOne(args.document, args.options)]; | ||
case 1: | ||
res = _a.sent(); | ||
result = _a.sent(); | ||
return [4, client.close()]; | ||
case 2: | ||
_a.sent(); | ||
return [2, res.insertedId]; | ||
return [2, result.insertedId]; | ||
case 3: | ||
@@ -95,3 +93,5 @@ err_1 = _a.sent(); | ||
result = _a.sent(); | ||
client.close(); | ||
return [4, client.close()]; | ||
case 2: | ||
_a.sent(); | ||
return [2, result.insertedIds]; | ||
@@ -98,0 +98,0 @@ } |
@@ -1,3 +0,2 @@ | ||
/// <reference types="node" /> | ||
export declare function updateOne(args: any): Promise<Buffer | null>; | ||
export declare function updateMany(args: any): Promise<Buffer | null>; | ||
export declare function updateOne(args: any): Promise<Uint8Array | null>; | ||
export declare function updateMany(args: any): Promise<Uint8Array | null>; |
@@ -17,3 +17,3 @@ "use strict"; | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (g && (g = 0, op[0] && (_ = 0)), _) try { | ||
while (_) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
@@ -20,0 +20,0 @@ if (y = 0, t) op = [op[0] & 2, t.value]; |
export declare function validate(args: any): void; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ Copyright 2023 Jovan Ilić |
{ | ||
"name": "cypress-mongodb", | ||
"version": "5.5.0", | ||
"version": "6.0.0", | ||
"description": "Cypress MongoDB plugin", | ||
@@ -33,8 +33,8 @@ "main": "./dist/index.js", | ||
"devDependencies": { | ||
"@faker-js/faker": "^8.0.1", | ||
"@types/node": "^20.2.5", | ||
"cypress": "^12.13.0", | ||
"prettier": "^2.8.8", | ||
"typescript": "^5.0.4" | ||
"@faker-js/faker": "^8.0.2", | ||
"@types/node": "^20.5.9", | ||
"cypress": "^13.1.0", | ||
"prettier": "^3.0.3", | ||
"typescript": "^5.2.2" | ||
} | ||
} |
@@ -16,3 +16,3 @@ # Introduction | ||
| MongoDB | `4.4`, `5.0`, `6.0` | | ||
| Node | `16.20`, `18.16`, `19.9` | | ||
| Node | `16.20`, `18.16`, `20.5` |npm | ||
| MongoDB Node.js Driver | `4.10.0` | | ||
@@ -25,60 +25,21 @@ | ||
# Environment setup | ||
# Plugin configuration | ||
Add the following `env` properties in your `cypress.config.js` file: | ||
In your `cypress.config.js` file, make the following changes: | ||
1. Add the necessary `mongodb` environment variables under `env` block | ||
2. Import and load the plugin under `e2e` block | ||
```JavaScript | ||
{ | ||
module.exports = defineConfig({ | ||
"env": { | ||
"mongodb": { | ||
"uri": "mongodb://localhost:27017", | ||
"database": "database_name", | ||
"collection": "collection_name" | ||
} | ||
} | ||
}); | ||
} | ||
``` | ||
import { configurePlugin } from 'cypress-mongodb'; | ||
<b>Note:</b> only `mongodb.uri` is mandatory, you can always override/set database and collection names in each cypress | ||
mongodb command using options. You can set both local and remote urls. | ||
# Plugin configuration - JavaScript | ||
In your `cypress.config.js` add the following: | ||
```JavaScript | ||
const mongo = require('cypress-mongodb'); | ||
module.exports = defineConfig({ | ||
env: { | ||
mongodb: { | ||
uri: 'mongodb://localhost:27017', | ||
database: 'database_name', | ||
collection: 'collection_name' | ||
} | ||
}, | ||
e2e: { | ||
setupNodeEvents(on, config) { | ||
mongo.configurePlugin(on); | ||
} | ||
} | ||
}); | ||
``` | ||
In your `cypress/support/e2e.js` add the following: | ||
```JavaScript | ||
const mongo = require('cypress-mongodb'); | ||
mongo.addCommands(); | ||
``` | ||
# Plugin configuration - TypeScript | ||
In your `cypress.config.ts` add the following: | ||
```TypeScript | ||
import {defineConfig} from 'cypress' | ||
import {configurePlugin} from 'cypress-mongodb'; | ||
/** | ||
* @type {Cypress.PluginConfig} | ||
*/ | ||
export default defineConfig({ | ||
e2e: { | ||
setupNodeEvents(on) { | ||
configurePlugin(on); | ||
@@ -90,7 +51,9 @@ } | ||
In your `cypress/support/e2e.ts` add the following: | ||
<b>Note:</b> only `mongodb.uri` is mandatory, you can always override/set database and collection names in each cypress | ||
mongodb command using options. You can set both local and remote urls. | ||
```TypeScript | ||
import {addCommands} from "cypress-mongodb"; | ||
Finally, in your `cypress/support/e2e.js` add the following: | ||
```JavaScript | ||
import { addCommands } from 'cypress-mongodb/dist/index-browser'; | ||
addCommands(); | ||
@@ -97,0 +60,0 @@ ``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
72623
33
1182
272