How to use getPathsAndIds method in Cypress

Best JavaScript code snippet using cypress

project_spec.js

Source:project_spec.js Github

copy

Full Screen

...923 ])924 sinon.stub(settings, 'id').resolves('id-123')925 })926 it('returns array of objects with paths and ids', () => {927 return getPathsAndIds().then((pathsAndIds) => {928 expect(pathsAndIds).to.eql([929 {930 path: '/path/to/first',931 id: 'id-123',932 },933 {934 path: '/path/to/second',935 id: 'id-123',936 },937 ])938 })939 })940 })941 context('.getProjectStatuses', () => {...

Full Screen

Full Screen

events_spec.js

Source:events_spec.js Github

copy

Full Screen

1require('../../spec_helper')2const EE = require('events')3const extension = require('@packages/extension')4const electron = require('electron')5const Promise = require('bluebird')6const debug = require('debug')('test')7const chromePolicyCheck = require(`${root}../lib/util/chrome_policy_check`)8const cache = require(`${root}../lib/cache`)9const logger = require(`${root}../lib/logger`)10const { ProjectE2E } = require(`${root}../lib/project-e2e`)11const { ProjectBase } = require(`${root}../lib/project-base`)12const Updater = require(`${root}../lib/updater`)13const user = require(`${root}../lib/user`)14const errors = require(`${root}../lib/errors`)15const browsers = require(`${root}../lib/browsers`)16const openProject = require(`${root}../lib/open_project`)17const open = require(`${root}../lib/util/open`)18const auth = require(`${root}../lib/gui/auth`)19const logs = require(`${root}../lib/gui/logs`)20const events = require(`${root}../lib/gui/events`)21const dialog = require(`${root}../lib/gui/dialog`)22const files = require(`${root}../lib/gui/files`)23const ensureUrl = require(`${root}../lib/util/ensure-url`)24const konfig = require(`${root}../lib/konfig`)25const api = require(`${root}../lib/api`)26describe('lib/gui/events', () => {27 beforeEach(function () {28 this.send = sinon.stub()29 this.options = {}30 this.cookies = sinon.stub({31 get () {},32 set () {},33 remove () {},34 })35 this.event = {36 sender: {37 send: this.send,38 session: {39 cookies: this.cookies,40 },41 },42 }43 this.bus = new EE()44 sinon.stub(electron.ipcMain, 'on')45 sinon.stub(electron.ipcMain, 'removeAllListeners')46 this.handleEvent = (type, arg) => {47 const id = `${type}-${Math.random()}`48 return Promise49 .try(() => {50 return events.handleEvent(this.options, this.bus, this.event, id, type, arg)51 }).return({52 sendCalledWith: (data) => {53 expect(this.send).to.be.calledWith('response', { id, data })54 },55 sendErrCalledWith: (err) => {56 expect(this.send).to.be.calledWith('response', { id, __error: errors.clone(err, { html: true }) })57 },58 })59 }60 })61 context('.stop', () => {62 it('calls ipc#removeAllListeners', () => {63 events.stop()64 expect(electron.ipcMain.removeAllListeners).to.be.calledOnce65 })66 })67 context('.start', () => {68 it('ipc attaches callback on request', () => {69 sinon.stub(events, 'handleEvent')70 events.start({ foo: 'bar' })71 expect(electron.ipcMain.on).to.be.calledWith('request')72 })73 it('partials in options in request callback', () => {74 electron.ipcMain.on.yields('arg1', 'arg2')75 const handleEvent = sinon.stub(events, 'handleEvent')76 events.start({ foo: 'bar' }, {})77 expect(handleEvent).to.be.calledWith({ foo: 'bar' }, {}, 'arg1', 'arg2')78 })79 })80 context('no ipc event', () => {81 it('throws', function () {82 return this.handleEvent('no:such:event').catch((err) => {83 expect(err.message).to.include('No ipc event registered for: \'no:such:event\'')84 })85 })86 })87 context('dialog', () => {88 describe('show:directory:dialog', () => {89 it('calls dialog.show and returns', function () {90 sinon.stub(dialog, 'show').resolves({ foo: 'bar' })91 return this.handleEvent('show:directory:dialog').then((assert) => {92 return assert.sendCalledWith({ foo: 'bar' })93 })94 })95 it('catches errors', function () {96 const err = new Error('foo')97 sinon.stub(dialog, 'show').rejects(err)98 return this.handleEvent('show:directory:dialog').then((assert) => {99 return assert.sendErrCalledWith(err)100 })101 })102 })103 describe('show:new:spec:dialog', () => {104 it('calls files.showDialogAndCreateSpec and returns', function () {105 const response = {106 path: '/path/to/project/cypress/integration/my_new_spec.js',107 specs: {108 integration: [109 {110 name: 'app_spec.js',111 absolute: '/path/to/project/cypress/integration/app_spec.js',112 relative: 'cypress/integration/app_spec.js',113 },114 ],115 },116 }117 sinon.stub(files, 'showDialogAndCreateSpec').resolves(response)118 return this.handleEvent('show:new:spec:dialog').then((assert) => {119 return assert.sendCalledWith(response)120 })121 })122 it('catches errors', function () {123 const err = new Error('foo')124 sinon.stub(files, 'showDialogAndCreateSpec').rejects(err)125 return this.handleEvent('show:new:spec:dialog').then((assert) => {126 return assert.sendErrCalledWith(err)127 })128 })129 })130 })131 context('user', () => {132 describe('begin:auth', () => {133 it('calls auth.start and returns user', function () {134 sinon.stub(auth, 'start').resolves({ foo: 'bar' })135 return this.handleEvent('begin:auth').then((assert) => {136 return assert.sendCalledWith({ foo: 'bar' })137 })138 })139 it('catches errors', function () {140 const err = new Error('foo')141 sinon.stub(auth, 'start').rejects(err)142 return this.handleEvent('begin:auth').then((assert) => {143 return assert.sendErrCalledWith(err)144 })145 })146 })147 describe('log:out', () => {148 it('calls user.logOut and returns user', function () {149 sinon.stub(user, 'logOut').resolves({ foo: 'bar' })150 return this.handleEvent('log:out').then((assert) => {151 return assert.sendCalledWith({ foo: 'bar' })152 })153 })154 it('catches errors', function () {155 const err = new Error('foo')156 sinon.stub(user, 'logOut').rejects(err)157 return this.handleEvent('log:out').then((assert) => {158 return assert.sendErrCalledWith(err)159 })160 })161 })162 describe('get:current:user', () => {163 it('calls user.get and returns user', function () {164 sinon.stub(user, 'get').resolves({ foo: 'bar' })165 return this.handleEvent('get:current:user').then((assert) => {166 return assert.sendCalledWith({ foo: 'bar' })167 })168 })169 it('catches errors', function () {170 const err = new Error('foo')171 sinon.stub(user, 'get').rejects(err)172 return this.handleEvent('get:current:user').then((assert) => {173 return assert.sendErrCalledWith(err)174 })175 })176 })177 })178 context('external shell', () => {179 describe('external:open', () => {180 it('shell.openExternal with string arg', function () {181 electron.shell.openExternal = sinon.spy()182 return this.handleEvent('external:open', 'https://cypress.io/').then(() => {183 expect(electron.shell.openExternal).to.be.calledWith('https://cypress.io/')184 })185 })186 it('shell.openExternal with obj arg', function () {187 electron.shell.openExternal = sinon.spy()188 return this.handleEvent('external:open', { url: 'https://cypress.io/' }).then(() => {189 expect(electron.shell.openExternal).to.be.calledWith('https://cypress.io/')190 })191 })192 })193 })194 context('window', () => {195 describe('window:open', () => {196 beforeEach(function () {197 this.options.projectRoot = '/path/to/my/project'198 this.win = sinon.stub({199 on () {},200 once () {},201 loadURL () {},202 webContents: {},203 })204 })205 it('calls windowOpenFn with args and resolves with return', function () {206 this.options.windowOpenFn = sinon.stub().rejects().withArgs({ type: 'INDEX ' }).resolves(this.win)207 return this.handleEvent('window:open', { type: 'INDEX' })208 .then((assert) => {209 return assert.sendCalledWith(events.nullifyUnserializableValues(this.win))210 })211 })212 it('catches errors', function () {213 const err = new Error('foo')214 this.options.windowOpenFn = sinon.stub().withArgs(this.options.projectRoot, { foo: 'bar' }).rejects(err)215 return this.handleEvent('window:open', { foo: 'bar' }).then((assert) => {216 return assert.sendErrCalledWith(err)217 })218 })219 })220 describe('window:close', () => {221 it('calls destroy on Windows#getByWebContents', function () {222 const win = {223 destroy: sinon.stub(),224 }225 this.options.getWindowByWebContentsFn = sinon.stub().withArgs(this.event.sender).returns(win)226 this.handleEvent('window:close')227 expect(win.destroy).to.be.calledOnce228 })229 })230 })231 context('updating', () => {232 describe('updater:check', () => {233 it('returns version when new version', function () {234 sinon.stub(Updater, 'check').yieldsTo('onNewVersion', { version: '1.2.3' })235 return this.handleEvent('updater:check').then((assert) => {236 return assert.sendCalledWith('1.2.3')237 })238 })239 it('returns false when no new version', function () {240 sinon.stub(Updater, 'check').yieldsTo('onNoNewVersion')241 return this.handleEvent('updater:check').then((assert) => {242 return assert.sendCalledWith(false)243 })244 })245 })246 describe('get:release:notes', () => {247 it('returns release notes from api', function () {248 const releaseNotes = { title: 'New in 1.2.3!' }249 sinon.stub(api, 'getReleaseNotes').resolves(releaseNotes)250 return this.handleEvent('get:release:notes').then((assert) => {251 return assert.sendCalledWith(releaseNotes)252 })253 })254 it('sends null if there is an error', function () {255 sinon.stub(api, 'getReleaseNotes').rejects(new Error('failed to get release notes'))256 return this.handleEvent('get:release:notes').then((assert) => {257 return assert.sendCalledWith(null)258 })259 })260 })261 })262 context('log events', () => {263 describe('get:logs', () => {264 it('returns array of logs', function () {265 sinon.stub(logger, 'getLogs').resolves([])266 return this.handleEvent('get:logs').then((assert) => {267 return assert.sendCalledWith([])268 })269 })270 it('catches errors', function () {271 const err = new Error('foo')272 sinon.stub(logger, 'getLogs').rejects(err)273 return this.handleEvent('get:logs').then((assert) => {274 return assert.sendErrCalledWith(err)275 })276 })277 })278 describe('clear:logs', () => {279 it('returns null', function () {280 sinon.stub(logger, 'clearLogs').resolves()281 return this.handleEvent('clear:logs').then((assert) => {282 return assert.sendCalledWith(null)283 })284 })285 it('catches errors', function () {286 const err = new Error('foo')287 sinon.stub(logger, 'clearLogs').rejects(err)288 return this.handleEvent('clear:logs').then((assert) => {289 return assert.sendErrCalledWith(err)290 })291 })292 })293 describe('on:log', () => {294 it('sets send to onLog', function () {295 const onLog = sinon.stub(logger, 'onLog')296 this.handleEvent('on:log')297 expect(onLog).to.be.called298 expect(onLog.getCall(0).args[0]).to.be.a('function')299 })300 })301 describe('off:log', () => {302 it('calls logger#off and returns null', function () {303 sinon.stub(logger, 'off')304 return this.handleEvent('off:log').then((assert) => {305 expect(logger.off).to.be.calledOnce306 return assert.sendCalledWith(null)307 })308 })309 })310 })311 context('gui errors', () => {312 describe('gui:error', () => {313 it('calls logs.error with arg', function () {314 const err = new Error('foo')315 sinon.stub(logs, 'error').withArgs(err).resolves()316 return this.handleEvent('gui:error', err).then((assert) => {317 return assert.sendCalledWith(null)318 })319 })320 it('calls logger.createException with error', function () {321 const err = new Error('foo')322 sinon.stub(logger, 'createException').withArgs(err).resolves()323 return this.handleEvent('gui:error', err).then((assert) => {324 expect(logger.createException).to.be.calledOnce325 return assert.sendCalledWith(null)326 })327 })328 it('swallows logger.createException errors', function () {329 const err = new Error('foo')330 sinon.stub(logger, 'createException').withArgs(err).rejects(new Error('err'))331 return this.handleEvent('gui:error', err).then((assert) => {332 expect(logger.createException).to.be.calledOnce333 return assert.sendCalledWith(null)334 })335 })336 it('catches errors', function () {337 const err = new Error('foo')338 const err2 = new Error('bar')339 sinon.stub(logs, 'error').withArgs(err).rejects(err2)340 return this.handleEvent('gui:error', err).then((assert) => {341 return assert.sendErrCalledWith(err2)342 })343 })344 })345 })346 context('user events', () => {347 describe('get:orgs', () => {348 it('returns array of orgs', function () {349 sinon.stub(ProjectBase, 'getOrgs').resolves([])350 return this.handleEvent('get:orgs').then((assert) => {351 return assert.sendCalledWith([])352 })353 })354 it('catches errors', function () {355 const err = new Error('foo')356 sinon.stub(ProjectBase, 'getOrgs').rejects(err)357 return this.handleEvent('get:orgs').then((assert) => {358 return assert.sendErrCalledWith(err)359 })360 })361 })362 describe('open:finder', () => {363 it('opens with open lib', function () {364 sinon.stub(open, 'opn').resolves('okay')365 return this.handleEvent('open:finder', 'path').then((assert) => {366 expect(open.opn).to.be.calledWith('path')367 return assert.sendCalledWith('okay')368 })369 })370 it('catches errors', function () {371 const err = new Error('foo')372 sinon.stub(open, 'opn').rejects(err)373 return this.handleEvent('open:finder', 'path').then((assert) => {374 return assert.sendErrCalledWith(err)375 })376 })377 it('works even after project is opened (issue #227)', function () {378 sinon.stub(open, 'opn').resolves('okay')379 sinon.stub(ProjectE2E.prototype, 'open').resolves()380 sinon.stub(ProjectE2E.prototype, 'getConfig').resolves({ some: 'config' })381 return this.handleEvent('open:project', '/_test-output/path/to/project-e2e')382 .then(() => {383 return this.handleEvent('open:finder', 'path')384 }).then((assert) => {385 expect(open.opn).to.be.calledWith('path')386 return assert.sendCalledWith('okay')387 })388 })389 })390 })391 context('project events', () => {392 describe('get:projects', () => {393 it('returns array of projects', function () {394 sinon.stub(ProjectBase, 'getPathsAndIds').resolves([])395 return this.handleEvent('get:projects').then((assert) => {396 return assert.sendCalledWith([])397 })398 })399 it('catches errors', function () {400 const err = new Error('foo')401 sinon.stub(ProjectBase, 'getPathsAndIds').rejects(err)402 return this.handleEvent('get:projects').then((assert) => {403 return assert.sendErrCalledWith(err)404 })405 })406 })407 describe('get:project:statuses', () => {408 it('returns array of projects with statuses', function () {409 sinon.stub(ProjectBase, 'getProjectStatuses').resolves([])410 return this.handleEvent('get:project:statuses').then((assert) => {411 return assert.sendCalledWith([])412 })413 })414 it('catches errors', function () {415 const err = new Error('foo')416 sinon.stub(ProjectBase, 'getProjectStatuses').rejects(err)417 return this.handleEvent('get:project:statuses').then((assert) => {418 return assert.sendErrCalledWith(err)419 })420 })421 })422 describe('get:project:status', () => {423 it('returns project returned by Project.getProjectStatus', function () {424 sinon.stub(ProjectBase, 'getProjectStatus').resolves('project')425 return this.handleEvent('get:project:status').then((assert) => {426 return assert.sendCalledWith('project')427 })428 })429 it('catches errors', function () {430 const err = new Error('foo')431 sinon.stub(ProjectBase, 'getProjectStatus').rejects(err)432 return this.handleEvent('get:project:status').then((assert) => {433 return assert.sendErrCalledWith(err)434 })435 })436 })437 describe('add:project', () => {438 it('adds project + returns result', function () {439 sinon.stub(ProjectBase, 'add').withArgs('/_test-output/path/to/project', this.options).resolves('result')440 return this.handleEvent('add:project', '/_test-output/path/to/project').then((assert) => {441 return assert.sendCalledWith('result')442 })443 })444 it('catches errors', function () {445 const err = new Error('foo')446 sinon.stub(ProjectBase, 'add').withArgs('/_test-output/path/to/project', this.options).rejects(err)447 return this.handleEvent('add:project', '/_test-output/path/to/project').then((assert) => {448 return assert.sendErrCalledWith(err)449 })450 })451 })452 describe('remove:project', () => {453 it('remove project + returns arg', function () {454 sinon.stub(cache, 'removeProject').withArgs('/_test-output/path/to/project-e2e').resolves()455 return this.handleEvent('remove:project', '/_test-output/path/to/project-e2e').then((assert) => {456 return assert.sendCalledWith('/_test-output/path/to/project-e2e')457 })458 })459 it('catches errors', function () {460 const err = new Error('foo')461 sinon.stub(cache, 'removeProject').withArgs('/_test-output/path/to/project-e2e').rejects(err)462 return this.handleEvent('remove:project', '/_test-output/path/to/project-e2e').then((assert) => {463 return assert.sendErrCalledWith(err)464 })465 })466 })467 describe('open:project', () => {468 beforeEach(function () {469 sinon.stub(extension, 'setHostAndPath').resolves()470 sinon.stub(browsers, 'getAllBrowsersWith')471 browsers.getAllBrowsersWith.resolves([])472 browsers.getAllBrowsersWith.withArgs('/usr/bin/baz-browser').resolves([{ foo: 'bar' }])473 this.open = sinon.stub(ProjectE2E.prototype, 'open').resolves()474 sinon.stub(ProjectE2E.prototype, 'close').resolves()475 return sinon.stub(ProjectE2E.prototype, 'getConfig').resolves({ some: 'config' })476 })477 afterEach(() => {478 return openProject.close()479 })480 it('open project + returns config', function () {481 return this.handleEvent('open:project', '/_test-output/path/to/project-e2e')482 .then((assert) => {483 return assert.sendCalledWith({ some: 'config' })484 })485 })486 it('catches errors', function () {487 const err = new Error('foo')488 this.open.rejects(err)489 return this.handleEvent('open:project', '/_test-output/path/to/project-e2e')490 .then((assert) => {491 return assert.sendErrCalledWith(err)492 })493 })494 it('sends \'focus:tests\' onFocusTests', function () {495 return this.handleEvent('open:project', '/_test-output/path/to/project-e2e')496 .then(() => {497 return this.handleEvent('on:focus:tests')498 }).then((assert) => {499 this.open.lastCall.args[0].onFocusTests()500 return assert.sendCalledWith(undefined)501 })502 })503 it('sends \'config:changed\' onSettingsChanged', function () {504 return this.handleEvent('open:project', '/_test-output/path/to/project-e2e')505 .then(() => {506 return this.handleEvent('on:config:changed')507 }).then((assert) => {508 this.open.lastCall.args[0].onSettingsChanged()509 return assert.sendCalledWith(undefined)510 })511 })512 it('sends \'spec:changed\' onSpecChanged', function () {513 return this.handleEvent('open:project', '/_test-output/path/to/project-e2e')514 .then(() => {515 return this.handleEvent('on:spec:changed')516 }).then((assert) => {517 this.open.lastCall.args[0].onSpecChanged('/path/to/spec.coffee')518 return assert.sendCalledWith('/path/to/spec.coffee')519 })520 })521 it('sends \'project:warning\' onWarning', function () {522 return this.handleEvent('open:project', '/_test-output/path/to/project-e2e')523 .then(() => {524 return this.handleEvent('on:project:warning')525 }).then((assert) => {526 this.open.lastCall.args[0].onWarning({ name: 'foo', message: 'foo' })527 return assert.sendCalledWith({ name: 'foo', message: 'foo' })528 })529 })530 it('sends \'project:error\' onError', function () {531 return this.handleEvent('open:project', '/_test-output/path/to/project-e2e')532 .then(() => {533 return this.handleEvent('on:project:error')534 }).then((assert) => {535 this.open.lastCall.args[0].onError({ name: 'foo', message: 'foo' })536 return assert.sendCalledWith({ name: 'foo', message: 'foo' })537 })538 })539 it('calls browsers.getAllBrowsersWith with no args when no browser specified', function () {540 return this.handleEvent('open:project', '/_test-output/path/to/project-e2e').then(() => {541 expect(browsers.getAllBrowsersWith).to.be.calledWith()542 })543 })544 it('calls browsers.getAllBrowsersWith with browser when browser specified', function () {545 sinon.stub(openProject, 'create').resolves()546 this.options.browser = '/usr/bin/baz-browser'547 return this.handleEvent('open:project', '/_test-output/path/to/project-e2e').then(() => {548 expect(browsers.getAllBrowsersWith).to.be.calledWith(this.options.browser)549 expect(openProject.create).to.be.calledWithMatch(550 '/_test-output/path/to/project',551 {552 browser: '/usr/bin/baz-browser',553 config: {554 browsers: [555 {556 foo: 'bar',557 },558 ],559 },560 },561 )562 })563 })564 it('attaches warning to Chrome browsers when Chrome policy check fails', function () {565 sinon.stub(openProject, 'create').resolves()566 this.options.browser = '/foo'567 browsers.getAllBrowsersWith.withArgs('/foo').resolves([{ family: 'chromium' }, { family: 'some other' }])568 sinon.stub(chromePolicyCheck, 'run').callsArgWith(0, new Error)569 return this.handleEvent('open:project', '/_test-output/path/to/project-e2e').then(() => {570 expect(browsers.getAllBrowsersWith).to.be.calledWith(this.options.browser)571 expect(openProject.create).to.be.calledWithMatch(572 '/_test-output/path/to/project',573 {574 browser: '/foo',575 config: {576 browsers: [577 {578 family: 'chromium',579 warning: 'Cypress detected policy settings on your computer that may cause issues with using this browser. For more information, see https://on.cypress.io/bad-browser-policy',580 },581 {582 family: 'some other',583 },584 ],585 },586 },587 )588 })589 })590 })591 describe('close:project', () => {592 beforeEach(() => {593 return sinon.stub(ProjectE2E.prototype, 'close').withArgs({ sync: true }).resolves()594 })595 it('is noop and returns null when no project is open', function () {596 expect(openProject.getProject()).to.be.null597 return this.handleEvent('close:project').then((assert) => {598 return assert.sendCalledWith(null)599 })600 })601 it('closes down open project and returns null', function () {602 sinon.stub(ProjectE2E.prototype, 'getConfig').resolves({})603 sinon.stub(ProjectE2E.prototype, 'open').resolves()604 return this.handleEvent('open:project', '/_test-output/path/to/project-e2e')605 .then(() => {606 // it should store the opened project607 expect(openProject.getProject()).not.to.be.null608 return this.handleEvent('close:project')609 }).then((assert) => {610 // it should store the opened project611 expect(openProject.getProject()).to.be.null612 return assert.sendCalledWith(null)613 })614 })615 })616 describe('get:runs', () => {617 it('calls openProject.getRuns', function () {618 sinon.stub(openProject, 'getRuns').resolves([])619 return this.handleEvent('get:runs').then((assert) => {620 expect(openProject.getRuns).to.be.called621 })622 })623 it('returns array of runs', function () {624 sinon.stub(openProject, 'getRuns').resolves([])625 return this.handleEvent('get:runs').then((assert) => {626 return assert.sendCalledWith([])627 })628 })629 it('sends UNAUTHENTICATED when statusCode is 401', function () {630 const err = new Error('foo')631 err.statusCode = 401632 sinon.stub(openProject, 'getRuns').rejects(err)633 return this.handleEvent('get:runs').then((assert) => {634 expect(this.send).to.be.calledWith('response')635 expect(this.send.firstCall.args[1].__error.type).to.equal('UNAUTHENTICATED')636 })637 })638 it('sends TIMED_OUT when cause.code is ESOCKETTIMEDOUT', function () {639 const err = new Error('foo')640 err.cause = { code: 'ESOCKETTIMEDOUT' }641 sinon.stub(openProject, 'getRuns').rejects(err)642 return this.handleEvent('get:runs').then((assert) => {643 expect(this.send).to.be.calledWith('response')644 expect(this.send.firstCall.args[1].__error.type).to.equal('TIMED_OUT')645 })646 })647 it('sends NO_CONNECTION when code is ENOTFOUND', function () {648 const err = new Error('foo')649 err.code = 'ENOTFOUND'650 sinon.stub(openProject, 'getRuns').rejects(err)651 return this.handleEvent('get:runs').then((assert) => {652 expect(this.send).to.be.calledWith('response')653 expect(this.send.firstCall.args[1].__error.type).to.equal('NO_CONNECTION')654 })655 })656 it('sends type when if existing for other errors', function () {657 const err = new Error('foo')658 err.type = 'NO_PROJECT_ID'659 sinon.stub(openProject, 'getRuns').rejects(err)660 return this.handleEvent('get:runs').then((assert) => {661 expect(this.send).to.be.calledWith('response')662 expect(this.send.firstCall.args[1].__error.type).to.equal('NO_PROJECT_ID')663 })664 })665 it('sends UNKNOWN + name,message,stack for other errors', function () {666 const err = new Error('foo')667 err.name = 'name'668 err.message = 'message'669 err.stack = 'stack'670 sinon.stub(openProject, 'getRuns').rejects(err)671 return this.handleEvent('get:runs').then((assert) => {672 expect(this.send).to.be.calledWith('response')673 expect(this.send.firstCall.args[1].__error.type).to.equal('UNKNOWN')674 })675 })676 })677 describe('setup:dashboard:project', () => {678 it('returns result of openProject.createCiProject', function () {679 sinon.stub(openProject, 'createCiProject').resolves('response')680 return this.handleEvent('setup:dashboard:project').then((assert) => {681 return assert.sendCalledWith('response')682 })683 })684 it('catches errors', function () {685 const err = new Error('foo')686 sinon.stub(openProject, 'createCiProject').rejects(err)687 return this.handleEvent('setup:dashboard:project').then((assert) => {688 return assert.sendErrCalledWith(err)689 })690 })691 })692 describe('get:record:keys', () => {693 it('returns result of project.getRecordKeys', function () {694 sinon.stub(openProject, 'getRecordKeys').resolves(['ci-key-123'])695 return this.handleEvent('get:record:keys').then((assert) => {696 return assert.sendCalledWith(['ci-key-123'])697 })698 })699 it('catches errors', function () {700 const err = new Error('foo')701 sinon.stub(openProject, 'getRecordKeys').rejects(err)702 return this.handleEvent('get:record:keys').then((assert) => {703 return assert.sendErrCalledWith(err)704 })705 })706 })707 describe('request:access', () => {708 it('returns result of project.requestAccess', function () {709 sinon.stub(openProject, 'requestAccess').resolves('response')710 return this.handleEvent('request:access', 'org-id-123').then((assert) => {711 expect(openProject.requestAccess).to.be.calledWith('org-id-123')712 return assert.sendCalledWith('response')713 })714 })715 it('catches errors', function () {716 const err = new Error('foo')717 sinon.stub(openProject, 'requestAccess').rejects(err)718 return this.handleEvent('request:access', 'org-id-123').then((assert) => {719 return assert.sendErrCalledWith(err)720 })721 })722 it('sends ALREADY_MEMBER when statusCode is 403', function () {723 const err = new Error('foo')724 err.statusCode = 403725 sinon.stub(openProject, 'requestAccess').rejects(err)726 return this.handleEvent('request:access', 'org-id-123').then((assert) => {727 expect(this.send).to.be.calledWith('response')728 expect(this.send.firstCall.args[1].__error.type).to.equal('ALREADY_MEMBER')729 })730 })731 it('sends ALREADY_REQUESTED when statusCode is 429 with certain error', function () {732 const err = new Error('foo')733 err.statusCode = 422734 err.errors = {735 userId: ['This User has an existing MembershipRequest to this Organization.'],736 }737 sinon.stub(openProject, 'requestAccess').rejects(err)738 return this.handleEvent('request:access', 'org-id-123').then((assert) => {739 expect(this.send).to.be.calledWith('response')740 expect(this.send.firstCall.args[1].__error.type).to.equal('ALREADY_REQUESTED')741 })742 })743 it('sends type when if existing for other errors', function () {744 const err = new Error('foo')745 err.type = 'SOME_TYPE'746 sinon.stub(openProject, 'requestAccess').rejects(err)747 return this.handleEvent('request:access', 'org-id-123').then((assert) => {748 expect(this.send).to.be.calledWith('response')749 expect(this.send.firstCall.args[1].__error.type).to.equal('SOME_TYPE')750 })751 })752 it('sends UNKNOWN for other errors', function () {753 const err = new Error('foo')754 sinon.stub(openProject, 'requestAccess').rejects(err)755 return this.handleEvent('request:access', 'org-id-123').then((assert) => {756 expect(this.send).to.be.calledWith('response')757 expect(this.send.firstCall.args[1].__error.type).to.equal('UNKNOWN')758 })759 })760 })761 describe('ping:api:server', () => {762 it('returns ensures url', function () {763 sinon.stub(ensureUrl, 'isListening').resolves()764 return this.handleEvent('ping:api:server').then((assert) => {765 expect(ensureUrl.isListening).to.be.calledWith(konfig('api_url'))766 return assert.sendCalledWith()767 })768 })769 it('catches errors', function () {770 const err = new Error('foo')771 sinon.stub(ensureUrl, 'isListening').rejects(err)772 return this.handleEvent('ping:api:server').then((assert) => {773 assert.sendErrCalledWith(err)774 expect(err.apiUrl).to.equal(konfig('api_url'))775 })776 })777 it('sends first of aggregate error', function () {778 const err = new Error('AggregateError')779 err.message = 'aggregate error'780 err[0] = {781 code: 'ECONNREFUSED',782 port: 1234,783 address: '127.0.0.1',784 }785 err.length = 1786 sinon.stub(ensureUrl, 'isListening').rejects(err)787 return this.handleEvent('ping:api:server').then((assert) => {788 assert.sendErrCalledWith(err)789 expect(err.name).to.equal('ECONNREFUSED 127.0.0.1:1234')790 expect(err.message).to.equal('ECONNREFUSED 127.0.0.1:1234')791 expect(err.apiUrl).to.equal(konfig('api_url'))792 })793 })794 })795 describe('launch:browser', () => {796 it('launches browser via openProject', function () {797 sinon.stub(openProject, 'launch').callsFake((browser, spec, opts) => {798 debug('spec was %o', spec)799 expect(browser, 'browser').to.eq('foo')800 expect(spec, 'spec').to.deep.equal({801 name: 'bar',802 absolute: '/path/to/bar',803 relative: 'to/bar',804 specType: 'integration',805 specFilter: undefined,806 })807 opts.onBrowserOpen()808 opts.onBrowserClose()809 return Promise.resolve()810 })811 const spec = {812 name: 'bar',813 absolute: '/path/to/bar',814 relative: 'to/bar',815 }816 const arg = {817 browser: 'foo',818 spec,819 specType: 'integration',820 }821 return this.handleEvent('launch:browser', arg).then(() => {822 expect(this.send.getCall(0).args[1].data).to.include({ browserOpened: true })823 expect(this.send.getCall(1).args[1].data).to.include({ browserClosed: true })824 })825 })826 it('passes specFilter', function () {827 sinon.stub(openProject, 'launch').callsFake((browser, spec, opts) => {828 debug('spec was %o', spec)829 expect(browser, 'browser').to.eq('foo')830 expect(spec, 'spec').to.deep.equal({831 name: 'bar',832 absolute: '/path/to/bar',833 relative: 'to/bar',834 specType: 'integration',835 specFilter: 'network',836 })837 opts.onBrowserOpen()838 opts.onBrowserClose()839 return Promise.resolve()840 })841 const spec = {842 name: 'bar',843 absolute: '/path/to/bar',844 relative: 'to/bar',845 }846 const arg = {847 browser: 'foo',848 spec,849 specType: 'integration',850 specFilter: 'network',851 }852 return this.handleEvent('launch:browser', arg).then(() => {853 expect(this.send.getCall(0).args[1].data).to.include({ browserOpened: true })854 expect(this.send.getCall(1).args[1].data).to.include({ browserClosed: true })855 })856 })857 it('wraps error titles if not set', function () {858 const err = new Error('foo')859 sinon.stub(openProject, 'launch').rejects(err)860 return this.handleEvent('launch:browser', {}).then(() => {861 expect(this.send.getCall(0).args[1].__error).to.include({ message: 'foo', title: 'Error launching browser' })862 })863 })864 })865 })...

Full Screen

Full Screen

project_static.js

Source:project_static.js Github

copy

Full Screen

...24function paths() {25 return cache_1.default.getProjectRoots();26}27exports.paths = paths;28function getPathsAndIds() {29 return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {30 const projectRoots = yield cache_1.default.getProjectRoots();31 // this assumes that the configFile for a cached project is 'cypress.json'32 // https://git.io/JeGyF33 return Promise.all(projectRoots.map((projectRoot) => (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {34 return {35 path: projectRoot,36 id: yield settings.id(projectRoot),37 };38 })));39 });40}41exports.getPathsAndIds = getPathsAndIds;42function getDashboardProjects() {...

Full Screen

Full Screen

events.js

Source:events.js Github

copy

Full Screen

...131 return send(null);132 case "get:orgs":133 return Project.getOrgs().then(send)["catch"](sendErr);134 case "get:projects":135 return Project.getPathsAndIds().then(send)["catch"](sendErr);136 case "get:project:statuses":137 return Project.getProjectStatuses(arg).then(send)["catch"](sendErr);138 case "get:project:status":139 return Project.getProjectStatus(arg).then(send)["catch"](sendErr);140 case "add:project":141 return Project.add(arg).then(send)["catch"](sendErr);142 case "remove:project":143 return Project.remove(arg).then(function() {144 return send(arg);145 })["catch"](sendErr);146 case "open:project":147 onSettingsChanged = function() {148 return bus.emit("config:changed");149 };...

Full Screen

Full Screen

tag.js

Source:tag.js Github

copy

Full Screen

...6function getTimestamp(fbid) {7 return dates[fbid];8}9const base = './output';10function getPathsAndIds() {11 const files = fs.readdirSync(base);12 const spec = files.map((f) => {13 const file = path.join(base, f);14 const fbid = path.basename(f, path.extname(f));15 return { file, fbid };16 });17 return spec;18}19// set functions20function setExifTimes(file, date) {21 // DateTimeOriginal -> YYYY:MM:DD HH:MM:SS22 const stamp = date.toISOString().replace(/-/g, ':').replace(/T/g, ' ').replace(/.\d\d\dZ$/, '');23 proc.execSync(`exiftool "-alldates=${stamp}" -overwrite_original ${file}`);24}25function setAttributeTimes(file, date) {26 // [[CC]YY]MMDDhhmm[.ss]27 const stamp = date.toISOString() // '2015-11-30T12:00:00.000Z'28 .replace(/[-T:]/g, '').replace(/(\d\d).\d\d\dZ$/, '.$1');29 proc.execSync(`touch -amt ${stamp} ${file}`);30}31function setTimes(file, ts) {32 const date = new Date(ts);33 setExifTimes(file, date);34 setAttributeTimes(file, date);35}36module.exports = { setTimes };37// main38function main() {39 /* eslint-disable no-console */40 const todo = getPathsAndIds();41 console.log(`~ ${todo.length} files to set ~`);42 todo.forEach(({ file, fbid }, i) => {43 const ts = getTimestamp(fbid);44 if (!ts) throw new Error(`No timestamp found for fbid ${fbid}`);45 console.log(`[${fbid}] (${i + 1}/${todo.length}) -> ${new Date(ts)}`);46 setTimes(file, ts);47 });48 /* eslint-enable no-console */49}...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('My First Test', () => {2 it('Does not do much!', () => {3 expect(true).to.equal(true)4 })5 it('getPathsAndIds', () => {6 cy.getPathsAndIds()7 })8})9Cypress.Commands.add('getPathsAndIds', () => {10 cy.document().then((doc) => {11 console.log('All paths and ids:')12 console.log(13 [...doc.querySelectorAll('*')].map((el) => {14 return {15 path: getPath(el),16 }17 })18 })19})20import './commands'21{22}23I have a problem with the cypress-plugin-snapshots plugin. It works fine in my local environment but when I run my tests in my CI (GitLab CI) it fails. I have a Cypress test that checks if a button is disabled or not. I have 2 snapshots, one with the button enabled and one with the button disabled. The test runs fine locally but fails in the CI. I have tried to set the viewportWidth and viewportHeight in the cypress.json file but it didn't help. Here is the error message I get:24describe('Login', () => {25 it('should login', () => {26 cy.get('[data-cy=email]').type('

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('test', () => {2 it('test', () => {3 cy.getPathsAndIds().then((pathsAndIds) => {4 console.log(pathsAndIds);5 });6 });7});8Cypress.Commands.add('getPathsAndIds', () => {9 return cy.window().then((win) => {10 const pathsAndIds = [];11 const paths = getAllPaths(win.document.body);12 paths.forEach((path) => {13 const id = win.document.querySelector(path).getAttribute('id');14 pathsAndIds.push({ path, id });15 });16 return pathsAndIds;17 });18});19function getAllPaths(node) {20 const paths = [];21 if (node.getAttribute('id')) {22 paths.push(`#${node.getAttribute('id')}`);23 }24 if (node.getAttribute('class')) {25 const classes = node.getAttribute('class').split(' ');26 classes.forEach((className) => {27 paths.push(`.${className}`);28 });29 }30 if (node.children.length) {31 for (let i = 0; i < node.children.length; i++) {32 const childPaths = getAllPaths(node.children[i]);33 childPaths.forEach((childPath) => {34 paths.push(`${childPath}`);35 });36 }37 }38 return paths;39}40describe('test', () => {41 it('test', () => {42 cy.getPathsAndIds().then((pathsAndIds) => {43 pathsAndIds.forEach((pathAndId) => {44 if (pathAndId.id) {45 cy.get(pathAndId.path).should('have.id', pathAndId.id);46 }47 });48 });49 });50});51cy.get('.MuiTable-root').find('tr').contains('Test').parent().parent().parent().p

Full Screen

Using AI Code Generation

copy

Full Screen

1const { getPathsAndIds } = require('cypress-fail-fast/plugin');2module.exports = (on, config) => {3 on('task', {4 getPathsAndIds: getPathsAndIds(config),5 });6};7const { getPathsAndIds } = require('cypress-fail-fast/plugin');8module.exports = (on, config) => {9 on('task', {10 getPathsAndIds: getPathsAndIds(config),11 });12};13const { getPathsAndIds } = require('cypress-fail-fast/plugin');14module.exports = (on, config) => {15 on('task', {16 getPathsAndIds: getPathsAndIds(config),17 });18};19const { getPathsAndIds } = require('cypress-fail-fast/plugin');20module.exports = (on, config) => {21 on('task', {22 getPathsAndIds: getPathsAndIds(config),23 });24};25const { getPathsAndIds } = require('cypress-fail-fast/plugin');26module.exports = (on, config) => {27 on('task', {28 getPathsAndIds: getPathsAndIds(config),29 });30};31const { getPathsAndIds } = require('cypress-fail-fast/plugin');32module.exports = (on, config) => {33 on('task', {34 getPathsAndIds: getPathsAndIds(config),35 });36};37const { getPaths

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('getPathsAndIds', () => {2 it('should return an array of paths and ids', () => {3 cy.getPathsAndIds().then(pathsAndIds => {4 expect(pathsAndIds).to.deep.equal([5 { path: 'path/to/file', id: 'id' },6 { path: 'path/to/file', id: 'id' }7 })8 })9})10Cypress.Commands.add('getPathsAndIds', () => {11 .get('a')12 .then($a => {13 return $a.map((i, a) => {14 return {15 }16 })17 })18 .get()19})20describe('getPathsAndIds', () => {21 it('should return an array of paths and ids', () => {22 cy.getPathsAndIds().then(pathsAndIds => {23 expect(pathsAndIds).to.deep.equal([24 { path: 'path/to/file', id: 'id' },25 { path: 'path/to/file', id: 'id' }26 })27 })28})29Cypress.Commands.add('getPathsAndIds', () => {30 .get('a')31 .then($a => {32 return $a.map((i, a) => {33 return {34 }35 })36 })37 .get()38})39describe('getPathsAndIds', () => {40 it('should return an array of paths and ids', () => {41 cy.getPathsAndIds().then(pathsAndIds => {42 expect(pathsAndIds).to.deep.equal([43 { path: 'path/to/file', id: 'id' },44 { path: 'path/to/file', id: 'id' }45 })46 })47})48Cypress.Commands.add('getPathsAndIds', () => {49 .get('a')50 .then($a => {51 return $a.map((i, a) => {52 return {

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('My First Test', function() {2 it('Does not do much!', function() {3 cy.get('nav').getPathsAndIds()4 })5})6Cypress.Commands.add('getPathsAndIds', { prevSubject: 'element' }, ($el) => {7 const $paths = $el.find('a')8 $paths.each((i, el) => {9 paths.push(el.getAttribute('href'))10 ids.push(el.getAttribute('id'))11 })12 console.log('paths: ', paths)13 console.log('ids: ', ids)14})15{16}17describe('My First Test', function() {18 it('Does not do much!', function() {19 cy.get('nav').getPathsAndIds()20 })21})22Cypress.Commands.add('getPathsAndIds', { prevSubject: 'element' }, ($el) => {23 const $paths = $el.find('a')24 $paths.each((i, el) => {25 paths.push(el.getAttribute('href'))26 ids.push(el.getAttribute('id'))27 })28 console.log('paths: ', paths)29 console.log('ids: ', ids)30})31{32}33describe('My First Test', function() {34 it('Does not do much!', function() {35 cy.get('nav').getPathsAndIds()36 })37})38Cypress.Commands.add('getPathsAndIds', { prevSubject: 'element' }, ($el) => {39 const $paths = $el.find('a')40 $paths.each((i, el) => {

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('Test', () => {2 it('test', () => {3 cy.getPathsAndIds();4 });5});6Cypress.Commands.add('getPathsAndIds', () => {7 cy.document().then((doc) => {8 const pathsAndIds = [];9 const elements = doc.getElementsByTagName('*');10 for (let i = 0; i < elements.length; i++) {11 if (elements[i].id) {12 pathsAndIds.push({13 path: Cypress.dom.getElementPath(elements[i]),14 });15 }16 }17 cy.log(pathsAndIds);18 });19});20import './commands';21{22 "testFiles": "**/*.{feature,features}",23 "env": {24 },25 "reporterOptions": {26 },27}28{29 "scripts": {30 },31 "dependencies": {32 },33 "devDependencies": {

Full Screen

Using AI Code Generation

copy

Full Screen

1cy.get('div').then(($div) => {2 const path = Cypress.dom.getElementPath($div.get(0));3 const id = Cypress.dom.getElementId($div.get(0));4 console.log('Path: ' + path);5 console.log('Id: ' + id);6});

Full Screen

Using AI Code Generation

copy

Full Screen

1describe("Get all the paths and ids", () => {2 it("Get all the paths and ids", () => {3 cy.getPathsAndIds().then((pathsAndIds) => {4 cy.writeFile("cypress/fixtures/pathsAndIds.json", pathsAndIds);5 });6 });7});8Cypress.Commands.add("getPathsAndIds", () => {9 return cy.window().then((win) => {10 const pathsAndIds = getPathsAndIds(win.document.body);11 return pathsAndIds;12 });13});14import "./commands";15describe("Get all the paths and ids", () => {16 it("Get all the paths and ids", () => {17 cy.getPathsAndIds().then((pathsAndIds) => {18 cy.writeFile("cypress/fixtures/pathsAndIds.json", pathsAndIds);19 });20 });21});22Cypress.Commands.add("getPathsAndIds", () => {23 return cy.window().then((win) => {24 const pathsAndIds = getPathsAndIds(win.document.body);25 return pathsAndIds;26 });27});28import "./commands";29describe("Get all the paths and ids", () => {30 it("Get all the paths and ids", () => {31 cy.getPathsAndIds().then((pathsAndIds) => {32 cy.writeFile("cypress/fixtures/pathsAndIds.json", pathsAndIds);33 });34 });35});

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