Best JavaScript code snippet using cypress
release.js
Source:release.js
1/*2 * @Author: eliduty3 * @Github: https://github.com/eliduty4 * @Date: 2022-02-10 14:02:105 * @LastEditors: eliduty6 * @LastEditTime: 2022-04-28 15:19:167 * @Description:8 */9/*10 åå¸æµç¨11 1ãæ建æå
12 2ãéæ©éè¦æ´æ°åå
13 3ãæ´æ°åå
çæ¬14 4ãæ´æ°ä¸»å
çæ¬å·ãgit tag ãçæchangelog15 */16const { readFileSync, writeFileSync } = require('fs');17const execa = require('execa');18const { prompt } = require('enquirer');19const semver = require('semver');20const chalk = require('chalk');21const args = require('minimist')(process.argv.slice(2));22const { getPackagesName, getPackage, getPackageFilePath, runParallel } = require('./utils');23const isPre = args.pre || args.p; // é¢åå¸24const run = (bin, args, opts = {}) => execa(bin, args, { stdio: 'inherit', ...opts });25const step = msg => console.log(chalk.cyan(msg));26const cupNumber = require('os').cpus().length;27main().catch(console.error);28async function main() {29 // æ£æ¥github gitæ交æ¯å¦æ£å¸¸30 await checkGithubNetwork();31 // æ£æ¥æ¯å¦ç»å½äºnpm32 await checkIsLoginNpm();33 // éæ©éè¦æ´æ°åå
34 const releasePackages = await selectPackages();35 // éæ©åå¸ççæ¬36 const releaseVersion = await selectReleaseVersion(isPre);37 // 计ç®çæ¬38 const versionInfo = await computedVersion(releasePackages, releaseVersion);39 //确认çæ¬å·40 await confirmVersion(versionInfo);41 //æ建æå
42 await buildPackages(releasePackages);43 // æ´æ°åå
çæ¬44 await updatePackages(versionInfo);45 // æ´æ°ä¸»å
çæ¬å·ãgit tag ãçæchangelog46 const isSuccess = await updateMainPackage();47 // æ ¹æ®ä¸»å
åå¸ç»æï¼å¤çåå
git message48 await commitPackagesMessage(versionInfo, !isSuccess);49 // åå¸å
50 await publishPackage(versionInfo);51 step('\nåå¸å®æï¼');52 // æ交git53 await commitGit();54}55/**56 * æ£æ¥github gitæ交æ¯å¦æ£å¸¸57 */58async function checkGithubNetwork() {59 step('\næ£æ¥githubç½ç»è¿æ¥...');60 const isSuccess = await run('git', ['pull']).catch(() => false);61 if (!isSuccess) {62 console.log(chalk.red('ç½ç»è¿æ¥å¼å¸¸ï¼'));63 process.exit();64 }65}66/**67 * æ£æ¥æ¯å¦ç»å½äºnpm68 */69async function checkIsLoginNpm() {70 step('\néªè¯å½åç»å½ç¶æ...');71 const isLogin = await run('pnpm', ['whoami']).catch(() => false);72 if (!isLogin) {73 console.log(chalk.red('ç¨æ·æªç»å½npmï¼'));74 process.exit();75 }76}77/**78 * éæ©åå¸çæ¬79 */80async function selectReleaseVersion(isPre) {81 const preReleaseVersion = [82 {83 name: 'prerelease',84 desc: 'å级é¢åå¸å·',85 },86 {87 name: 'prepatch',88 desc: 'å级修订å·ï¼ä¿çé¢åå¸å·',89 },90 {91 name: 'preminor',92 desc: 'å级次çæ¬å·ï¼ä¿çé¢åå¸å·',93 },94 {95 name: 'premajor',96 desc: 'å级主çæ¬å·ï¼ä¿çé¢åå¸å·',97 },98 ];99 const releaseVersion = [100 {101 name: 'patch',102 desc: 'å级修订å·',103 },104 {105 name: 'minor',106 desc: 'å级次çæ¬å·',107 },108 {109 name: 'major',110 desc: 'å级主çæ¬å·',111 },112 ];113 const versionIncrements = [...(isPre ? preReleaseVersion : releaseVersion)].concat([{ name: 'custom', desc: 'èªå®ä¹' }]);114 const { versionName } = await prompt({115 type: 'select',116 name: 'versionName',117 message: '[åé]请éæ©ä¸ä¸ªåå¸ççæ¬',118 choices: versionIncrements.map(i => ({119 message: `${i.name.padEnd(10, ' ')} - ${i.desc}`,120 name: i.name,121 })),122 });123 return versionName;124}125/**126 * éæ©è¦åå¸çå
127 * @returns128 */129async function selectPackages() {130 const packages = getPackagesName();131 const { releasePackages } = await prompt({132 type: 'multiselect',133 name: 'releasePackages',134 message: '[å¤é]请éæ©è¦åå¸çå
ï¼ä½¿ç¨ç©ºæ ¼é®éæ©ï¼',135 choices: packages,136 });137 if (!releasePackages.length) {138 throw new Error(`è³å°éæ©ä¸ä¸ªè¦åå¸çå
`);139 }140 return releasePackages;141}142/**143 * 计ç®çæ¬å·144 * @param {*} releasePackages145 * @param {*} releaseVersion146 */147async function computedVersion(packages, releaseVersion) {148 const isCustom = releaseVersion === 'custom';149 let customVersion;150 if (isCustom) {151 customVersion = (152 await prompt({153 type: 'input',154 name: 'version',155 message: '请è¾å
¥çæ¬å·(示ä¾ï¼1.2.3)',156 })157 ).version;158 if (!semver.valid(customVersion)) {159 throw new Error(`æ æççæ¬å·: ${customVersion}`);160 }161 }162 let versionInfo = [];163 packages.forEach(package => {164 const current = getPackage(package).version;165 const target = isCustom ? customVersion : semver.inc(getPackage(package).version, releaseVersion);166 versionInfo.push({167 package,168 current,169 target,170 isValid: semver.lt(current, target),171 });172 });173 return versionInfo;174}175/**176 * 确认çæ¬ä¿¡æ¯177 * @param {*} versionInfo178 */179async function confirmVersion(versionInfo) {180 step('确认çæ¬ä¿¡æ¯');181 let invalidVersion = [];182 versionInfo.map(version => {183 const isValid = version.isValid;184 !isValid && invalidVersion.push(version);185 console.log(`${isValid ? 'â
' : 'â'} ${version.package} (${version.current} â ${version.target})\n`);186 });187 if (invalidVersion.length) {188 const invalidPackage = invalidVersion.map(item => item.package).join('ã');189 throw new Error(`${invalidPackage}ç®æ çæ¬å·æ æ`);190 }191 const { yes } = await prompt({192 type: 'confirm',193 name: 'yes',194 message: `确认åå¸ï¼`,195 });196 if (!yes) {197 process.exit();198 }199}200/**201 * æ建æå
202 */203async function buildPackages(packages) {204 step('\næ£å¨æ建...');205 await run('pnpm', ['run', 'build', ...packages]);206}207/**208 * æ´æ°åå
çæ¬ä¿¡æ¯209 * @param {*} releasePackagesVersionInfo210 */211async function updatePackages(releasePackagesVersionInfo) {212 step('\næ£å¨æ´æ°åå
çæ¬...');213 releasePackagesVersionInfo.forEach(item => {214 const pkgPath = getPackageFilePath(item.package);215 const pkg = JSON.parse(readFileSync(pkgPath, 'utf-8'));216 pkg.version = item.target;217 writeFileSync(pkgPath, JSON.stringify(pkg, '', '\t'), { encoding: 'utf8' });218 });219}220/**221 * æ´æ°ä¸»å
222 */223async function updateMainPackage() {224 step('\næ´æ°ä¸»å
ä¿¡æ¯...');225 const isSuccess = await run('pnpm', ['run', 'version']).catch(() => false);226 return !!isSuccess;227}228async function commitPackagesMessage(releasePackagesVersionInfo, isRollBack) {229 if (isRollBack) {230 // 主å
åå¸å¤±è´¥ åæ»åå
231 runParallel(cupNumber, releasePackagesVersionInfo, rollback);232 } else {233 // 主å
åå¸æå æ交åå
message234 const releaseCommit = [];235 releasePackagesVersionInfo.forEach(item => {236 // åå
commit message237 releaseCommit.push(`${item.package} v${item.target}`);238 });239 // æ交åå
commit message240 const { stdout } = await run('git', ['diff'], { stdio: 'pipe' });241 if (stdout) {242 step('\nCommitting changes...');243 await run('git', ['add', '-A']);244 await run('git', ['commit', '-m', `chore(release): ${releaseCommit.join(' ')}`]);245 } else {246 console.log('No changes to commit.');247 }248 }249}250/**251 * åæ»å
252 * @param {*} package253 */254async function rollback(versionInfo) {255 const pkgPath = getPackageFilePath(versionInfo.package);256 step(`\næ£å¨åæ»${pkgPath}...`);257 await run('git', ['checkout', '-q', '--', pkgPath]);258}259/**260 * åå¸éä¸çå
261 */262async function publishPackage(versionInfoList) {263 step('\nåå¸å
å°npm...');264 await runParallel(cupNumber, versionInfoList, pushlish);265}266async function pushlish(versionInfo) {267 step(`\næ£å¨åå¸${versionInfo.package}...`);268 await run('pnpm', ['publish', '--filter', versionInfo.package, '--access', 'public']);269}270async function commitGit() {271 step(`\næ交gitä¿¡æ¯...`);272 try {273 await run('git', ['push']);274 await run('git', ['push', '--follow-tags origin main']);275 } catch (err) {276 console.log(chalk.red('githubç½ç»è¿æ¥å¼å¸¸ï¼è¯·å°è¯æå¨æ交ï¼'));277 }...
ReimageService.js
Source:ReimageService.js
1var reimageServices = angular.module("mcd.am.service.reimage", ["ngResource"]);2reimageServices.factory("reimageService", ["$resource",3 function ($resource) {4 return $resource(Utils.ServiceURI.Address() + 'api/Reimage/:action', {}, {5 createProject: { method: "POST", params: { action: "CreateProject" }, isArray: false },6 getReimageInfo: { method: 'GET', params: { action: 'GetReimageInfo', projectId: '@projectId' }, isArray: false },7 getEstimatedVsActualConstruction: {8 method: 'GET',9 params: { action: 'GetEstimatedVsActualConstruction' },10 isArray: false11 },12 getReimageSummary: { method: 'GET', params: { action: 'GetReimageSummary', projectId: '@projectId' }, isArray: false },13 submitConsInfo: { method: 'POST', params: { action: 'SubmitConsInfo' }, isArray: false },14 saveConsInfo: {15 method: "POST",16 params: { action: "SaveConsInfo" },17 isArray: false18 },19 recallConsInfo: {20 method: "POST",21 params: { contorller: "ConsInfo", action: "RecallConsInfo" },22 isArray: false23 },24 editConsInfo: {25 method: "POST",26 params: { contorller: "ConsInfo", action: "EditConsInfo" },27 isArray: false28 },29 getKeyMeasuresInfo: {30 method: "GET",31 params: { action: "GetKeyMeasuresInfo" },32 isArray: false33 },34 getConsInfo: {35 method: "GET",36 params: { action: "GetConsInfo" },37 isArray: false38 },39 getConsInfoAgreementList: {40 method: "GET",41 params: { action: "GetConsInfoAgreementList" },42 isArray: true43 },44 getPackageAgreementList: {45 method: "GET",46 params: { action: "GetPackageAgreementList" },47 isArray: true48 },49 getInvestCost: {50 method: "GET",51 params: { action: "GetInvestCost" },52 isArray: false53 },54 getPackageInfo: {55 method: "GET",56 params: { action: "GetPackageInfo" },57 isArray: false58 },59 getConsInvtChecking: {60 method: "GET",61 params: { action: "GetConsInvtChecking" },62 isArray: false63 },64 getWriteOff: {65 method: "GET",66 params: { action: "GetWriteOff" },67 isArray: false68 },69 returnConsInfo: {70 method: 'POST',71 params: { action: 'ReturnConsInfo' },72 isArray: false73 },74 returnPackage: {75 method: 'POST',76 params: { action: 'ReturnPackage' },77 isArray: false78 },79 getPackageAgreementList: {80 method: 'GET',81 params: { action: 'GetPackageAgreementList' },82 isArray: true83 },84 resubmitConsInfo: {85 method: "POST",86 params: { contorller: "ConsInfo", action: "ResubmitConsInfo" },87 isArray: false88 },89 approveConsInfo: { method: 'POST', params: { action: 'ApproveConsInfo' }, isArray: false },90 approvePackage: { method: 'POST', params: { action: 'ApprovePackage' }, isArray: false },91 approveConsInvtChecking: { method: 'POST', params: { action: 'ApproveConsInvtChecking' }, isArray: false },92 rejectConsInfo: { method: 'POST', params: { action: 'RejectConsInfo' }, isArray: false },93 rejectPackage: { method: 'POST', params: { action: 'RejectPackage' }, isArray: false },94 recallPackage: { method: 'POST', params: { action: 'RecallPackage' }, isArray: false },95 recallConsInvtChecking: { method: 'POST', params: { action: 'RecallConsInvtChecking' }, isArray: false },96 returnConsInvtChecking: { method: 'POST', params: { action: 'ReturnConsInvtChecking' }, isArray: false },97 editPackage: { method: 'POST', params: { action: 'EditPackage' }, isArray: false },98 editConsInvtChecking: { method: 'POST', params: { action: 'EditConsInvtChecking' }, isArray: false },99 initReimageSummary: {100 method: "GET",101 params: { action: "InitReimageSummary" },102 isArray: false103 },104 saveReimageSummary: {105 method: "POST",106 params: { action: "SaveReimageSummary" },107 isArray: false108 },109 recallReimageSummary: {110 method: "POST",111 params: { contorller: "Reimage", action: "RecallReimageSummary" },112 isArray: false113 },114 editReimageSummary: {115 method: "POST",116 params: { contorller: "Reimage", action: "EditReimageSummary" },117 isArray: false118 },119 savePackage: {120 method: "POST",121 params: { action: "SavePackage" },122 isArray: false123 },124 saveConsInvtChecking: {125 method: "POST",126 params: { action: "SaveConsInvtChecking" },127 isArray: false128 },129 submitConsInvtChecking: {130 method: "POST",131 params: { action: "SubmitConsInvtChecking" },132 isArray: false133 },134 resubmitConsInvtChecking: {135 method: "POST",136 params: { action: "ResubmitConsInvtChecking" },137 isArray: false138 },139 resubmitPackage: {140 method: "POST",141 params: { action: "ResubmitPackage" },142 isArray: false143 },144 submitPackage: {145 method: "POST",146 params: { action: "SubmitPackage" },147 isArray: false148 },149 submitReimageSummary: {150 method: "POST",151 params: { action: "SubmitReimageSummary" },152 isArray: false153 },154 isExistReimageSummaryAttachment: {155 method: 'POST',156 params: { action: "IsExistReimageSummaryAttachment" },157 isArray: false158 },159 ////----------GBMemo160 getGBMemoInfo: {161 method: "GET",162 params: { action: "GetGBMemoInfo" },163 isArray: false164 },165 saveGBMemo: {166 method: 'POST',167 params: { action: 'SaveGBMemo' },168 isArray: false169 },170 submitGBMemo: {171 method: 'POST',172 params: { action: 'SubmitGBMemo' },173 isArray: false174 },175 resubmitGBMemo: {176 method: 'POST',177 params: { action: 'ResubmitGBMemo' },178 isArray: false179 },180 approveGBMemo: {181 method: 'POST',182 params: { action: 'ApproveGBMemo' },183 isArray: false184 },185 recallGBMemo: {186 method: 'POST',187 params: { action: 'RecallGBMemo' },188 isArray: false189 },190 editGBMemo: {191 method: 'POST',192 params: { action: 'EditGBMemo' },193 isArray: false194 },195 returnGBMemo: {196 method: 'POST',197 params: { action: 'ReturnGBMemo' },198 isArray: false199 },200 notifyGBMemo: {201 method: 'POST',202 params: { action: 'NotifyGBMemo' },203 isArray: false204 },205 packageList: {206 method: 'POST',207 params: { action: 'PackageList' },208 isArray: false209 },210 releasePackages: {211 method: 'POST',212 params: { action: 'ReleasePackages' },213 isArray: true214 }215 });...
npm-release.js
Source:npm-release.js
...143 }144 if (process.env.CIRCLE_PULL_REQUEST) {145 return console.log(`Release process cannot be run on a PR`)146 }147 await releasePackages(packagesToRelease)148 console.log(`\n\nRelease process completed successfully!`)149}150// execute main function if called from command line151if (require.main === module) {152 main()153}154module.exports = {155 parseSemanticReleaseOutput,156 readPackageJson,...
SelectPackageController.js
Source:SelectPackageController.js
...56 }57 });58 };59 $scope.ok = function () {60 reimageService.releasePackages($scope.selectedItems).$promise.then(function (response) {61 $scope.selectedItems = [];62 $scope.search();63 messager.showMessage("åéæå", "fa-check c_green");64 });65 };66 }...
ViewReleasesController.js
Source:ViewReleasesController.js
1'use strict';2angular.module('MLDS')3 .controller('ViewReleasesController', 4 ['$scope', '$log', 'Session', 'PackageUtilsService', '$location', 'MemberService', 'UserAffiliateService','releasePackagesQueryResult', 'MemberPackageService',5 function ($scope, $log, Session, PackageUtilsService, $location, MemberService, UserAffiliateService, releasePackagesQueryResult, MemberPackageService) {6 $scope.utils = PackageUtilsService;7 $scope.releasePackagesByMember = [];8 $scope.alerts = [];9 10 $scope.isMembershipApproved = UserAffiliateService.isMembershipApproved;11 12 $scope.viewLicense = function (memberKey) {13 MemberService.getMemberLicense(memberKey);14 };15 16 $scope.goToViewPackagePage = function goToViewPackagePage(releasePackageId) {17 $location.path('/viewReleases/viewRelease/'+ releasePackageId);18 };19 20 $scope.releasePackageOrderBy = MemberPackageService.orderByJustName; 21 var releasePackages = releasePackagesQueryResult;22 $scope.releasePackagesByMember = _.chain(releasePackages)23 .filter(PackageUtilsService.isPackagePublished)24 .groupBy(function(value) {return value.member.key;})25 .map(function(packages, memberKey) {26 return {27 member: MemberService.membersByKey[memberKey], 28 packages: PackageUtilsService.releasePackageSort(packages)};})29 .value();30 if(Session.member != null)31 {32 var memberRelease = _.find($scope.releasePackagesByMember, function(item)33 {34 if(Session.member.key != null && Session.member.key != 'undefined' && Session.member.key != "IHTSDO")35 {36 if(item.member.key == Session.member.key)37 {38 return 1;39 }40 }41 else{return 0};42 });43 _.each($scope.releasePackagesByMember, function(item)44 {45 if(item.member.key == "IHTSDO" && memberRelease != null && memberRelease != 'undefined'){46 _.each(memberRelease.packages, function(releasePackage){47 item.packages.push(releasePackage);48 });49 item.packages = PackageUtilsService.releasePackageSort(item.packages);50 }51 });52 }...
ReleasePackageService.js
Source:ReleasePackageService.js
1'use strict';2angular.module('MLDS')3.factory('ReleasePackageService', ['$http', '$log', '$q', '$window', '$location', function($http, $log, $q, $window, $location){4 5 var service = {};6 service.updateReleaseLicense = function(releasePackageId, file) {7 var formData = new FormData();8 formData.append('file', file);9 10 return $http.post('/api/releasePackages/' + encodeURIComponent(releasePackageId) + '/license', formData, {11 transformRequest: angular.identity,12 headers: {'Content-Type': undefined}13 });14 };15 16 service.getReleaseLicense = function(releasePackageId) {17 $window.open('/api/releasePackages/' + encodeURIComponent(releasePackageId) + '/license', '_blank');18 };19 20 return service;21 ...
ReleaseVersionsService.js
Source:ReleaseVersionsService.js
1'use strict';2angular.module('MLDS').factory('ReleaseVersionsService',3 ['$resource',4 function($resource) {5 return $resource(6 'api/releasePackages/:releasePackageId/releaseVersions/:releaseVersionId',7 {8 releasePackageId : '@releasePackageId',9 releaseVersionId : '@releaseVersionId'10 }, {11 update : {12 method : 'PUT'13 },14 notify : {15 method : 'POST',16 url: 'api/releasePackages/:releasePackageId/releaseVersions/:releaseVersionId/notifications'17 }18 });...
release-js.js
Source:release-js.js
1import { packages } from './utils'2import execa from 'execa'3import chalk from "chalk";4async function releasePackages(packages) {5 packages.forEach(pkg => {6 process.chdir(path.resolve(__dirname, '../', pkg))7 console.log('Publishing...', chalk.yellow(process.cwd()))8 execa.sync('npm publish --access public')9 })10}...
Using AI Code Generation
1const cypress = require('cypress');2cypress.run({3 env: {4 }5}).then((results) => {6 console.log(results);7}).catch((err) => {8 console.error(err);9});10describe('Test to use releasePackages method of Cypress', () => {11 it('Should create a package and release it', () => {12 cy.login();13 cy.createPackage();14 cy.releasePackage();15 });16});17Cypress.Commands.add('login', () => {18 cy.get('.login-button').click();19 cy.get('input[name="username"]').type('username');20 cy.get('input[name="password"]').type('password');21 cy.get('button[type="submit"]').click();22});23Cypress.Commands.add('createPackage', () => {24 cy.get('a[href="/packages"]').click();25 cy.get('a[href="/packages/create"]').click();26 cy.get('input[name="name"]').type('test');27 cy.get('input[name="description"]').type('test');28 cy.get('button[type="submit"]').click();29});30Cypress.Commands.add('releasePackage', () => {31 cy.get('a[href="/packages/test"]').click();32 cy.get('a[href="/packages/test/settings"]').click();33 cy.get('a[href="/packages/test/settings/release"]').click();34 cy.get('button[type="submit"]').click();35});36import './commands';37Cypress.on('window:before:load', (win) => {38 delete win.fetch;39});40Cypress.on('uncaught:exception', (err, runnable) => {41 return false;42});
Using AI Code Generation
1const cypress = require('cypress')2cypress.run({3 reporterOptions: {4 }5}).then((results) => {6 console.log(results)7 cypress.releasePackages()8})9{ video: true,10 env: {},11 browsers: [ { name: 'chrome', family: 'chromium', channel: 'stable' } ],12 { video: true,13 env: {},14 execPath: '/var/lib/jenkins/workspace/MyProject/node_modules/electron/dist/electron' },15 'v8.11.1' }16{ totalFailed: 0,
Using AI Code Generation
1var packages = require('cypress/packages');2packages.releasePackages();3var packages = require('cypress/packages');4packages.releasePackages();5var packages = require('cypress/packages');6packages.releasePackages();7var packages = require('cypress/packages');8packages.releasePackages();9var packages = require('cypress/packages');10packages.releasePackages();11var packages = require('cypress/packages');12packages.releasePackages();13var packages = require('cypress/packages');14packages.releasePackages();15var packages = require('cypress/packages');16packages.releasePackages();17var packages = require('cypress/packages');18packages.releasePackages();19var packages = require('cypress/packages');20packages.releasePackages();
Using AI Code Generation
1const fs = require('fs');2const path = require('path');3const cypress = require('cypress');4const { getDependencyTree } = require('get-dependency-tree');5const specFiles = fs.readdirSync('cypress/integration').map((file) => {6 return path.join('cypress/integration', file);7});8const dependencies = getDependencyTree(specFiles);9cypress.run({10 config: {11 },12}).then((results) => {13 console.log(results);14 process.exit(results.totalFailed);15});
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!!