Best JavaScript code snippet using cypress
config_spec.js
Source:config_spec.js
...1394 it('does nothing if supportFile is falsey', () => {1395 const obj = {1396 projectRoot: '/_test-output/path/to/project',1397 }1398 return config.setSupportFileAndFolder(obj)1399 .then((result) => {1400 expect(result).to.eql(obj)1401 })1402 })1403 it('sets the full path to the supportFile and supportFolder if it exists', () => {1404 const projectRoot = process.cwd()1405 const obj = config.setAbsolutePaths({1406 projectRoot,1407 supportFile: 'test/unit/config_spec.js',1408 })1409 return config.setSupportFileAndFolder(obj)1410 .then((result) => {1411 expect(result).to.eql({1412 projectRoot,1413 supportFile: `${projectRoot}/test/unit/config_spec.js`,1414 supportFolder: `${projectRoot}/test/unit`,1415 })1416 })1417 })1418 it('sets the supportFile to default index.js if it does not exist, support folder does not exist, and supportFile is the default', () => {1419 const projectRoot = path.join(process.cwd(), 'test/support/fixtures/projects/no-scaffolding')1420 const obj = config.setAbsolutePaths({1421 projectRoot,1422 supportFile: 'cypress/support',1423 })1424 return config.setSupportFileAndFolder(obj)1425 .then((result) => {1426 expect(result).to.eql({1427 projectRoot,1428 supportFile: `${projectRoot}/cypress/support/index.js`,1429 supportFolder: `${projectRoot}/cypress/support`,1430 })1431 })1432 })1433 it('sets the supportFile to false if it does not exist, support folder exists, and supportFile is the default', () => {1434 const projectRoot = path.join(process.cwd(), 'test/support/fixtures/projects/empty-folders')1435 const obj = config.setAbsolutePaths({1436 projectRoot,1437 supportFile: 'cypress/support',1438 })1439 return config.setSupportFileAndFolder(obj)1440 .then((result) => {1441 expect(result).to.eql({1442 projectRoot,1443 supportFile: false,1444 })1445 })1446 })1447 it('throws error if supportFile is not default and does not exist', () => {1448 const projectRoot = process.cwd()1449 const obj = config.setAbsolutePaths({1450 projectRoot,1451 supportFile: 'does/not/exist',1452 })1453 return config.setSupportFileAndFolder(obj)1454 .catch((err) => {1455 expect(err.message).to.include('The support file is missing or invalid.')1456 })1457 })1458 it('sets the supportFile to index.ts if it exists (without ts require hook)', () => {1459 const projectRoot = path.join(process.cwd(), 'test/support/fixtures/projects/ts-proj')1460 const supportFolder = `${projectRoot}/cypress/support`1461 const supportFilename = `${supportFolder}/index.ts`1462 const e = new Error('Cannot resolve TS file by default')1463 e.code = 'MODULE_NOT_FOUND'1464 sinon.stub(config.utils, 'resolveModule').withArgs(supportFolder).throws(e)1465 const obj = config.setAbsolutePaths({1466 projectRoot,1467 supportFile: 'cypress/support',1468 })1469 return config.setSupportFileAndFolder(obj)1470 .then((result) => {1471 debug('result is', result)1472 expect(result).to.eql({1473 projectRoot,1474 supportFolder,1475 supportFile: supportFilename,1476 })1477 })1478 })1479 it('uses custom TS supportFile if it exists (without ts require hook)', () => {1480 const projectRoot = path.join(process.cwd(), 'test/support/fixtures/projects/ts-proj-custom-names')1481 const supportFolder = `${projectRoot}/cypress`1482 const supportFilename = `${supportFolder}/support.ts`1483 const e = new Error('Cannot resolve TS file by default')1484 e.code = 'MODULE_NOT_FOUND'1485 sinon.stub(config.utils, 'resolveModule').withArgs(supportFilename).throws(e)1486 const obj = config.setAbsolutePaths({1487 projectRoot,1488 supportFile: 'cypress/support.ts',1489 })1490 return config.setSupportFileAndFolder(obj)1491 .then((result) => {1492 debug('result is', result)1493 expect(result).to.eql({1494 projectRoot,1495 supportFolder,1496 supportFile: supportFilename,1497 })1498 })1499 })1500 })1501 context('.setPluginsFile', () => {1502 it('does nothing if pluginsFile is falsey', () => {1503 const obj = {1504 projectRoot: '/_test-output/path/to/project',...
config.js
Source:config.js
...180 config_1.default.validate(lodash_1.default.omit(config, 'browsers'), (errMsg) => {181 return errors_1.default.throw('CONFIG_VALIDATION_ERROR', errMsg);182 });183 config_1.default.validateNoBreakingConfig(config, errors_1.default.warning, errors_1.default.throw);184 return setSupportFileAndFolder(config, defaultsForRuntime)185 .then((obj) => (0, exports.setPluginsFile)(obj, defaultsForRuntime))186 .then(setScaffoldPaths);187}188exports.mergeDefaults = mergeDefaults;189function setResolvedConfigValues(config, defaults, resolved) {190 const obj = lodash_1.default.clone(config);191 obj.resolved = resolveConfigValues(config, defaults, resolved);192 debug('resolved config is %o', obj.resolved.browsers);193 return obj;194}195exports.setResolvedConfigValues = setResolvedConfigValues;196// Given an object "resolvedObj" and a list of overrides in "obj"197// marks all properties from "obj" inside "resolvedObj" using198// {value: obj.val, from: "plugin"}199function setPluginResolvedOn(resolvedObj, obj) {200 return lodash_1.default.each(obj, (val, key) => {201 if (lodash_1.default.isObject(val) && !lodash_1.default.isArray(val) && resolvedObj[key]) {202 // recurse setting overrides203 // inside of objected204 return setPluginResolvedOn(resolvedObj[key], val);205 }206 const valueFrom = {207 value: val,208 from: 'plugin',209 };210 resolvedObj[key] = valueFrom;211 });212}213exports.setPluginResolvedOn = setPluginResolvedOn;214function updateWithPluginValues(cfg, overrides) {215 if (!overrides) {216 overrides = {};217 }218 debug('updateWithPluginValues %o', { cfg, overrides });219 // make sure every option returned from the plugins file220 // passes our validation functions221 config_1.default.validate(overrides, (errMsg) => {222 if (cfg.pluginsFile && cfg.projectRoot) {223 const relativePluginsPath = path_1.default.relative(cfg.projectRoot, cfg.pluginsFile);224 return errors_1.default.throw('PLUGINS_CONFIG_VALIDATION_ERROR', relativePluginsPath, errMsg);225 }226 return errors_1.default.throw('CONFIG_VALIDATION_ERROR', errMsg);227 });228 let originalResolvedBrowsers = cfg && cfg.resolved && cfg.resolved.browsers && lodash_1.default.cloneDeep(cfg.resolved.browsers);229 if (!originalResolvedBrowsers) {230 // have something to resolve with if plugins return nothing231 originalResolvedBrowsers = {232 value: cfg.browsers,233 from: 'default',234 };235 }236 const diffs = (0, return_deep_diff_1.default)(cfg, overrides, true);237 debug('config diffs %o', diffs);238 const userBrowserList = diffs && diffs.browsers && lodash_1.default.cloneDeep(diffs.browsers);239 if (userBrowserList) {240 debug('user browser list %o', userBrowserList);241 }242 // for each override go through243 // and change the resolved values of cfg244 // to point to the plugin245 if (diffs) {246 debug('resolved config before diffs %o', cfg.resolved);247 setPluginResolvedOn(cfg.resolved, diffs);248 debug('resolved config object %o', cfg.resolved);249 }250 // merge cfg into overrides251 const merged = lodash_1.default.defaultsDeep(diffs, cfg);252 debug('merged config object %o', merged);253 // the above _.defaultsDeep combines arrays,254 // if diffs.browsers = [1] and cfg.browsers = [1, 2]255 // then the merged result merged.browsers = [1, 2]256 // which is NOT what we want257 if (Array.isArray(userBrowserList) && userBrowserList.length) {258 merged.browsers = userBrowserList;259 merged.resolved.browsers.value = userBrowserList;260 }261 if (overrides.browsers === null) {262 // null breaks everything when merging lists263 debug('replacing null browsers with original list %o', originalResolvedBrowsers);264 merged.browsers = cfg.browsers;265 if (originalResolvedBrowsers) {266 merged.resolved.browsers = originalResolvedBrowsers;267 }268 }269 debug('merged plugins config %o', merged);270 return merged;271}272exports.updateWithPluginValues = updateWithPluginValues;273// combines the default configuration object with values specified in the274// configuration file like "cypress.json". Values in configuration file275// overwrite the defaults.276function resolveConfigValues(config, defaults, resolved = {}) {277 // pick out only known configuration keys278 return lodash_1.default279 .chain(config)280 .pick(config_1.default.getPublicConfigKeys())281 .mapValues((val, key) => {282 let r;283 const source = (s) => {284 return {285 value: val,286 from: s,287 };288 };289 r = resolved[key];290 if (r) {291 if (lodash_1.default.isObject(r)) {292 return r;293 }294 return source(r);295 }296 if (!(!lodash_1.default.isEqual(config[key], defaults[key]) && key !== 'browsers')) {297 // "browsers" list is special, since it is dynamic by default298 // and can only be overwritten via plugins file299 return source('default');300 }301 return source('config');302 }).value();303}304exports.resolveConfigValues = resolveConfigValues;305// instead of the built-in Node process, specify a path to 3rd party Node306const setNodeBinary = (obj, userNodePath, userNodeVersion) => {307 // if execPath isn't found we weren't executed from the CLI and should used the bundled node version.308 if (userNodePath && userNodeVersion && obj.nodeVersion !== 'bundled') {309 obj.resolvedNodePath = userNodePath;310 obj.resolvedNodeVersion = userNodeVersion;311 return obj;312 }313 obj.resolvedNodeVersion = process.versions.node;314 return obj;315};316exports.setNodeBinary = setNodeBinary;317function setScaffoldPaths(obj) {318 obj = lodash_1.default.clone(obj);319 debug('set scaffold paths');320 return scaffold_1.default.fileTree(obj)321 .then((fileTree) => {322 debug('got file tree');323 obj.scaffoldedFiles = fileTree;324 return obj;325 });326}327exports.setScaffoldPaths = setScaffoldPaths;328// async function329function setSupportFileAndFolder(obj, defaults) {330 if (!obj.supportFile) {331 return bluebird_1.default.resolve(obj);332 }333 obj = lodash_1.default.clone(obj);334 // TODO move this logic to find support file into util/path_helpers335 const sf = obj.supportFile;336 debug(`setting support file ${sf}`);337 debug(`for project root ${obj.projectRoot}`);338 return bluebird_1.default339 .try(() => {340 // resolve full path with extension341 obj.supportFile = exports.utils.resolveModule(sf);342 return debug('resolved support file %s', obj.supportFile);343 }).then(() => {...
Using AI Code Generation
1describe('My First Test', () => {2 it('Does not do much!', () => {3 cy.contains('type').click()4 cy.url().should('include', '/commands/actions')5 cy.get('.action-email')6 .type('
Using AI Code Generation
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('
Using AI Code Generation
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('
Using AI Code Generation
1describe('My First Test', function() {2 it('Does not do much!', function() {3 cy.setSupportFileAndFolder('support','supportFolder');4 })5})6describe('My First Test', function() {7 it('Does not do much!', function() {8 cy.setSupportFileAndFolder('support','supportFolder');9 })10})11describe('My First Test', function() {12 it('Does not do much!', function() {13 cy.setSupportFileAndFolder('support','supportFolder');14 })15})16describe('My First Test', function() {17 it('Does not do much!', function() {18 cy.setSupportFileAndFolder('support','supportFolder');19 })20})21describe('My First Test', function() {22 it('Does not do much!', function() {23 cy.setSupportFileAndFolder('support','supportFolder');24 })25})26describe('My First Test', function() {27 it('Does not do much!', function() {28 cy.setSupportFileAndFolder('support','supportFolder');29 })30})31describe('My First Test', function() {32 it('Does not do much!', function() {33 cy.setSupportFileAndFolder('support','supportFolder');34 })35})36describe('My First Test', function() {37 it('Does not do much!', function() {38 cy.setSupportFileAndFolder('support','supportFolder');39 })40})41describe('My First Test', function() {42 it('Does not do much!', function() {
Using AI Code Generation
1const { setSupportFileAndFolder } = require('cypress/support-file-and-folder');2setSupportFileAndFolder('support', 'support');3const { setSupportFileAndFolder } = require('cypress/support-file-and-folder');4setSupportFileAndFolder('support', 'support');5const { setSupportFileAndFolder } = require('cypress/support-file-and-folder');6setSupportFileAndFolder('support', 'support');7const { setSupportFileAndFolder } = require('cypress/support-file-and-folder');8setSupportFileAndFolder('support', 'support');9const { setSupportFileAndFolder } = require('cypress/support-file-and-folder');10setSupportFileAndFolder('support', 'support');11const { setSupportFileAndFolder } = require('cypress/support-file-and-folder');12setSupportFileAndFolder('support', 'support');13const { setSupportFileAndFolder } = require('cypress/support-file-and-folder');14setSupportFileAndFolder('support', 'support');15const { setSupportFileAndFolder } = require('cypress/support-file-and-folder');16setSupportFileAndFolder('support', 'support');
Using AI Code Generation
1var path = require('path');2module.exports = (on, config) => {3 config = setSupportFileAndFolder(config);4 return config;5};6function setSupportFileAndFolder(config) {7 const supportFolder = path.join(__dirname, '..', 'support');8 config.supportFile = path.join(supportFolder, 'index.js');9 config.supportFolder = supportFolder;10 return config;11}12import './commands';13import { addMatchImageSnapshotCommand } from 'cypress-image-snapshot/command';14addMatchImageSnapshotCommand();15Cypress.Commands.add('login', () => {16 cy.visit('/login');17 cy.get('#username').type('test');18 cy.get('#password').type('test');19 cy.get('#login').click();20});21Cypress.Commands.add('logout', () => {22 cy.get('#logout').click();23});24Cypress.Commands.add('addTodo', (todo) => {25 cy.get('#new-todo').type(todo);26 cy.get('#new-todo').type('{enter}');27});28Cypress.Commands.add('deleteTodo', (todo) => {29 cy.get('li').contains(todo).find('button').click();30});31Cypress.Commands.add('toggleTodo', (todo) => {32 cy.get('li').contains(todo).find('input').click();33});34Cypress.Commands.add('editTodo', (todo, newTodo) => {35 cy.get('li').contains(todo).dblclick();36 cy.get('li').contains(todo).find('input').clear();37 cy.get('li').contains(todo).find('input').type(newTodo);38 cy.get('li').contains(todo).find('input').type('{enter}');39});40Cypress.Commands.add('filterTodos', (filter) => {41 cy.get('a').contains(filter).click();42});43Cypress.Commands.add('isOn', (page) => {44 cy.url().should('include', page);45});46Cypress.Commands.add('hasTodo', (todo) => {
Using AI Code Generation
1Cypress.setSupportFileAndFolder({2})3Cypress.setSupportFileAndFolder({4})5Cypress.setSupportFileAndFolder({6})7Cypress.setSupportFileAndFolder({8})
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!!