Best JavaScript code snippet using cypress
config-test.js
Source:config-test.js
...14 gatherMode = 'snapshot';15 });16 it('should throw if the config path is not absolute', () => {17 const configFn = () =>18 initializeConfig(undefined, {gatherMode, configPath: '../relative/path'});19 expect(configFn).toThrow(/must be an absolute path/);20 });21 it('should not mutate the original input', () => {22 const configJson = {artifacts: [{id: 'Accessibility', gatherer: 'accessibility'}]};23 const {config} = initializeConfig(configJson, {gatherMode});24 expect(configJson).toEqual({artifacts: [{id: 'Accessibility', gatherer: 'accessibility'}]});25 expect(config).not.toBe(configJson);26 expect(config).not.toEqual(configJson);27 expect(config.artifacts).toMatchObject([{gatherer: {path: 'accessibility'}}]);28 });29 it('should use default config when none passed in', () => {30 const {config} = initializeConfig(undefined, {gatherMode});31 expect(config.settings).toMatchObject({formFactor: 'mobile'});32 if (!config.audits) throw new Error('Did not define audits');33 expect(config.audits.length).toBeGreaterThan(0);34 });35 it('should resolve settings with defaults', () => {36 const {config} = initializeConfig(37 {settings: {output: 'csv', maxWaitForFcp: 1234}},38 {settingsOverrides: {maxWaitForFcp: 12345}, gatherMode}39 );40 expect(config.settings).toMatchObject({41 formFactor: 'mobile', // inherit from default42 output: 'csv', // config-specific overrides43 maxWaitForFcp: 12345, // explicit overrides44 });45 });46 it('should resolve artifact definitions', () => {47 const configJson = {artifacts: [{id: 'Accessibility', gatherer: 'accessibility'}]};48 const {config} = initializeConfig(configJson, {gatherMode});49 expect(config).toMatchObject({50 artifacts: [{id: 'Accessibility', gatherer: {path: 'accessibility'}}],51 });52 });53 it('should throw on invalid artifact definitions', () => {54 const configJson = {artifacts: [{id: 'ImageElements', gatherer: 'image-elements'}]};55 expect(() => initializeConfig(configJson, {gatherMode})).toThrow(/ImageElements gatherer/);56 });57 it('should resolve navigation definitions', () => {58 gatherMode = 'navigation';59 const configJson = {60 artifacts: [{id: 'Accessibility', gatherer: 'accessibility'}],61 navigations: [{id: 'default', artifacts: ['Accessibility']}],62 };63 const {config} = initializeConfig(configJson, {gatherMode});64 expect(config).toMatchObject({65 artifacts: [{id: 'Accessibility', gatherer: {path: 'accessibility'}}],66 navigations: [67 {id: 'default', artifacts: [{id: 'Accessibility', gatherer: {path: 'accessibility'}}]},68 ],69 });70 });71 it('should throw when navigations are defined without artifacts', () => {72 const configJson = {73 navigations: [{id: 'default', artifacts: ['Accessibility']}],74 };75 expect(() => initializeConfig(configJson, {gatherMode})).toThrow(/Cannot use navigations/);76 });77 it('should throw when navigations use unrecognized artifacts', () => {78 const configJson = {79 artifacts: [],80 navigations: [{id: 'default', artifacts: ['Accessibility']}],81 };82 expect(() => initializeConfig(configJson, {gatherMode})).toThrow(/Unrecognized artifact/);83 });84 it('should set default properties on navigations', () => {85 gatherMode = 'navigation';86 const configJson = {87 artifacts: [],88 navigations: [{id: 'default'}],89 };90 const {config} = initializeConfig(configJson, {gatherMode});91 expect(config).toMatchObject({92 navigations: [93 {94 id: 'default',95 blankPage: 'about:blank',96 artifacts: [],97 disableThrottling: false,98 networkQuietThresholdMs: 0,99 cpuQuietThresholdMs: 0,100 },101 ],102 });103 });104 it('should filter configuration by gatherMode', () => {105 const timespanGatherer = new BaseGatherer();106 timespanGatherer.meta = {supportedModes: ['timespan']};107 const configJson = {108 artifacts: [109 {id: 'Accessibility', gatherer: 'accessibility'},110 {id: 'Timespan', gatherer: {instance: timespanGatherer}},111 ],112 };113 const {config} = initializeConfig(configJson, {gatherMode: 'snapshot'});114 expect(config).toMatchObject({115 artifacts: [{id: 'Accessibility', gatherer: {path: 'accessibility'}}],116 });117 });118 describe('resolveArtifactDependencies', () => {119 /** @type {LH.Gatherer.FRGathererInstance} */120 let dependencyGatherer;121 /** @type {LH.Gatherer.FRGathererInstance<'ImageElements'>} */122 let dependentGatherer;123 /** @type {LH.Config.Json} */124 let configJson;125 beforeEach(() => {126 const dependencySymbol = Symbol('dependency');127 dependencyGatherer = new BaseGatherer();128 dependencyGatherer.meta = {symbol: dependencySymbol, supportedModes: ['snapshot']};129 // @ts-expect-error - we satisfy the interface on the next line130 dependentGatherer = new BaseGatherer();131 dependentGatherer.meta = {132 supportedModes: ['snapshot'],133 dependencies: {ImageElements: dependencySymbol},134 };135 configJson = {136 artifacts: [137 {id: 'Dependency', gatherer: {instance: dependencyGatherer}},138 {id: 'Dependent', gatherer: {instance: dependentGatherer}},139 ],140 navigations: [141 {id: 'default', artifacts: ['Dependency']},142 {id: 'second', artifacts: ['Dependent']},143 ],144 };145 });146 it('should resolve artifact dependencies', () => {147 const {config} = initializeConfig(configJson, {gatherMode: 'snapshot'});148 expect(config).toMatchObject({149 artifacts: [150 {id: 'Dependency', gatherer: {instance: dependencyGatherer}},151 {152 id: 'Dependent',153 gatherer: {154 instance: dependentGatherer,155 },156 dependencies: {157 ImageElements: {id: 'Dependency'},158 },159 },160 ],161 });162 });163 it('should resolve artifact dependencies in navigations', () => {164 const {config} = initializeConfig(configJson, {gatherMode: 'snapshot'});165 expect(config).toMatchObject({166 navigations: [167 {artifacts: [{id: 'Dependency'}]},168 {169 artifacts: [170 {171 id: 'Dependent',172 dependencies: {173 ImageElements: {id: 'Dependency'},174 },175 },176 ],177 },178 ],179 });180 });181 it('should throw when dependencies are out of order in artifacts', () => {182 if (!configJson.artifacts) throw new Error('Failed to run beforeEach');183 configJson.artifacts = [configJson.artifacts[1], configJson.artifacts[0]];184 expect(() => initializeConfig(configJson, {gatherMode: 'snapshot'}))185 .toThrow(/Failed to find dependency/);186 });187 it('should throw when dependencies are out of order within a navigation', () => {188 if (!configJson.navigations) throw new Error('Failed to run beforeEach');189 const invalidNavigation = {id: 'default', artifacts: ['Dependent', 'Dependency']};190 configJson.navigations = [invalidNavigation];191 expect(() => initializeConfig(configJson, {gatherMode: 'snapshot'}))192 .toThrow(/Failed to find dependency/);193 });194 it('should throw when dependencies are out of order between navigations', () => {195 if (!configJson.navigations) throw new Error('Failed to run beforeEach');196 const invalidNavigation = {id: 'default', artifacts: ['Dependent']};197 configJson.navigations = [invalidNavigation];198 expect(() => initializeConfig(configJson, {gatherMode: 'snapshot'}))199 .toThrow(/Failed to find dependency/);200 });201 it('should throw when timespan needs snapshot', () => {202 dependentGatherer.meta.supportedModes = ['timespan'];203 dependencyGatherer.meta.supportedModes = ['snapshot'];204 expect(() => initializeConfig(configJson, {gatherMode: 'navigation'}))205 .toThrow(/Dependency.*is invalid/);206 });207 it('should throw when timespan needs navigation', () => {208 dependentGatherer.meta.supportedModes = ['timespan'];209 dependencyGatherer.meta.supportedModes = ['navigation'];210 expect(() => initializeConfig(configJson, {gatherMode: 'navigation'}))211 .toThrow(/Dependency.*is invalid/);212 });213 it('should throw when navigation needs snapshot', () => {214 dependentGatherer.meta.supportedModes = ['navigation'];215 dependencyGatherer.meta.supportedModes = ['snapshot'];216 expect(() => initializeConfig(configJson, {gatherMode: 'navigation'}))217 .toThrow(/Dependency.*is invalid/);218 });219 });220 it.todo('should support extension');221 it.todo('should support plugins');222 it.todo('should adjust default pass options for throttling method');223 it.todo('should filter configuration by inclusive settings');224 it.todo('should filter configuration by exclusive settings');225 it.todo('should validate audit/gatherer interdependencies');226 it.todo('should validate gatherers do not support all 3 modes');...
app.js
Source:app.js
1'use strict';2angular3 .module('bahmni.appointments')4 .config(['$urlRouterProvider', '$stateProvider', '$httpProvider', '$bahmniTranslateProvider', '$compileProvider',5 function ($urlRouterProvider, $stateProvider, $httpProvider, $bahmniTranslateProvider, $compileProvider) {6 $httpProvider.defaults.headers.common['Disable-WWW-Authenticate'] = true;7 $urlRouterProvider.otherwise('/home/manage/summary');8 $urlRouterProvider.when('/home/manage', '/home/manage/summary');9 // @if DEBUG='production'10 $compileProvider.debugInfoEnabled(false);11 // @endif12 // @if DEBUG='development'13 $compileProvider.debugInfoEnabled(true);14 // @endif15 $stateProvider16 .state('home', {17 url: '/home',18 abstract: true,19 views: {20 'additional-header': {21 templateUrl: 'views/appointmentsHeader.html',22 controller: 'AppointmentsHeaderController'23 },24 'mainContent': {25 template: '<div class="opd-wrapper appointments-page-wrapper">' +26 '<div ui-view="content" class="opd-content-wrapper appointments-content-wrapper"></div>' +27 '</div>'28 }29 },30 data: {31 backLinks: []32 },33 resolve: {34 initializeConfig: function (initialization, $stateParams) {35 return initialization($stateParams.appName);36 }37 }38 }).state('home.manage', {39 url: '/manage',40 views: {41 'content': {42 templateUrl: 'views/manage/appointmentsManage.html',43 controller: 'AppointmentsManageController'44 }45 }46 }).state('home.manage.summary', {47 url: '/summary',48 tabName: 'summary',49 params: {50 viewDate: null51 },52 views: {53 'content@manage': {54 templateUrl: 'views/manage/appointmentsSummary.html',55 controller: 'AppointmentsSummaryController'56 }57 }58 }).state('home.manage.appointments', {59 url: '/appointments',60 params: {61 filterParams: {},62 isFilterOpen: true,63 isSearchEnabled: false64 },65 views: {66 'filter': {67 templateUrl: 'views/manage/appointmentFilter.html',68 controller: 'AppointmentsFilterController'69 },70 'content@manage': {71 templateUrl: 'views/manage/allAppointments.html',72 controller: 'AllAppointmentsController'73 }74 }75 }).state('home.manage.appointments.calendar', {76 url: '/calendar',77 tabName: 'calendar',78 params: {79 viewDate: null,80 doFetchAppointmentsData: true,81 appointmentsData: null,82 weekView: false83 },84 views: {85 'content@viewAppointments': {86 templateUrl: 'views/manage/calendar/calendarView.html',87 controller: 'AppointmentsCalendarViewController'88 }89 }90 }).state('home.manage.appointments.calendar.new', {91 url: '/new',92 params: {93 appointment: null94 },95 views: {96 'content@appointment': {97 templateUrl: 'views/manage/newAppointment.html',98 controller: 'AppointmentsCreateController'99 }100 },101 resolve: {102 appointmentContext: function (appointmentInitialization, $stateParams) {103 return appointmentInitialization($stateParams);104 },105 appointmentCreateConfig: function (initializeConfig, appointmentConfigInitialization, appointmentContext) {106 return appointmentConfigInitialization(appointmentContext);107 }108 }109 }).state('home.manage.appointments.calendar.edit', {110 url: '/:uuid',111 views: {112 'content@appointment': {113 templateUrl: 'views/manage/newAppointment.html',114 controller: 'AppointmentsCreateController'115 }116 },117 resolve: {118 appointmentContext: function (appointmentInitialization, $stateParams) {119 return appointmentInitialization($stateParams);120 },121 appointmentCreateConfig: function (initializeConfig, appointmentConfigInitialization, appointmentContext) {122 return appointmentConfigInitialization(appointmentContext);123 }124 }125 }).state('home.manage.appointments.list', {126 url: '/list',127 tabName: 'list',128 params: {129 viewDate: null,130 patient: null,131 doFetchAppointmentsData: true,132 appointmentsData: null133 },134 views: {135 'content@viewAppointments': {136 templateUrl: 'views/manage/list/listView.html',137 controller: 'AppointmentsListViewController'138 }139 }140 }).state('home.manage.appointments.list.new', {141 url: '/new',142 views: {143 'content@appointment': {144 templateUrl: 'views/manage/newAppointment.html',145 controller: 'AppointmentsCreateController'146 }147 },148 resolve: {149 appointmentContext: function (appointmentInitialization, $stateParams) {150 return appointmentInitialization($stateParams);151 },152 appointmentCreateConfig: function (initializeConfig, appointmentConfigInitialization, appointmentContext) {153 return appointmentConfigInitialization(appointmentContext);154 }155 }156 }).state('home.manage.appointments.list.edit', {157 url: '/:uuid',158 views: {159 'content@appointment': {160 templateUrl: 'views/manage/newAppointment.html',161 controller: 'AppointmentsCreateController'162 }163 },164 resolve: {165 appointmentContext: function (appointmentInitialization, $stateParams) {166 return appointmentInitialization($stateParams);167 },168 appointmentCreateConfig: function (initializeConfig, appointmentConfigInitialization, appointmentContext) {169 return appointmentConfigInitialization(appointmentContext);170 }171 }172 }).state('home.admin', {173 url: '/admin',174 abstract: true,175 views: {176 'content': {177 templateUrl: 'views/admin/appointmentsAdmin.html'178 }179 }180 }).state('home.admin.service', {181 url: '/service',182 views: {183 'content@admin': {184 templateUrl: 'views/admin/allAppointmentServices.html',185 controller: 'AllAppointmentServicesController'186 }187 }188 }).state('home.admin.service.edit', {189 url: '/:uuid',190 views: {191 'content@admin': {192 templateUrl: 'views/admin/appointmentService.html',193 controller: 'AppointmentServiceController'194 }195 },196 resolve: {197 appointmentServiceContext: function (appointmentServiceInitialization, $stateParams) {198 return appointmentServiceInitialization($stateParams.uuid);199 }200 }201 });202 $bahmniTranslateProvider.init({app: 'appointments', shouldMerge: true});203 }]).run(['$window', function ($window) {204 moment.locale($window.localStorage["NG_TRANSLATE_LANG_KEY"] || "en");...
pipe-architect.test.js
Source:pipe-architect.test.js
...7 expect = chai.expect;8chai.use(sinonChai);9describe('pipe architect', function () {10 it('should resolve the default buildDir correctly', function (done) {11 architect.initializeConfig().then(function (data) {12 expect(data.buildDir).to.equal(path.resolve('build'));13 done();14 });15 });16 it('should resolve a custom buildDir correctly', function (done) {17 architect.initializeConfig({18 buildDir: 'my-custom-build-dir'19 }).then(function (data) {20 expect(data.buildDir).to.equal(path.resolve('my-custom-build-dir'));21 done();22 });23 });24 it('should resolve the default contentDir correctly', function (done) {25 architect.initializeConfig().then(function (data) {26 expect(data.contentDir).to.equal(path.resolve('content'));27 done();28 });29 });30 it('should resolve a custom contentDir correctly', function (done) {31 architect.initializeConfig({32 contentDir: 'my-custom-content-dir'33 }).then(function (data) {34 expect(data.contentDir).to.equal(path.resolve('my-custom-content-dir'));35 done();36 });37 });38 it('should resolve the themesDir correctly', function (done) {39 architect.initializeConfig().then(function (data) {40 expect(data.themesDir).to.equal(path.resolve('themes'));41 done();42 });43 });44 it('should resolve a custom themesDir correctly', function (done) {45 architect.initializeConfig({46 themesDir: 'my-custom-themes-dir'47 }).then(function (data) {48 expect(data.themesDir).to.equal(path.resolve('my-custom-themes-dir'));49 done();50 });51 });52 it('should resolve a custom content structure', function (done) {53 architect.initializeConfig({54 contentDir: 'test/content',55 content: {56 'test-category-two/': {57 type: 'pages'58 }59 }60 }).then(architect.loadCustoms).then(function (data) {61 expect(data.content).to.deep.equal({62 './': {63 type: 'pages'64 },65 'static/': {66 type: 'statics'67 },...
get-stompit-queue-config.test.js
Source:get-stompit-queue-config.test.js
1import { initializeConfig } from '../../';2import { getStompitQueueConfig } from '../get-stompit-queue-config';3jest.mock('../../');4describe('getStompitQueueConfig', () => {5 const hosts = [6 {7 host: 'mq-1',8 port: '61613',9 ssl: false,10 connectHeaders: { login: 'guest', passcode: 'guest', host: '/' }11 },12 {13 host: 'mq-2',14 port: '61613',15 ssl: false,16 connectHeaders: { login: 'guest', passcode: 'guest', host: '/' }17 }18 ];19 it('should output an array that is the same length as config queueUrls', () => {20 const mockQueueUrls = ['tcp://mq-1:61613', 'tcp://mq-2:61613'];21 initializeConfig.mockReturnValue({22 queueUrls: mockQueueUrls,23 queueUsername: 'guest',24 queuePassword: 'guest',25 queueVirtualHost: '/'26 });27 expect(Array.isArray(getStompitQueueConfig())).toBe(true);28 expect(getStompitQueueConfig().length).toEqual(hosts.length);29 });30 it('should correctly format the config to match stompit config requirements', () => {31 const mockQueueUrls = ['tcp://mq-1:61613', 'tcp://mq-2:61613'];32 initializeConfig.mockReturnValue({33 queueUrls: mockQueueUrls,34 queueUsername: 'guest',35 queuePassword: 'guest',36 queueVirtualHost: '/'37 });38 expect(getStompitQueueConfig()).toEqual(hosts);39 });40 it('should remove any empty urls from config.queueUrls before parsing', () => {41 const mockQueueUrls = ['tcp://mq-1:61613', ''];42 initializeConfig.mockReturnValue({43 queueUrls: mockQueueUrls,44 queueUsername: 'guest',45 queuePassword: 'guest',46 queueVirtualHost: '/'47 });48 expect(getStompitQueueConfig()).toEqual([hosts[0]]);49 });50 it('should return an empty array if there are no queueUrls defined in config', () => {51 const mockQueueUrls = ['', ''];52 initializeConfig.mockReturnValue({53 queueUrls: mockQueueUrls,54 queueUsername: 'guest',55 queuePassword: 'guest',56 queueVirtualHost: '/'57 });58 expect(getStompitQueueConfig()).toEqual([]);59 });...
abstractlayerconfig.test.js
Source:abstractlayerconfig.test.js
...4 const {default: AbstractLayerConfig} = goog.module.get('os.layer.config.AbstractLayerConfig');5 it('has a default size option', function() {6 var lc = new AbstractLayerConfig();7 var options = {};8 lc.initializeConfig(options);9 expect(lc.size).toBe(3);10 });11 it('handles the size option', function() {12 var lc = new AbstractLayerConfig();13 var options = {'size': 4};14 lc.initializeConfig(options);15 expect(lc.size).toBe(4);16 });17 it('is visible by default', function() {18 var lc = new AbstractLayerConfig();19 var options = {};20 lc.initializeConfig(options);21 expect(lc.visible).toBe(true);22 });23 it('handles the visible option for false', function() {24 var lc = new AbstractLayerConfig();25 var options = {'visible': false};26 lc.initializeConfig(options);27 expect(lc.visible).toBe(false);28 });29 it('handles the visible option for true', function() {30 var lc = new AbstractLayerConfig();31 var options = {'visible': true};32 lc.initializeConfig(options);33 expect(lc.visible).toBe(true);34 });35 it('is does not colorize by default', function() {36 var lc = new AbstractLayerConfig();37 var options = {};38 lc.initializeConfig(options);39 expect(lc.colorize).toBe(false);40 });41 it('handles the colorize option for true', function() {42 var lc = new AbstractLayerConfig();43 var options = {'colorize': true};44 lc.initializeConfig(options);45 expect(lc.colorize).toBe(true);46 });47 it('handles the colorize option for false', function() {48 var lc = new AbstractLayerConfig();49 var options = {'colorize': false};50 lc.initializeConfig(options);51 expect(lc.colorize).toBe(false);52 });...
normalize.js
Source:normalize.js
1const path = require('path')2const fs = require('fs-extra')3const initializeConfig = require('happo/lib/initializeConfig')4const { config, getLastResultSummary, pathToSnapshot } = require('happo-core')5config.set(initializeConfig())6const resultSummaryJSON = getLastResultSummary()7Promise.all(8 resultSummaryJSON.newImages.map(newImage => {9 const input = pathToSnapshot({10 ...newImage,11 fileName: 'current.png',12 })13 const [suite, name] = newImage.description.split('-')14 const output = path.join(15 config.get().snapshotsFolder,16 suite,17 `${name}-${newImage.viewportName}.png`18 )19 return new Promise((accept, reject) => {...
destructuring.js
Source:destructuring.js
...7}8/**9 * Destructuring10 */11function initializeConfig() {12 const serverState = window.fromServerState;13 dispatch(setStepInitialize({14 token: serverState.config.token,15 mallKey: serverState.config.mallKey,16 authKey: serverState.config.authKey,17 isMember: serverState.config.isMember,18 isEnable: serverState.config.isEnable19 }));20}21var fromServerState = {22 /**23 * initializeConfig í¨ì를 ê·¼ê±°ë¡ ì´ ê°ì²´ì 구조를 ë§ë¤ì´ë¼24 */25};...
Firebase.init.jsx
Source:Firebase.init.jsx
1import { initializeApp } from "firebase/app";2import { getAuth } from 'firebase/auth';3const firebaseConfig = {4 apiKey: "AIzaSyD6xT2b_Y_iSl5JnMZ7b2OvMb-PZfl_UvA",5 authDomain: "router-firebase-integrat-5f508.firebaseapp.com",6 projectId: "router-firebase-integrat-5f508",7 storageBucket: "router-firebase-integrat-5f508.appspot.com",8 messagingSenderId: "142864760680",9 appId: "1:142864760680:web:b040e9732d48f05e43e0dd"10};11const initializeConfig = initializeApp(firebaseConfig);12export const auth = getAuth(initializeConfig);...
Using AI Code Generation
1before(() => {2 cy.initializeConfig()3})4before(() => {5 cy.initializeConfig()6})7before(() => {8 cy.initializeConfig()9})10before(() => {11 cy.initializeConfig()12})13before(() => {14 cy.initializeConfig()15})16before(() => {17 cy.initializeConfig()18})19before(() => {20 cy.initializeConfig()21})22before(() => {23 cy.initializeConfig()24})
Using AI Code Generation
1import { initializeConfig } from 'cypress-firebase';2import fbConfig from './firebase.json';3initializeConfig(fbConfig);4describe('My First Test', () => {5 it('Does not do much!', () => {6 expect(true).to.equal(true);7 });8});9describe('My First Test', () => {10 it('Does not do much!', () => {11 });12});13initializeConfig(config, options);14cy.login(email, password);15cy.logout();16cy.signup(email, password);17cy.getAuthUser();18cy.createUser(email, password);19cy.deleteUser(email, password);20cy.updateUser(email, password);21cy.resetPassword(email);22cy.updateProfile(displayName, photoURL);23cy.updateEmail(email);
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.
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.
Watch this 3 hours of complete tutorial to learn the basics of Cypress and various Cypress commands with the Cypress testing at LambdaTest.
Get 100 minutes of automation test minutes FREE!!