From 334d09a1d3155700a498303474328d3338a9f446 Mon Sep 17 00:00:00 2001 From: Trevor Nelms Date: Wed, 9 Aug 2023 10:29:51 -0600 Subject: [PATCH] SBVT-1779: Better error message if no Cypress module installed (#146) * SBVT-1787: updating the dom upload put to work within vt website * SBVT-1779: adding error handling to when cypress not installed * SBVT-1779: reformatting * SBVT-1779: pino update --------- Co-authored-by: trevor.nelms --- bin/setup.js | 50 +++++++++++++++--------- package-lock.json | 12 +++--- package.json | 2 +- test/package-lock.json | 86 ++++++++++++++++++++++++++++-------------- test/package.json | 2 +- 5 files changed, 98 insertions(+), 54 deletions(-) diff --git a/bin/setup.js b/bin/setup.js index 515ffea..39bdc28 100755 --- a/bin/setup.js +++ b/bin/setup.js @@ -9,22 +9,36 @@ const pluginRequire = `\nrequire('@smartbear/visualtest-cypress')(module)`; const commandsImport = `\nimport '@smartbear/visualtest-cypress/commands'`; const vtConfContent = `module.exports = {\n\tprojectToken: 'PROJECT_TOKEN',\n}`; // const jsonData = `"chromeWebSecurity": false`; -//TODO add try catch -const packageFile = fs.readFileSync(path.resolve(path.dirname(require.resolve('cypress', {paths: [cwd]})), 'package.json')); -const usersCypress = JSON.parse(packageFile.toString()); let error = false; +const usersCypressVersion = (() => { + let packageFile, usersCypress; + try { + packageFile = fs.readFileSync(path.resolve(path.dirname(require.resolve('cypress', {paths: [cwd]})), 'package.json')); + usersCypress = JSON.parse(packageFile.toString()); + } catch (err) { + error = true; + console.log(chalk.bold.yellow('\nCypress not found, please run: ')); + console.log(chalk.magenta.underline(`npm install cypress\nnpx cypress open`)); + console.log((`Go through the Cypress setup wizard`)); + process.stdout.write(chalk.yellow(`Then, run: `)); + process.stdout.write(chalk.magenta.underline(`npx visualtest-setup`)); + console.log(chalk.yellow(` again.\n`)); + } + return usersCypress; +})(); + let cypressVersionAbove10; //boolean true if above version 10 let checkCypressVersion = () => { //checks if the user's version is supported, and if it above or below Cypress version 10 (due to different naming conventions) - if (usersCypress.version.split('.')[0] < 7 || usersCypress.version.split('.')[0] <= 7 && usersCypress.version.split('.')[1] < 4) { + if (usersCypressVersion.version.split('.')[0] < 7 || usersCypressVersion.version.split('.')[0] <= 7 && usersCypressVersion.version.split('.')[1] < 4) { // Note as of now this is not supported because cy.request cannot send blobs in previous versions - console.log(chalk.redBright(`Detected Cypress ${usersCypress.version}`)); + console.log(chalk.redBright(`Detected Cypress ${usersCypressVersion.version}`)); console.log(chalk.green(`Only Cypress 7.4.0+ is supported`)); error = true; } - cypressVersionAbove10 = usersCypress.version.split('.')[0] >= 10; - checkForTypeScript(cypressVersionAbove10) + cypressVersionAbove10 = usersCypressVersion.version.split('.')[0] >= 10; + checkForTypeScript(cypressVersionAbove10); /** if we decide to support older versions commenting out for now @@ -63,21 +77,21 @@ let fileExtension; // this for either '.js' or '.ts' const checkForTypeScript = (version10) => { try { try { - fs.readFileSync(version10 ? `${process.cwd()}/cypress/support/e2e.js` : `${process.cwd()}/cypress/support/index.js`, 'utf-8') - fileExtension = ".js" + fs.readFileSync(version10 ? `${process.cwd()}/cypress/support/e2e.js` : `${process.cwd()}/cypress/support/index.js`, 'utf-8'); + fileExtension = ".js"; } catch (error) { - fs.readFileSync(version10 ? `${process.cwd()}/cypress/support/e2e.ts` : `${process.cwd()}/cypress/support/index.ts`, 'utf-8') - fileExtension = ".ts" + fs.readFileSync(version10 ? `${process.cwd()}/cypress/support/e2e.ts` : `${process.cwd()}/cypress/support/index.ts`, 'utf-8'); + fileExtension = ".ts"; console.log(chalk.yellow('TypeScript detected - this currently in beta.')); } } catch (error) { //TODO look into logging later // logger.debug('Issue with finding file extension, defaulting to ".js".') // logger.debug('Most likely the Cypress project is not set up yet') - fileExtension = ".js" + fileExtension = ".js"; // error handled later } -} +}; let setupVTConf = () => { const filePath = `${process.cwd()}/visualTest.config.js`; @@ -109,7 +123,7 @@ let setupVTConf = () => { }; let setupCommands = () => { - let aboveVersion10 = usersCypress.version.split('.')[0] >= 10; + let aboveVersion10 = usersCypressVersion.version.split('.')[0] >= 10; const supportPath = aboveVersion10 ? `${process.cwd()}/cypress/support/e2e` : `${process.cwd()}/cypress/support/index`; let fileContent; @@ -134,7 +148,7 @@ let setupCommands = () => { } }; let setupPlugin = () => { - let aboveVersion10 = usersCypress.version.split('.')[0] >= 10; + let aboveVersion10 = usersCypressVersion.version.split('.')[0] >= 10; const supportPath = aboveVersion10 ? path.resolve(process.cwd(), 'cypress.config') : `${process.cwd()}/cypress/plugins/index`; let fileContent; @@ -165,7 +179,7 @@ const setupTypeScriptIndexFile = () => { let fileContent; try { - fileContent = fs.readFileSync(filePath, 'utf-8'); + fileContent = fs.readFileSync(filePath, 'utf-8'); } catch (err) { // okay if this file was not found } @@ -178,9 +192,9 @@ const setupTypeScriptIndexFile = () => { process.stdout.write(chalk.green(`TypeScript import statement added.`)); console.log(chalk.dim(`\t Filepath: cypress/support/index.d.ts`)); } -} +}; -checkCypressVersion(); +if (!error) checkCypressVersion(); if (!error) setupCommands(); if (!error) setupPlugin(); if (!error && fileExtension === '.ts') setupTypeScriptIndexFile(); diff --git a/package-lock.json b/package-lock.json index 0b34df0..754bfbb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@smartbear/visualtest-cypress", - "version": "1.7.7", + "version": "1.7.8", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@smartbear/visualtest-cypress", - "version": "1.7.7", + "version": "1.7.8", "license": "ISC", "dependencies": { "axios": "^1.4.0", @@ -14,7 +14,7 @@ "dotenv": "^16.3.1", "fs-extra": "^11.1.1", "jimp": "^0.22.10", - "pino": "^8.14.2", + "pino": "^8.15.0", "pino-pretty": "^10.2.0", "uuid": "^9.0.0" }, @@ -1050,9 +1050,9 @@ "integrity": "sha512-CzFr90qM24ju5f88quFC/6qohjC144rehe5n6DH900lgXmUe86+xCKc10ev56gRKC4/BkHUoG4uSiQgBiIXwDA==" }, "node_modules/pino": { - "version": "8.14.2", - "resolved": "https://registry.npmjs.org/pino/-/pino-8.14.2.tgz", - "integrity": "sha512-zKu9aWeSWTy1JgvxIpZveJKKsAr4+6uNMZ0Vf0KRwzl/UNZA3XjHiIl/0WwqLMkDwuHuDkT5xAgPA2jpKq4whA==", + "version": "8.15.0", + "resolved": "https://registry.npmjs.org/pino/-/pino-8.15.0.tgz", + "integrity": "sha512-olUADJByk4twxccmAxb1RiGKOSvddHugCV3wkqjyv+3Sooa2KLrmXrKEWOKi0XPCLasRR5jBXxioE1jxUa4KzQ==", "dependencies": { "atomic-sleep": "^1.0.0", "fast-redact": "^3.1.1", diff --git a/package.json b/package.json index 80b1eed..f4d512b 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "dotenv": "^16.3.1", "fs-extra": "^11.1.1", "jimp": "^0.22.10", - "pino": "^8.14.2", + "pino": "^8.15.0", "pino-pretty": "^10.2.0", "uuid": "^9.0.0" }, diff --git a/test/package-lock.json b/test/package-lock.json index f8e950b..08534b4 100644 --- a/test/package-lock.json +++ b/test/package-lock.json @@ -10,7 +10,7 @@ "license": "ISC", "dependencies": { "@smartbear/visualtest-cypress": "file:..", - "cypress": "^12.17.1", + "cypress": "^12.17.3", "mochawesome": "^7.1.3", "mochawesome-merge": "^4.3.0" } @@ -43,9 +43,9 @@ } }, "node_modules/@cypress/request": { - "version": "2.88.11", - "resolved": "https://registry.npmjs.org/@cypress/request/-/request-2.88.11.tgz", - "integrity": "sha512-M83/wfQ1EkspjkE2lNWNV5ui2Cv7UCv1swW1DqljahbzLVWltcsexQh8jYtuS/vzFXP+HySntGM83ZXA9fn17w==", + "version": "2.88.12", + "resolved": "https://registry.npmjs.org/@cypress/request/-/request-2.88.12.tgz", + "integrity": "sha512-tOn+0mDZxASFM+cuAP9szGUGPI1HwWVSvdzm7V4cCsPdFTx6qMj29CwaQmRAMIEhORIUBFBsYROYJcveK4uOjA==", "dependencies": { "aws-sign2": "~0.7.0", "aws4": "^1.8.0", @@ -62,7 +62,7 @@ "performance-now": "^2.1.0", "qs": "~6.10.3", "safe-buffer": "^5.1.2", - "tough-cookie": "~2.5.0", + "tough-cookie": "^4.1.3", "tunnel-agent": "^0.6.0", "uuid": "^8.3.2" }, @@ -92,9 +92,9 @@ "link": true }, "node_modules/@types/node": { - "version": "14.18.53", - "resolved": "https://registry.npmjs.org/@types/node/-/node-14.18.53.tgz", - "integrity": "sha512-soGmOpVBUq+gaBMwom1M+krC/NNbWlosh4AtGA03SyWNDiqSKtwp7OulO1M6+mg8YkHMvJ/y0AkCeO8d1hNb7A==" + "version": "16.18.40", + "resolved": "https://registry.npmjs.org/@types/node/-/node-16.18.40.tgz", + "integrity": "sha512-+yno3ItTEwGxXiS/75Q/aHaa5srkpnJaH+kdkTVJ3DtJEwv92itpKbxU+FjPoh2m/5G9zmUQfrL4A4C13c+iGA==" }, "node_modules/@types/sinonjs__fake-timers": { "version": "8.1.1", @@ -374,9 +374,9 @@ } }, "node_modules/cachedir": { - "version": "2.3.0", - "resolved": "https://registry.npmjs.org/cachedir/-/cachedir-2.3.0.tgz", - "integrity": "sha512-A+Fezp4zxnit6FanDmv9EqXNAi3vt9DWp51/71UEhXukb7QUuvtv9344h91dyAxuTLoSYJFU299qzR3tzwPAhw==", + "version": "2.4.0", + "resolved": "https://registry.npmjs.org/cachedir/-/cachedir-2.4.0.tgz", + "integrity": "sha512-9EtFOZR8g22CL7BWjJ9BUx1+A/djkofnyW3aOXZORNW2kxoUpx2h+uN2cOqwPmFhnpVmxg+KW2OjOSgChTEvsQ==", "engines": { "node": ">=6" } @@ -616,14 +616,14 @@ } }, "node_modules/cypress": { - "version": "12.17.1", - "resolved": "https://registry.npmjs.org/cypress/-/cypress-12.17.1.tgz", - "integrity": "sha512-eKfBgO6t8waEyhegL4gxD7tcI6uTCGttu+ZU7y9Hq8BlpMztd7iLeIF4AJFAnbZH1xjX+wwgg4cRKFNSvv3VWQ==", + "version": "12.17.3", + "resolved": "https://registry.npmjs.org/cypress/-/cypress-12.17.3.tgz", + "integrity": "sha512-/R4+xdIDjUSLYkiQfwJd630S81KIgicmQOLXotFxVXkl+eTeVO+3bHXxdi5KBh/OgC33HWN33kHX+0tQR/ZWpg==", "hasInstallScript": true, "dependencies": { "@cypress/request": "^2.88.11", "@cypress/xvfb": "^1.2.4", - "@types/node": "^14.14.31", + "@types/node": "^16.18.39", "@types/sinonjs__fake-timers": "8.1.1", "@types/sizzle": "^2.3.2", "arch": "^2.2.0", @@ -762,11 +762,12 @@ } }, "node_modules/enquirer": { - "version": "2.3.6", - "resolved": "https://registry.npmjs.org/enquirer/-/enquirer-2.3.6.tgz", - "integrity": "sha512-yjNnPr315/FjS4zIsUxYguYUPP2e1NK4d7E7ZOLiyYCcbFBiTMyID+2wvm2w6+pZ/odMA7cRkjhsPbltwBOrLg==", + "version": "2.4.1", + "resolved": "https://registry.npmjs.org/enquirer/-/enquirer-2.4.1.tgz", + "integrity": "sha512-rRqJg/6gd538VHvR3PSrdRBb/1Vy2YfzHqzvbhGIQpDRKIa4FgV/54b5Q1xYSxOOwKvjXweS26E0Q+nAMwp2pQ==", "dependencies": { - "ansi-colors": "^4.1.1" + "ansi-colors": "^4.1.1", + "strip-ansi": "^6.0.1" }, "engines": { "node": ">=8.6" @@ -2215,6 +2216,11 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/querystringify": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/querystringify/-/querystringify-2.2.0.tgz", + "integrity": "sha512-FIqgj2EUvTa7R50u0rGsyTftzjYmv/a3hO345bZNrqabNqjtgiDMgmo4mkUjd+nzU5oF3dClKqFIPUKybUyqoQ==" + }, "node_modules/randombytes": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/randombytes/-/randombytes-2.1.0.tgz", @@ -2262,6 +2268,11 @@ "resolved": "https://registry.npmjs.org/require-main-filename/-/require-main-filename-2.0.0.tgz", "integrity": "sha512-NKN5kMDylKuldxYLSUfrbo5Tuzh4hd+2E8NPPX02mZtn1VuREQToYe/ZdlJy+J3uCpfaiGF05e7B8W0iXbQHmg==" }, + "node_modules/requires-port": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/requires-port/-/requires-port-1.0.0.tgz", + "integrity": "sha512-KigOCHcocU3XODJxsu8i/j8T9tzT4adHiecwORRQ0ZZFcp7ahwXuRU1m+yuO90C5ZUyGeGfocHDI14M3L3yDAQ==" + }, "node_modules/restore-cursor": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/restore-cursor/-/restore-cursor-3.1.0.tgz", @@ -2532,21 +2543,31 @@ } }, "node_modules/tough-cookie": { - "version": "2.5.0", - "resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-2.5.0.tgz", - "integrity": "sha512-nlLsUzgm1kfLXSXfRZMc1KLAugd4hqJHDTvc2hDIwS3mZAfMEuMbc03SujMF+GEcpaX/qboeycw6iO8JwVv2+g==", + "version": "4.1.3", + "resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-4.1.3.tgz", + "integrity": "sha512-aX/y5pVRkfRnfmuX+OdbSdXvPe6ieKX/G2s7e98f4poJHnqH3281gDPm/metm6E/WRamfx7WC4HUqkWHfQHprw==", "dependencies": { - "psl": "^1.1.28", - "punycode": "^2.1.1" + "psl": "^1.1.33", + "punycode": "^2.1.1", + "universalify": "^0.2.0", + "url-parse": "^1.5.3" }, "engines": { - "node": ">=0.8" + "node": ">=6" + } + }, + "node_modules/tough-cookie/node_modules/universalify": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/universalify/-/universalify-0.2.0.tgz", + "integrity": "sha512-CJ1QgKmNg3CwvAv/kOFmtnEN05f0D/cn9QntgNOQlQF9dgvVTHj3t+8JPdjqawCHk7V/KA+fbUqzZ9XWhcqPUg==", + "engines": { + "node": ">= 4.0.0" } }, "node_modules/tslib": { - "version": "2.6.0", - "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.6.0.tgz", - "integrity": "sha512-7At1WUettjcSRHXCyYtTselblcHl9PJFFVKiCAy/bY97+BPZXSQ2wbq0P9s8tK2G7dFQfNnlJnPAiArVBVBsfA==" + "version": "2.6.1", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.6.1.tgz", + "integrity": "sha512-t0hLfiEKfMUoqhG+U1oid7Pva4bbDPHYfJNiB7BiIjRkj1pyC++4N3huJfqY6aRH6VTB0rvtzQwjM4K6qpfOig==" }, "node_modules/tunnel-agent": { "version": "0.6.0", @@ -2591,6 +2612,15 @@ "node": ">=8" } }, + "node_modules/url-parse": { + "version": "1.5.10", + "resolved": "https://registry.npmjs.org/url-parse/-/url-parse-1.5.10.tgz", + "integrity": "sha512-WypcfiRhfeUP9vvF0j6rw0J3hrWrw6iZv3+22h6iRMJ/8z1Tj6XfLP4DsUix5MhMPnXpiHDoKyoZ/bdCkwBCiQ==", + "dependencies": { + "querystringify": "^2.1.1", + "requires-port": "^1.0.0" + } + }, "node_modules/uuid": { "version": "8.3.2", "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz", diff --git a/test/package.json b/test/package.json index 56ef8a0..b018134 100644 --- a/test/package.json +++ b/test/package.json @@ -12,7 +12,7 @@ "license": "ISC", "dependencies": { "@smartbear/visualtest-cypress": "file:..", - "cypress": "^12.17.1", + "cypress": "^12.17.3", "mochawesome": "^7.1.3", "mochawesome-merge": "^4.3.0" }