How to use driver.connect method in Cypress

Best JavaScript code snippet using cypress

sqlite3_test.js

Source:sqlite3_test.js Github

copy

Full Screen

...23 .describe('sqlite3')24 .addBatch({25 createTable: {26 topic: function () {27 driver.connect(28 config,29 internals,30 function (err, db) {31 assert.isNull(err);32 db.createTable(33 'event',34 {35 id: {36 type: dataType.INTEGER,37 primaryKey: true,38 autoIncrement: true,39 notNull: true40 },41 str: { type: dataType.STRING, unique: true },42 txt: {43 type: dataType.TEXT,44 notNull: true,45 defaultValue: 'foo'46 },47 intg: dataType.INTEGER,48 rel: dataType.REAL,49 dt: dataType.DATE_TIME,50 bl: dataType.BOOLEAN,51 raw: {52 type: dataType.DATE_TIME,53 defaultValue: {54 raw: 'CURRENT_TIMESTAMP'55 }56 },57 special: {58 type: dataType.DATE_TIME,59 defaultValue: {60 special: 'CURRENT_TIMESTAMP'61 }62 }63 },64 this.callback.bind(this, null, db)65 );66 }.bind(this)67 );68 },69 teardown: function (db) {70 db.close()71 .then(function () {72 return unlink(config.filename);73 })74 .nodeify(this.callback);75 },76 'has resulting table metadata': {77 topic: function (db) {78 dbmeta(79 'sqlite3',80 { connection: db.connection },81 function (err, meta) {82 if (err) {83 return this.callback(err);84 }85 meta.getTables(this.callback);86 }.bind(this)87 );88 },89 'containing the event table': function (err, tables) {90 assert.isNull(err);91 var table = findByName(tables, 'event');92 assert.isNotNull(table);93 assert.strictEqual(table.getName(), 'event');94 }95 },96 'has column metadata for the event table': {97 topic: function (db) {98 dbmeta(99 'sqlite3',100 { connection: db.connection },101 function (err, meta) {102 if (err) {103 return this.callback(err);104 }105 meta.getColumns('event', this.callback);106 }.bind(this)107 );108 },109 'with 9 columns': function (err, columns) {110 assert.isNotNull(columns);111 assert.isNull(err);112 assert.strictEqual(columns.length, 9);113 },114 'that has integer id column that is primary key, non-nullable, and auto increments': function (115 err,116 columns117 ) {118 var column = findByName(columns, 'id');119 assert.isNull(err);120 assert.strictEqual(column.getDataType(), 'INTEGER');121 assert.strictEqual(column.isPrimaryKey(), true);122 assert.strictEqual(column.isNullable(), false);123 assert.strictEqual(column.isAutoIncrementing(), true);124 },125 'that has text str column that is unique': function (err, columns) {126 var column = findByName(columns, 'str');127 assert.isNull(err);128 assert.strictEqual(column.getDataType(), 'VARCHAR');129 assert.strictEqual(column.isUnique(), true);130 },131 'that has text txt column that is non-nullable': function (132 err,133 columns134 ) {135 var column = findByName(columns, 'txt');136 assert.isNull(err);137 assert.strictEqual(column.getDataType(), 'TEXT');138 assert.strictEqual(column.isNullable(), false);139 // assert.strictEqual(column.getDefaultValue(), 'foo');140 },141 'that has integer intg column': function (err, columns) {142 var column = findByName(columns, 'intg');143 assert.isNull(err);144 assert.strictEqual(column.getDataType(), 'INTEGER');145 assert.strictEqual(column.isNullable(), true);146 },147 'that has real rel column': function (err, columns) {148 var column = findByName(columns, 'rel');149 assert.isNull(err);150 assert.strictEqual(column.getDataType(), 'REAL');151 assert.strictEqual(column.isNullable(), true);152 },153 'that has integer dt column': function (err, columns) {154 var column = findByName(columns, 'dt');155 assert.isNull(err);156 assert.strictEqual(column.getDataType(), 'DATETIME');157 assert.strictEqual(column.isNullable(), true);158 },159 'that has boolean bl column': function (err, columns) {160 assert.isNull(err);161 var column = findByName(columns, 'bl');162 assert.strictEqual(column.getDataType(), 'BOOLEAN');163 assert.strictEqual(column.isNullable(), true);164 },165 'that has raw column': function (err, columns) {166 assert.isNull(err);167 var column = findByName(columns, 'raw');168 assert.strictEqual(column.getDefaultValue(), 'CURRENT_TIMESTAMP');169 },170 'that has special CURRENT_TIMESTAMP column': function (err, columns) {171 assert.isNull(err);172 var column = findByName(columns, 'special');173 assert.strictEqual(column.getDefaultValue(), 'CURRENT_TIMESTAMP');174 }175 }176 }177 })178 .addBatch({179 dropTable: {180 topic: function () {181 driver.connect(182 config,183 internals,184 function (err, db) {185 assert.isNull(err);186 db.createTable(187 'event',188 {189 id: {190 type: dataType.INTEGER,191 primaryKey: true,192 autoIncrement: true193 }194 },195 function (err) {196 if (err) {197 return this.callback(err);198 }199 db.dropTable('event', this.callback.bind(this, null, db));200 }.bind(this)201 );202 }.bind(this)203 );204 },205 teardown: function (db) {206 db.close()207 .then(function () {208 return unlink(config.filename);209 })210 .nodeify(this.callback);211 },212 'has table metadata': {213 topic: function (db) {214 dbmeta(215 'sqlite3',216 { connection: db.connection },217 function (err, meta) {218 if (err) {219 return this.callback(err);220 }221 meta.getTables(this.callback);222 }.bind(this)223 );224 },225 'containing no tables': function (err, tables) {226 assert.isNull(err);227 assert.isNotNull(tables);228 assert.strictEqual(tables.length, 1);229 }230 }231 }232 })233 .addBatch({234 renameTable: {235 topic: function () {236 driver.connect(237 config,238 internals,239 function (err, db) {240 assert.isNull(err);241 db.createTable(242 'event',243 {244 id: {245 type: dataType.INTEGER,246 primaryKey: true,247 autoIncrement: true248 }249 },250 function () {251 db.renameTable(252 'event',253 'functions',254 this.callback.bind(this, null, db)255 );256 }.bind(this)257 );258 }.bind(this)259 );260 },261 teardown: function (db) {262 db.close()263 .then(function () {264 return unlink(config.filename);265 })266 .nodeify(this.callback);267 },268 'has table metadata': {269 topic: function (db) {270 dbmeta(271 'sqlite3',272 { connection: db.connection },273 function (err, meta) {274 if (err) {275 return this.callback(err);276 }277 meta.getTables(this.callback);278 }.bind(this)279 );280 },281 'containing the functions table': function (err, tables) {282 assert.isNull(err);283 assert.isNotNull(tables);284 var table = findByName(tables, 'functions');285 assert.strictEqual(table.getName(), 'functions');286 assert.isNull(findByName(tables, 'event'));287 }288 }289 }290 })291 .addBatch({292 addColumn: {293 topic: function () {294 driver.connect(295 config,296 internals,297 function (err, db) {298 assert.isNull(err);299 db.createTable(300 'event',301 {302 id: {303 type: dataType.INTEGER,304 primaryKey: true,305 autoIncrement: true306 }307 },308 function () {309 db.addColumn(310 'event',311 'title',312 'string',313 this.callback.bind(this, null, db)314 );315 }.bind(this)316 );317 }.bind(this)318 );319 },320 teardown: function (db) {321 db.close()322 .then(function () {323 return unlink(config.filename);324 })325 .nodeify(this.callback);326 },327 'has column metadata': {328 topic: function (db) {329 dbmeta(330 'sqlite3',331 { connection: db.connection },332 function (err, meta) {333 if (err) {334 return this.callback(err);335 }336 meta.getColumns('event', this.callback);337 }.bind(this)338 );339 },340 'with additional title column': function (err, columns) {341 assert.isNull(err);342 assert.isNotNull(columns);343 assert.strictEqual(columns.length, 2);344 var column = findByName(columns, 'title');345 assert.strictEqual(column.getName(), 'title');346 assert.strictEqual(column.getDataType(), 'VARCHAR');347 }348 }349 }350 // removeColumn351 // renameColumn352 // changeColumn353 })354 .addBatch({355 addIndex: {356 topic: function () {357 driver.connect(358 config,359 internals,360 function (err, db) {361 assert.isNull(err);362 db.createTable(363 'event',364 {365 id: {366 type: dataType.INTEGER,367 primaryKey: true,368 autoIncrement: true369 },370 title: { type: dataType.STRING }371 },372 function () {373 db.addIndex(374 'event',375 'event_title',376 'title',377 this.callback.bind(this, null, db)378 );379 }.bind(this)380 );381 }.bind(this)382 );383 },384 teardown: function (db) {385 db.close()386 .then(function () {387 return unlink(config.filename);388 })389 .nodeify(this.callback);390 },391 'has resulting index metadata': {392 topic: function (db) {393 dbmeta(394 'sqlite3',395 { connection: db.connection },396 function (err, meta) {397 if (err) {398 return this.callback(err);399 }400 meta.getIndexes('event', this.callback);401 }.bind(this)402 );403 },404 'with additional index': function (err, indexes) {405 assert.isNull(err);406 assert.isNotNull(indexes);407 var index = findByName(indexes, 'event_title');408 assert.strictEqual(index.getName(), 'event_title');409 assert.strictEqual(index.getTableName(), 'event');410 assert.strictEqual(index.getColumnName(), 'title');411 }412 }413 }414 })415 .addBatch({416 insert: {417 topic: function () {418 driver.connect(419 config,420 internals,421 function (err, _db) {422 assert.isNull(err);423 db = _db;424 db.createTable('event', {425 id: {426 type: dataType.INTEGER,427 primaryKey: true,428 autoIncrement: true429 },430 title: { type: dataType.STRING }431 })432 .then(function () {433 return db.insert('event', ['id', 'title'], [2, 'title']);434 })435 .then(function () {436 return db.all('SELECT * from event;');437 })438 .then(function (data) {439 return data;440 })441 .nodeify(this.callback);442 }.bind(this)443 );444 },445 teardown: function () {446 db.close()447 .then(function () {448 return unlink(config.filename);449 })450 .nodeify(this.callback);451 },452 'with additional row': function (err, data) {453 assert.isNull(err);454 assert.strictEqual(data.length, 1);455 }456 }457 })458 .addBatch({459 insertWithSingleQuotes: {460 topic: function () {461 driver.connect(462 config,463 internals,464 function (err, _db) {465 assert.isNull(err);466 db = _db;467 db.createTable('event', {468 id: {469 type: dataType.INTEGER,470 primaryKey: true,471 autoIncrement: true472 },473 title: { type: dataType.STRING }474 })475 .then(function () {476 return db.insert(477 'event',478 ['id', 'title'],479 [2, "Bill's Mother's House"]480 );481 })482 .then(function () {483 return db.all('SELECT * from event;');484 })485 .nodeify(this.callback);486 }.bind(this)487 );488 },489 teardown: function () {490 db.close()491 .then(function () {492 return unlink(config.filename);493 })494 .nodeify(this.callback);495 },496 'with additional row': function (err, data) {497 assert.isNull(err);498 assert.strictEqual(data.length, 1);499 }500 }501 })502 .addBatch({503 removeIndex: {504 topic: function () {505 driver.connect(506 config,507 internals,508 function (err, db) {509 assert.isNull(err);510 db.createTable(511 'event',512 {513 id: {514 type: dataType.INTEGER,515 primaryKey: true,516 autoIncrement: true517 },518 title: { type: dataType.STRING }519 },520 function (err) {521 assert.isNull(err);522 db.addIndex(523 'event',524 'event_title',525 'title',526 function (err) {527 assert.isNull(err);528 db.removeIndex(529 'event_title',530 this.callback.bind(this, null, db)531 );532 }.bind(this)533 );534 }.bind(this)535 );536 }.bind(this)537 );538 },539 teardown: function (db) {540 db.close()541 .then(function () {542 return unlink(config.filename);543 })544 .nodeify(this.callback);545 },546 'has resulting index metadata': {547 topic: function (db) {548 dbmeta(549 'sqlite3',550 { connection: db.connection },551 function (err, meta) {552 if (err) {553 return this.callback(err);554 }555 meta.getIndexes('event', this.callback);556 }.bind(this)557 );558 },559 'without index': function (err, indexes) {560 assert.isNull(err);561 assert.isNotNull(indexes);562 assert.strictEqual(indexes.length, 0);563 }564 }565 }566 })567 .addBatch({568 removeIndexWithTableName: {569 topic: function () {570 driver.connect(571 config,572 internals,573 function (err, db) {574 assert.isNull(err);575 db.createTable(576 'event',577 {578 id: {579 type: dataType.INTEGER,580 primaryKey: true,581 autoIncrement: true582 },583 title: { type: dataType.STRING }584 },585 function (err) {586 assert.isNull(err);587 db.addIndex(588 'event',589 'event_title',590 'title',591 function (err) {592 assert.isNull(err);593 db.removeIndex(594 'event',595 'event_title',596 this.callback.bind(this, null, db)597 );598 }.bind(this)599 );600 }.bind(this)601 );602 }.bind(this)603 );604 },605 teardown: function (db) {606 db.close()607 .then(function () {608 return unlink(config.filename);609 })610 .nodeify(this.callback);611 },612 'has resulting index metadata': {613 topic: function (db) {614 dbmeta(615 'sqlite3',616 { connection: db.connection },617 function (err, meta) {618 if (err) {619 return this.callback(err);620 }621 meta.getIndexes('event', this.callback);622 }.bind(this)623 );624 },625 'without index': function (err, indexes) {626 assert.isNull(err);627 assert.isNotNull(indexes);628 assert.strictEqual(indexes.length, 0);629 }630 }631 }632 })633 .addBatch({634 createMigrationsTable: {635 topic: function () {636 driver.connect(637 config,638 internals,639 function (err, db) {640 assert.isNull(err);641 db.createMigrationsTable(this.callback.bind(this, null, db));642 }.bind(this)643 );644 },645 teardown: function (db) {646 db.close()647 .then(function () {648 return unlink(config.filename);649 })650 .nodeify(this.callback);...

Full Screen

Full Screen

util.js

Source:util.js Github

copy

Full Screen

1const { suite } = require('uvu');2const semiver = require('semiver');3const assert = require('uvu/assert');4const { join, isAbsolute, resolve } = require('path');5const $ = require('../lib/util');6const fixtures = join(__dirname, 'fixtures');7const version = process.version.substring(1);8const hasImports = semiver(version, '12.0.0') > 0;9// ---10const glob = suite('$.glob', {11 dir: join(fixtures, 'pg', 'migrations')12});13glob('usage', async ctx => {14 const out = await $.glob(ctx.dir);15 assert.ok(Array.isArray(out), 'returns Promise<Array>');16 assert.is(out.length, 6, '~> has 6 items');17 const first = out[0];18 assert.type(first, 'object', 'items are objects');19 assert.type(first.name, 'string', '~> has "name" string');20 assert.type(first.abs, 'string', '~> has "abs" string');21 assert.ok(isAbsolute(first.abs), '~~> is absolute path');22 const names = out.map(x => x.name);23 const expects = ['001.js', '002.js', '003.js', '004.js', '005.js', '006.js'];24 assert.equal(names, expects, '~> file order is expected');25});26glob('throws', async ctx => {27 let caught = false;28 try {29 await $.glob(join(ctx.dir, 'foobar'));30 assert.unreachable('should not run');31 } catch (err) {32 assert.instance(err, Error, 'throws an Error');33 assert.is(err.code, 'ENOENT', '~> is "ENOENT" code');34 assert.ok(err.stack.includes('no such file or directory'), '~> has detail');35 caught = true;36 }37 assert.ok(caught);38});39glob.run();40// ---41const diff = suite('$.diff');42diff('usage', () => {43 const exists = ['001', '002', '003'].map(name => ({ name }));44 const locals = ['001', '002', '003', '004', '005'].map(name => ({ name }));45 const output = $.diff(exists, locals);46 assert.ok(Array.isArray(output), 'returns an Array');47 assert.ok(output.every(x => locals.includes(x)), '~> only returns items from `locals` list');48 assert.is(output.length, 2, '~> has 2 NEW items');49 const names = output.map(x => x.name);50 assert.equal(names, ['004', '005']);51});52diff('identical', () => {53 const exists = ['001', '002', '003'].map(name => ({ name }));54 const locals = ['001', '002', '003'].map(name => ({ name }));55 const output = $.diff(exists, locals);56 assert.ok(Array.isArray(output), 'returns an Array');57 assert.is(output.length, 0, '~> has 0 NEW items');58});59diff('throws sequence error', () => {60 let caught = false;61 try {62 const exists = ['001', '003'].map(name => ({ name }));63 const locals = ['001', '002', '003'].map(name => ({ name }));64 $.diff(exists, locals);65 assert.unreachable('SHOULD NOT REACH');66 } catch (err) {67 caught = true;68 assert.instance(err, Error, 'throws an Error');69 assert.is(err.message, `Cannot run "002" after "003" has been applied`);70 assert.ok(err.stack.length > err.message.length, '~> has "stack" details');71 }72 assert.ok(caught);73});74diff.run();75// ---76const pluck = suite('$.pluck');77// Note: Arrays are received in reverse78pluck('(utils) pluck', () => {79 // should return everything, in sync80 const foobar = ['003', '002', '001'];81 const exists = foobar.map(name => ({ name }));82 const locals = foobar.map(name => ({ name }));83 const output = $.pluck(exists, locals);84 assert.ok(Array.isArray(output), 'returns an Array');85 assert.ok(output.every(x => locals.includes(x)), '~> only returns items from `locals` list');86 assert.is(output.length, 3, '~> has 3 candidates');87 const names = output.map(x => x.name);88 assert.equal(names, foobar);89});90// Note: Arrays are received in reverse91pluck('locals >> exists', () => {92 // should NOT return items that don't exist yet93 const exists = ['003', '002', '001'].map(name => ({ name }));94 const locals = ['005', '004', '003', '002', '001'].map(name => ({ name }));95 const output = $.pluck(exists, locals);96 assert.ok(Array.isArray(output), 'returns an Array');97 assert.ok(output.every(x => locals.includes(x)), '~> only returns items from `locals` list');98 assert.is(output.length, 3, '~> has 3 candidates');99 const names = output.map(x => x.name);100 assert.equal(names, ['003', '002', '001']);101});102// Note: Arrays are received in reverse103pluck('exists >> locals :: throws', () => {104 let caught = false;105 try {106 // throws error because we don't have 005 definitions107 const exists = ['005', '004', '003', '002', '001'].map(name => ({ name }));108 const locals = ['003', '002', '001'].map(name => ({ name }));109 $.pluck(exists, locals);110 assert.unreachable('SHOULD NOT REACH');111 } catch (err) {112 caught = true;113 assert.instance(err, Error, 'throws an Error');114 assert.is(err.message, `Cannot find "005" migration file`);115 assert.ok(err.stack.length > err.message.length, '~> has "stack" details');116 }117 assert.ok(caught);118});119pluck.run();120// ---121const exists = suite('$.exists');122exists('success', () => {123 const output = $.exists('uvu');124 assert.type(output, 'string', 'returns string (success)');125 assert.is(output, require.resolve('uvu'))126});127exists('failure', () => {128 const output = $.exists('foobar');129 assert.type(output, 'boolean', 'returns boolean (fail)');130 assert.is(output, false)131});132exists('failure :: relative', () => {133 const output = $.exists('./foobar');134 assert.type(output, 'boolean', 'returns boolean (fail)');135 assert.is(output, false)136});137exists.run();138// ---139const detect = suite('$.detect');140detect('usage', () => {141 const ORDER = ['postgres', 'pg', 'mysql', 'mysql2', 'better-sqlite3'];142 const seen = [];143 const prev = $.exists;144 // @ts-ignore145 $.exists = x => {146 seen.push(x);147 }148 const foo = $.detect();149 assert.is(foo, undefined, 'returns undefined (failure)');150 assert.equal(seen, ORDER, '~> looks for drivers (ordered)');151 // @ts-ignore152 $.exists = x => x === 'pg';153 const bar = $.detect();154 assert.is(bar, 'pg', '~> found "pg" (mock)');155 $.exists = prev;156});157detect.run();158// ---159const load = suite('$.load');160load('success', async () => {161 const input = resolve('.', 'index.js'); // root/index.js162 const output = await $.load(input);163 assert.type(output, 'object', '~> returns _something_ if exists');164 assert.type(output.down, 'function', '~> had "down" export');165 assert.type(output.up, 'function', '~> had "up" export')166});167load('success w/ cwd', async () => {168 const input = resolve(__dirname, 'util.js'); // this file169 const output = await $.load(input);170 assert.type(output, 'object', '~> returns _something_ if exists')171});172load('failure', async () => {173 const foobar = resolve('.', 'foobar.ts'); // root dir174 try {175 await $.load(foobar);176 assert.unreachable();177 } catch (err) {178 assert.instance(err, Error);179 assert.is(err.code, 'MODULE_NOT_FOUND');180 assert.match(err.message, foobar);181 }182});183load.run();184// ---185const toConfig = suite('$.toConfig');186toConfig('direct :: CommonJS', async () => {187 const postgres = join(fixtures, 'postgres');188 const output = await $.toConfig('ley.config.js', postgres);189 // NOTE: interop handled190 assert.type(output, 'object');191 assert.is(output.database, 'ley_testing');192});193if (hasImports) {194 // gave ".mjs" -> no fuzzy matching195 toConfig('direct :: ES Module', async () => {196 const postgres = join(fixtures, 'postgres.esm');197 const output = await $.toConfig('ley.config.mjs', postgres);198 // NOTE: interop handled199 assert.type(output, 'object');200 assert.is(output.database, 'ley_testing');201 });202 // gave ".js" -> look for ".mjs" too203 toConfig('loose :: ES Module', async () => {204 const postgres = join(fixtures, 'postgres.esm');205 const output = await $.toConfig('ley.config.js', postgres);206 // NOTE: interop handled207 assert.type(output, 'object');208 assert.is(output.database, 'ley_testing');209 });210}211// gave ".cjs" -> does not exist; no fuzzy212toConfig('direct :: failure', async () => {213 const output = await $.toConfig('foobar.cjs', fixtures);214 assert.is(output, undefined);215});216toConfig.run();217// ---218const MigrationError = suite('$.MigrationError');219MigrationError('MigrationError', () => {220 const original = new Error('hello world');221 const migration = { name: '000.js', abs: 'path/to/000.js' };222 Object.assign(original, { code: 42703, position: 8, foobar: undefined });223 const error = new $.MigrationError(original, migration);224 assert.instance(error, $.MigrationError, 'is MigrationError');225 assert.instance(error, Error, '~> still inherits Error class');226 assert.ok(error.stack.length > 0, 'has "stack" trace');227 assert.ok(error.stack.length > original.stack.length, '~> is longer than original trace');228 assert.ok(error.stack.includes(original.stack), '~> contains original trace');229 assert.is(error.code, original.code, 'inherits original "code" property (custom)');230 assert.is(error.foobar, original.foobar, 'inherits original "foobar" property (custom)');231 assert.is(error.position, original.position, 'inherits original "position" property (custom)');232 assert.equal(error.migration, migration, 'attaches custom "migration" key w/ file data');233});234MigrationError.run();235// ---236const isDriver = suite('$.isDriver');237isDriver('connect', () => {238 assert.throws(239 () => $.isDriver({}),240 'Driver must have "connect" function'241 );242 assert.throws(243 () => $.isDriver({ connect: 123 }),244 'Driver must have "connect" function'245 );246});247isDriver('setup', () => {248 let noop = () => {};249 assert.throws(250 () => $.isDriver({ connect: noop }),251 'Driver must have "setup" function'252 );253 assert.throws(254 () => $.isDriver({ connect: noop, setup: 123 }),255 'Driver must have "setup" function'256 );257});258isDriver('loop', () => {259 let noop = () => {};260 assert.throws(261 () => $.isDriver({ connect: noop, setup: noop }),262 'Driver must have "loop" function'263 );264 assert.throws(265 () => $.isDriver({ connect: noop, setup: noop, loop: 123 }),266 'Driver must have "loop" function'267 );268});269isDriver('end', () => {270 let noop = () => {};271 assert.throws(272 () => $.isDriver({ connect: noop, setup: noop, loop: noop }),273 'Driver must have "end" function'274 );275 assert.throws(276 () => $.isDriver({ connect: noop, setup: noop, loop: noop, end: 123 }),277 'Driver must have "end" function'278 );279});...

Full Screen

Full Screen

2.connection.js

Source:2.connection.js Github

copy

Full Screen

...11 before('open connection', function () {12 driver = new Driver();13 });14 it('2.1 properly opens and releases connections', function (done) {15 driver.connect(config, function (err, connection) {16 should.not.exist(err);17 connection.close(function (err) {18 should.not.exist(err);19 });20 done();21 });22 });23 it('2.2 raises an exception if calling method, commit(), after closed', function (done) {24 driver.connect(config, function (err, connection) {25 should.not.exist(err);26 connection.close(function (err) {27 should.not.exist(err);28 connection.commit(function (err) {29 should.exist(err);30 should.strictEqual(err.message, "connection closed");31 done();32 });33 });34 });35 });36 it('2.3 raises an exception if calling method, rollback(), after closed', function (done) {37 driver.connect(config, function (err, connection) {38 should.not.exist(err);39 connection.close(function (err) {40 should.not.exist(err);41 connection.rollback(function (err) {42 should.exist(err);43 should.strictEqual(err.message, "connection closed");44 done();45 });46 });47 });48 });49 it('2.4 raises an exception if calling method, close(), after closed', function (done) {50 driver.connect(config, function (err, connection) {51 should.not.exist(err);52 connection.close(function (err) {53 should.not.exist(err);54 connection.close(function (err) {55 should.exist(err);56 should.strictEqual(err.message, "failed to close connection [connection closed]");57 done();58 });59 });60 });61 });62 it('2.5 raises an exception if calling method, execute(), after closed', function (done) {63 driver.connect(config, function (err, connection) {64 should.not.exist(err);65 connection.close(function (err) {66 should.not.exist(err);67 connection.execute('SELECT * FROM SYSTEM.CONNECTIONS', function (err, results) {68 should.exist(err);69 should.not.exist(results);70 should.strictEqual(err.message, "connection closed");71 done();72 });73 });74 });75 });76 it('2.10 setting auto-commit', function () {77 driver.connect(config, function (err, connection) {78 should.not.exist(err);79 describe('2.10.1 with non-boolean values raises an exception', function () {80 var defaultValue;81 beforeEach('get auto-commit default', function () {82 defaultValue = connection.autoCommit;83 });84 afterEach('reset auto-commit to default', function () {85 connection.autoCommit = defaultValue;86 });87 var setAsGlobalOption = function (setValue, callback) {88 should.throws(89 function () {90 connection.autoCommit = setValue;91 },92 /invalid type in assignment/93 );94 callback();95 };96 it('2.10.1 Negative - 0', function (done) {97 setAsGlobalOption(0, done);98 });99 it('2.10.2 Negative - negative number', function (done) {100 setAsGlobalOption(-1, done);101 });102 it('2.10.3 Negative - positive number', function (done) {103 setAsGlobalOption(1, done);104 });105 it('2.10.4 Negative - NaN', function (done) {106 setAsGlobalOption(NaN, done);107 });108 it('2.10.5 Negative - undefined', function (done) {109 setAsGlobalOption(undefined, done);110 });111 });112 after(function () {113 connection.close(function (err) {114 should.not.exist(err);115 });116 })117 });118 });119 it('2.11 setting read-only', function () {120 driver.connect(config, function (err, connection) {121 should.not.exist(err);122 describe('2.11.1 with non-boolean values raises an exception', function () {123 var defaultValue;124 beforeEach('get read-only default', function () {125 defaultValue = connection.readOnly;126 });127 afterEach('reset read-only to default', function () {128 connection.readOnly = defaultValue;129 });130 var setAsGlobalOption = function (setValue, callback) {131 should.throws(132 function () {133 connection.readOnly = setValue;134 },...

Full Screen

Full Screen

driver.js

Source:driver.js Github

copy

Full Screen

...15}16driver.insert = async function (table, data) {17 var status = false;18 try {19 var connection = await driver.connect();20 var database = connection.db;21 var collection = database.collection(table);22 data['created_at'] = new Date();23 var result = await collection.insertOne(data);24 status = true;25 } catch (e) {26 console.log(e);27 status = false;28 } finally {29 // Ensures that the client will close when you finish/error30 await connection.client.close();31 return status;32 }33}34driver.fetch = async function (table, query = {}) {35 var result = false;36 try {37 var connection = await driver.connect();38 var database = connection.db;39 var collection = database.collection(table);40 result = await collection.find(query).toArray();41 } catch (e) {42 console.log(e);43 result = false;44 } finally {45 // Ensures that the client will close when you finish/error46 await connection.client.close();47 return result;48 }49}50driver.update = async function (table, query, data) {51 var status = false;52 try {53 var connection = await driver.connect();54 var database = connection.db;55 var collection = database.collection(table);56 data['updated_at'] = new Date();57 data = {58 $set: data,59 $setOnInsert: {60 created_at: new Date()61 }62 };63 var options = {};64 await collection.updateOne(query, data, options);65 status = true;66 } catch (e) {67 console.log(e);68 status = false;69 } finally {70 // Ensures that the client will close when you finish/error71 await connection.client.close();72 return status;73 }74}75driver.delete = async function (table, query) {76 var status = false;77 try {78 var connection = await driver.connect();79 var database = connection.db;80 var collection = database.collection(table);81 await collection.deleteOne(query);82 status = true;83 } catch (e) {84 console.log(e);85 status = false;86 } finally {87 // Ensures that the client will close when you finish/error88 await connection.client.close();89 return status;90 }91}92driver.insertOrUpdate = async function (table, query, data) {93 var status = false;94 try {95 var connection = await driver.connect();96 var database = connection.db;97 var collection = database.collection(table);98 data['updated_at'] = new Date();99 data = {100 $set: data,101 $setOnInsert: {102 created_at: new Date()103 }104 };105 var options = { upsert: true };106 await collection.updateOne(query, data, options);107 status = true;108 } catch (e) {109 console.log(e);110 status = false;111 } finally {112 // Ensures that the client will close when you finish/error113 await connection.client.close();114 return status;115 }116}117driver.lookup = async function (table, joinTable, localField, foreignField, newCol, query = null) {118 var result = false;119 try {120 if(!newCol) newCol = localField;121 var connection = await driver.connect();122 var database = connection.db;123 var collection = database.collection(table);124 let aggregate = [125 { 126 $lookup: {127 from: joinTable,128 localField: localField,129 foreignField: foreignField,130 as: newCol131 }132 }133 ];134 if(query) {135 aggregate = [...

Full Screen

Full Screen

driver.spec.js

Source:driver.spec.js Github

copy

Full Screen

1const assert = require('assert');2const { kinit, kdestroy } = require('./helpers/kerberos');3const { buildGssapiConnectionString } = require('./helpers/connection-string');4const driver = require('./helpers/driver');5const { USER_PRINCIPAL,6 SERVER_WITH_DEFAULT_NAME,7 SERVER_WITH_ALTERNATE_NAME,8 EXPECTED_USER,9 USER_NAME,10 REALM11} = require('./constants');12describe('driver', () => {13 beforeEach(async() => {14 await kdestroy();15 await kinit('mongodb.user@EXAMPLE.COM', 'password');16 });17 after(async() => {18 await kdestroy();19 });20 describe('?authMechanism=GSSAPI&authSource=$external', () => {21 it('connects with a complete connection string to mongodb/ service principal', async() => {22 const user = await driver.connectAndReturnUser(23 buildGssapiConnectionString(24 USER_PRINCIPAL,25 SERVER_WITH_DEFAULT_NAME26 )27 );28 assert.deepStrictEqual(user, EXPECTED_USER);29 });30 describe('?gssapiServiceName', () => {31 it('is not supported anymore', async() => {32 const error = await driver.connectAndReturnUser(33 buildGssapiConnectionString(34 USER_PRINCIPAL,35 SERVER_WITH_ALTERNATE_NAME,36 { gssapiServiceName: 'alternate' }37 )38 ).catch(err => err);39 assert.strictEqual(error.message, 'option gssapiservicename is not supported');40 });41 });42 describe('?authMechanismProperties', () => {43 describe('SERVICE_NAME', () => {44 it('connects with alternate service name', async() => {45 const user = await driver.connectAndReturnUser(46 buildGssapiConnectionString(47 USER_PRINCIPAL,48 SERVER_WITH_ALTERNATE_NAME,49 { authMechanismProperties: 'SERVICE_NAME:alternate' }50 )51 );52 assert.deepStrictEqual(user, EXPECTED_USER);53 });54 });55 describe('gssapiServiceName', () => {56 it('is not supported in authMechanismProperties', async() => {57 const errorOrUser = await driver.connectAndReturnUser(58 buildGssapiConnectionString(59 USER_PRINCIPAL,60 SERVER_WITH_ALTERNATE_NAME,61 { authMechanismProperties: 'gssapiServiceName:alternate' }62 )63 ).catch(err => err);64 assert.ok(errorOrUser instanceof Error);65 });66 });67 describe('SERVICE_REALM', () => {68 it('specifies a realm if missing', async() => {69 const user = await driver.connectAndReturnUser(70 buildGssapiConnectionString(71 USER_NAME,72 SERVER_WITH_DEFAULT_NAME,73 { authMechanismProperties: `SERVICE_REALM:${REALM}` }74 )75 );76 assert.deepStrictEqual(user, EXPECTED_USER);77 });78 // NOTE: this would require a cross-realm setup to be tested properly79 it('overrides only the service realm if a user already has a realm', async() => {80 const user = await driver.connectAndReturnUser(81 buildGssapiConnectionString(82 USER_PRINCIPAL,83 SERVER_WITH_DEFAULT_NAME,84 { authMechanismProperties: `SERVICE_REALM:${REALM}` }85 )86 );87 assert.deepStrictEqual(user, EXPECTED_USER);88 });89 });90 });91 });...

Full Screen

Full Screen

3.promises.js

Source:3.promises.js Github

copy

Full Screen

...11 before('create driver', function () {12 driver = new Driver();13 });14 it('3.1 returns a promise from Connection.connect', function (done) {15 var promise = driver.connect(config);16 promise17 .then(function (connection) {18 connection.should.be.ok();19 connection.close(function (err) {20 if (err) {21 return done(err);22 } else {23 return done();24 }25 });26 })27 .catch(function (err) {28 should.not.exist(err);29 return done();30 });31 });32 it('3.2 returns a promise from connection.close', function (done) {33 driver.connect(config)34 .then(function (conn) {35 conn.should.be.ok();36 var promise = conn.close();37 return promise;38 })39 .then(function () {40 return done();41 })42 .catch(function (err) {43 should.not.exist(err);44 return done();45 });46 });47 it('3.2 returns a promise from connection.commit', function (done) {48 driver.connect(config)49 .then(function (conn) {50 conn.should.be.ok();51 var promise = conn.commit();52 return promise53 .then(function () {54 return conn.close()55 .then(done);56 });57 })58 .catch(function (err) {59 should.not.exist(err);60 return done();61 });62 });63 it('3.2 returns a promise from connection.rollback', function (done) {64 driver.connect(config)65 .then(function (conn) {66 conn.should.be.ok();67 var promise = conn.rollback();68 return promise69 .then(function () {70 return conn.close()71 .then(done);72 });73 })74 .catch(function (err) {75 should.not.exist(err);76 return done();77 });78 });79 it('3.3 can run the documentation promises sample', function (done) {80 driver.connect(config)81 .then(connection => {82 connection.execute('SELECT 1 FROM DUAL')83 .then(results => {84 results.getRows(1)85 .then(rows => console.log(rows))86 .catch(e => console.log(e.stack))87 })88 .catch(e => {89 console.log(e.stack());90 });91 })92 .catch(e => {93 console.log(e.stack());94 });...

Full Screen

Full Screen

app.js

Source:app.js Github

copy

Full Screen

1'use strict';2const {Driver, Pool} = require('./lib');3async function test_driver(){4 let driver = new Driver();5 driver.connect();6 let res_one = await driver.query("SELECT NOW() AS res_one");7 console.log(res_one);8 let res_two = await driver.query("SELECT NOW() AS res_two");9 console.log(res_two);10 driver.end();11}12async function test_pool(){13 let pool = new Pool();14 let res = await pool.query("SELECT NOW() AS res");15 console.log(res);16 pool = new Pool();17 res = await pool.query("SELECT NOW() AS res");18 console.log(res);19}20//test_driver();21//test_pool();22async function get_data(){23 let driver = new Driver();24 driver.connect();25 let res = await driver.query("SELECT * from mydata");26 console.log('id | names | contact');27 for(let i = 0; i < res.length; i++){28 console.log(res[i].id + ' | ' + res[i].names + ' | ' + res[i].contact);29 }30 driver.end();31}32get_data();33async function in_data(){34 let driver = new Driver();35 driver.connect();36 let res = await driver.query("INSERT INTO mydata VALUES(null, 'Mayde','8733')");37 console.log(res);38 driver.end();39}...

Full Screen

Full Screen

driver.test.js

Source:driver.test.js Github

copy

Full Screen

...8 driver.disconnect = disconnect9})10test('driver - does not disconnect if no active connection', async () => {11 driver.disconnect = jest.fn()12 await driver.connect(conn)13 expect(driver.disconnect).not.toBeCalled()14})15test('driver - disconnect if has active connection', async () => {16 driver.disconnect = jest.fn()17 await driver.connect(conn)18 await driver.connect(conn2)19 expect(driver.disconnect).toBeCalled()20})21test('driver - disconnect', async () => {22 const connection = await driver.connect(conn)23 await driver.disconnect()24 expect(connection.close).toBeCalled()25})26test('driver - return connection', async () => {27 await driver.connect(conn)28 const c = driver.getConnection()29 expect(c).toBeDefined()...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('Google Search', () => {2 it('should search for the word Selenium', () => {3 const searchInput = $('input[name="q"]')4 searchInput.setValue('Selenium')5 browser.keys('Enter')6 })7})

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('My First Test', function() {2 it('Does not do much!', function() {3 cy.contains('type').click()4 cy.url().should('include', '/commands/actions')5 cy.get('.action-email')6 .type('

Full Screen

Using AI Code Generation

copy

Full Screen

1Cypress.Commands.add('connect', (url) => {2 cy.window().then((window) => {3 window.driver.connect(url);4 });5});6Cypress.Commands.add('disconnect', () => {7 cy.window().then((window) => {8 window.driver.disconnect();9 });10});11Cypress.Commands.add('emit', (event, data) => {12 cy.window().then((window) => {13 window.driver.emit(event, data);14 });15});16Cypress.Commands.add('on', (event, callback) => {17 cy.window().then((window) => {18 window.driver.on(event, callback);19 });20});21Cypress.Commands.add('removeListener', (event, callback) => {22 cy.window().then((window) => {23 window.driver.removeListener(event, callback);24 });25});26Cypress.Commands.add('onConnect', (callback) => {27 cy.window().then((window) => {28 window.driver.onConnect(callback);29 });30});31Cypress.Commands.add('onDisconnect', (callback) => {32 cy.window().then((window) => {33 window.driver.onDisconnect(callback);34 });35});36Cypress.Commands.add('onEvent', (event, callback) => {37 cy.window().then((window) => {38 window.driver.onEvent(event, callback);39 });40});41Cypress.Commands.add('onMessage', (callback) => {42 cy.window().then((window) => {43 window.driver.onMessage(callback);44 });45});46Cypress.Commands.add('onReconnect', (callback) => {47 cy.window().then((window) => {48 window.driver.onReconnect(callback);49 });50});

Full Screen

Cypress Tutorial

Cypress is a renowned Javascript-based open-source, easy-to-use end-to-end testing framework primarily used for testing web applications. Cypress is a relatively new player in the automation testing space and has been gaining much traction lately, as evidenced by the number of Forks (2.7K) and Stars (42.1K) for the project. LambdaTest’s Cypress Tutorial covers step-by-step guides that will help you learn from the basics till you run automation tests on LambdaTest.

Chapters:

  1. What is Cypress? -
  2. Why Cypress? - Learn why Cypress might be a good choice for testing your web applications.
  3. Features of Cypress Testing - Learn about features that make Cypress a powerful and flexible tool for testing web applications.
  4. Cypress Drawbacks - Although Cypress has many strengths, it has a few limitations that you should be aware of.
  5. Cypress Architecture - Learn more about Cypress architecture and how it is designed to be run directly in the browser, i.e., it does not have any additional servers.
  6. Browsers Supported by Cypress - Cypress is built on top of the Electron browser, supporting all modern web browsers. Learn browsers that support Cypress.
  7. Selenium vs Cypress: A Detailed Comparison - Compare and explore some key differences in terms of their design and features.
  8. Cypress Learning: Best Practices - Take a deep dive into some of the best practices you should use to avoid anti-patterns in your automation tests.
  9. How To Run Cypress Tests on LambdaTest? - Set up a LambdaTest account, and now you are all set to learn how to run Cypress tests.

Certification

You can elevate your expertise with end-to-end testing using the Cypress automation framework and stay one step ahead in your career by earning a Cypress certification. Check out our Cypress 101 Certification.

YouTube

Watch this 3 hours of complete tutorial to learn the basics of Cypress and various Cypress commands with the Cypress testing at LambdaTest.

Run Cypress automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful