Best JavaScript code snippet using cypress
parse-env.js
Source:parse-env.js
1/* global describe, it */2process.env.NODE_ENV = 'test'3// test related packages4const expect = require('chai').expect5const parseEnv = require('../lib/parse-env.js')6describe('Environment variables', () => {7 describe('valETHAddress', () => {8 it('should throw error when empty', done => {9 expect(() => {10 parseEnv.valETHAddress('')11 }).to.throw('The Ethereum address is invalid')12 done()13 })14 it('should throw error when null', done => {15 expect(() => {16 parseEnv.valETHAddress(null)17 }).to.throw('The Ethereum address is invalid')18 done()19 })20 it('should throw error when not hex', done => {21 expect(() => {22 parseEnv.valETHAddress('not hex')23 }).to.throw('The Ethereum address is invalid')24 done()25 })26 it('should throw error when too short', done => {27 expect(() => {28 parseEnv.valETHAddress('0x32Be343B94f860124dC4')29 }).to.throw('The Ethereum address is invalid')30 done()31 })32 it('should throw error when too long', done => {33 expect(() => {34 parseEnv.valETHAddress('0x32Be343B94f860124dC4fEe278FDCBD38C102D8832Be343B94f860124dC4fEe278FDCBD38C102D88')35 }).to.throw('The Ethereum address is invalid')36 done()37 })38 it('should throw error when missing 0x prefix', done => {39 expect(() => {40 parseEnv.valETHAddress('32Be343B94f860124dC4fEe278FDCBD38C102D88')41 }).to.throw('The Ethereum address is invalid')42 done()43 })44 it('should return lowercased when valid', done => {45 let result = parseEnv.valETHAddress('0x32Be343B94f860124dC4fEe278FDCBD38C102D88')46 expect(result).to.equal('0x32be343b94f860124dc4fee278fdcbd38c102d88')47 done()48 })49 })50 describe('valNodeUIPassword', () => {51 it('should allow and return empty string', done => {52 let result = parseEnv.valNodeUIPassword('')53 expect(result).to.equal('')54 done()55 })56 it('should throw error when not alpha-numeric', done => {57 expect(() => {58 parseEnv.valNodeUIPassword('bad_password')59 }).to.throw('The CHAINPOINT_NODE_UI_PASSWORD is invalid')60 done()61 })62 it('should return password when valid', done => {63 let pw = 'goodpw1234'64 let result = parseEnv.valNodeUIPassword(pw)65 expect(result).to.equal(pw)66 done()67 })68 })69 describe('valCoreIPList', () => {70 it('should return success with empty string', done => {71 let result = parseEnv.valCoreIPList('')72 expect(result).to.equal('')73 done()74 })75 it('should throw error with bad single IP', done => {76 expect(() => {77 parseEnv.valCoreIPList('234234.234234.234234.23434')78 }).to.throw('The Core IP list is invalid')79 done()80 })81 it('should return true with valid v4 IP', done => {82 let result = parseEnv.valCoreIPList('65.1.1.1')83 expect(result).to.deep.equal(['65.1.1.1'])84 done()85 })86 it('should return success with valid v6 IP', done => {87 let result = parseEnv.valCoreIPList('FE80:0000:0000:0000:0202:B3FF:FE1E:8329')88 expect(result).to.deep.equal(['FE80:0000:0000:0000:0202:B3FF:FE1E:8329'])89 done()90 })91 it('should return success with valid collapsed v6 IP', done => {92 let result = parseEnv.valCoreIPList('FE80::0202:B3FF:FE1E:8329')93 expect(result).to.deep.equal(['FE80::0202:B3FF:FE1E:8329'])94 done()95 })96 it('should return success with hybrid v6 IP', done => {97 let result = parseEnv.valCoreIPList('::ffff:65.1.1.1')98 expect(result).to.deep.equal(['::ffff:65.1.1.1'])99 done()100 })101 it('should throw error with bad IP in group', done => {102 expect(() => {103 parseEnv.valCoreIPList('65.1.1.1,10.165.32.31,234234.234234.234234.23434')104 }).to.throw('The Core IP list is invalid')105 done()106 })107 it('should throw error with missing IP in group', done => {108 expect(() => {109 parseEnv.valCoreIPList('65.1.1.1,,10.165.32.31')110 }).to.throw('The Core IP list is invalid')111 done()112 })113 it('should throw error with duplicate IP in group', done => {114 expect(() => {115 parseEnv.valCoreIPList('65.1.1.1,65.1.1.1,10.165.32.31')116 }).to.throw('The Core IPs cannot contain duplicates')117 done()118 })119 it('should return success with valid IP list', done => {120 let result = parseEnv.valCoreIPList('65.1.1.1,FE80::0202:B3FF:FE1E:8329,10.165.32.31')121 expect(result).to.deep.equal(['65.1.1.1', 'FE80::0202:B3FF:FE1E:8329', '10.165.32.31'])122 done()123 })124 })125 describe('valAutoAcquire', () => {126 it('should throw error with number', done => {127 expect(() => {128 parseEnv.valAutoAcquire(0)129 }).to.throw('The AUTO_REFILL_ENABLED value is invalid')130 done()131 })132 it('should throw error with not true/false string', done => {133 expect(() => {134 parseEnv.valAutoAcquire('maybe')135 }).to.throw('The AUTO_REFILL_ENABLED value is invalid')136 done()137 })138 it('should return true on TRUE', done => {139 let result = parseEnv.valAutoAcquire('TRUE')140 expect(result).to.equal(true)141 done()142 })143 it('should return true on true', done => {144 let result = parseEnv.valAutoAcquire('true')145 expect(result).to.equal(true)146 done()147 })148 it('should return false on FALSE', done => {149 let result = parseEnv.valAutoAcquire('FALSE')150 expect(result).to.equal(false)151 done()152 })153 it('should return false on False', done => {154 let result = parseEnv.valAutoAcquire('False')155 expect(result).to.equal(false)156 done()157 })158 })159 describe('valNetwork', () => {160 it('should throw error with number', done => {161 expect(() => {162 parseEnv.valNetwork(234)163 }).to.throw('The NETWORK value is invalid')164 done()165 })166 it('should throw error with boolean', done => {167 expect(() => {168 parseEnv.valNetwork(true)169 }).to.throw('The NETWORK value is invalid')170 done()171 })172 it('should return mainnet on empty', done => {173 let result = parseEnv.valNetwork('')174 expect(result).to.equal('mainnet')175 done()176 })177 it('should return mainnet on mainnet', done => {178 let result = parseEnv.valNetwork('mainnet')179 expect(result).to.equal('mainnet')180 done()181 })182 it('should return testnet on testnet', done => {183 let result = parseEnv.valNetwork('testnet')184 expect(result).to.equal('testnet')185 done()186 })187 })188 describe('valPrivateNetwork', () => {189 it('should throw error with number', done => {190 expect(() => {191 parseEnv.valPrivateNetwork(234)192 }).to.throw('The PRIVATE_NETWORK value is invalid')193 done()194 })195 it('should throw error with not true/false string', done => {196 expect(() => {197 parseEnv.valPrivateNetwork('maybe')198 }).to.throw('The PRIVATE_NETWORK value is invalid')199 done()200 })201 it('should return true on TRUE', done => {202 let result = parseEnv.valPrivateNetwork('TRUE')203 expect(result).to.equal(true)204 done()205 })206 it('should return true on true', done => {207 let result = parseEnv.valPrivateNetwork('true')208 expect(result).to.equal(true)209 done()210 })211 it('should return false on FALSE', done => {212 let result = parseEnv.valPrivateNetwork('FALSE')213 expect(result).to.equal(false)214 done()215 })216 it('should return false on False', done => {217 let result = parseEnv.valPrivateNetwork('False')218 expect(result).to.equal(false)219 done()220 })221 })...
defaults.js
Source:defaults.js
...27const { parseEnv } = require("../app/lib/env");28module.exports = {29 nearest: {30 radius: {31 DEFAULT: parseEnv(NEAREST_RADIUS_DEFAULT, 100),32 MAX: parseEnv(NEAREST_RADIUS_MAX, 2000),33 },34 limit: {35 DEFAULT: parseEnv(NEAREST_LIMIT_DEFAULT, 10),36 MAX: parseEnv(NEAREST_LIMIT_MAX, 100),37 },38 },39 search: {40 limit: {41 DEFAULT: parseEnv(SEARCH_LIMIT_DEFAULT, 10),42 MAX: parseEnv(SEARCH_LIMIT_MAX, 100),43 },44 },45 bulkGeocode: {46 geolocations: {47 MAX: parseEnv(BULKGEOCODE_GEOLOCATIONS_MAX, 100), // Maximum number of geolocations per request48 ASYNC_LIMIT: parseEnv(BULKGEOCODE_GEOLOCATIONS_ASYNC_LIMIT, null), // Maximum number of parallel DB queries per request49 TIMEOUT: parseEnv(BULKGEOCODE_GEOLOCATIONS_TIMEOUT, 30000), // Maximum interval to run a single bulk request50 },51 },52 bulkLookups: {53 postcodes: {54 MAX: parseEnv(BULKLOOKUPS_POSTCODES_MAX, 100), // Maximum number of postcodes per request55 ASYNC_LIMIT: parseEnv(BULKLOOKUPS_POSTCODES_ASYNC_LIMIT, null), // Maximum number of parallel DB queries per request56 TIMEOUT: parseEnv(BULKLOOKUPS_POSTCODES_TIMEOUT, 30000), // Maximum interval to run a single bulk request57 },58 },59 nearestOutcodes: {60 radius: {61 DEFAULT: parseEnv(NEARESTOUTCODES_RADIUS_DEFAULT, 5000),62 MAX: parseEnv(NEARESTOUTCODES_RADIUS_MAX, 25000),63 },64 limit: {65 DEFAULT: parseEnv(NEARESTOUTCODES_LIMIT_DEFAULT, 10),66 MAX: parseEnv(NEARESTOUTCODES_LIMIT_MAX, 100),67 },68 },69 placesSearch: {70 limit: {71 DEFAULT: parseEnv(PLACESSEARCH_LIMIT_DEFAULT, 10),72 MAX: parseEnv(PLACESSEARCH_LIMIT_MAX, 100),73 },74 },75 placesContained: {76 limit: {77 DEFAULT: parseEnv(PLACESCONTAINED_LIMIT_DEFAULT, 10),78 MAX: parseEnv(PLACESCONTAINED_LIMIT_MAX, 100),79 },80 },81 placesNearest: {82 limit: {83 DEFAULT: parseEnv(PLACESNEAREST_LIMIT_DEFAULT, 10),84 MAX: parseEnv(PLACESNEAREST_LIMIT_MAX, 100),85 },86 radius: {87 DEFAULT: parseEnv(PLACESNEAREST_RADIUS_DEFAULT, 1000),88 MAX: parseEnv(PLACESNEAREST_RADIUS_MAX, 10000),89 },90 },91 filterableAttributes: [92 "postcode",93 "quality",94 "eastings",95 "northings",96 "country",97 "nhs_ha",98 "longitude",99 "latitude",100 "parliamentary_constituency",101 "european_electoral_region",102 "primary_care_trust",...
archetype.js
Source:archetype.js
...26 }27};28const optionsSpec = {};29const webpackConfigSpec = {30 devHostname: parseEnv("WEBPACK_DEV_HOST", "localhost"),31 devPort: parseEnv("WEBPACK_DEV_PORT", 3000, "number"),32 cdnProtocol: parseEnv("WEBPACK_DEV_CDN_PROTOCOL", null),33 cdnHostname: parseEnv("WEBPACK_DEV_CDN_HOST", null),34 cdnPort: parseEnv("WEBPACK_DEV_CDN_PORT", 0, "number"),35 https: parseEnv("WEBPACK_DEV_HTTPS", false, "boolean"),36 cssModuleSupport: parseEnv("CSS_MODULE_SUPPORT", true, "boolean"),37 enableBabelPolyfill: parseEnv("ENABLE_BABEL_POLYFILL", false, "boolean"),38 enableHotModuleReload: parseEnv("ENABLE_HOT_MODULE_RELOAD", true, "boolean"),39 enableNodeSourcePlugin: parseEnv("ENABLE_NODESOURCE_PLUGIN", false, "boolean"),40 woffFontInlineLimit: parseEnv("WODD_FONT_INLINE_LIMIT", 1000, "number"),41 enableShortenCSSNames: parseEnv("ENABLE_SHORTEN_CSS_NAMES", false, "boolean"),42 enableWarningsOverlay: parseEnv("WEBPACK_DEV_WARNINGS_OVERLAY", true, "boolean"),43 optimizeCSSOptions: parseEnv("OPTIMIZE_CSS_OPTIONS", defaultOptimizeCssOptions, "json"),44 htmlWebpackPluginOptions: parseEnv(45 "HTML_WEBPACK_PLUGIN_OPTIONS",46 defaultHtmlWebpackPluginOptions,47 "json"48 ),49 preserveSymlinks: parseEnv("WEBPACK_PRESERVE_SYMLINKS", false, "boolean"),50 minify: parseEnv("WEBPACK_MINIFY", true, "boolean")51};52const babelConfigSpec = {53 enableTypeScript: parseEnv("ENABLE_TYPESCRIPT", false, "boolean"),54 enableDynamicImport: parseEnv("ENABLE_DYNAMIC_IMPORT", true, "boolean"),55 enableFlow: { env: "ENABLE_BABEL_FLOW", default: true },56 // require the @flow directive in source to enable FlowJS type stripping57 flowRequireDirective: parseEnv("FLOW_REQUIRE_DIRECTIVE", false, "boolean"),58 proposalDecorators: parseEnv("BABEL_PROPOSAL_DECORATORS", false, "boolean"),59 legacyDecorators: parseEnv("BABEL_LEGACY_DECORATORS", true, "boolean"),60 transformClassProps: parseEnv("BABEL_CLASS_PROPS", false, "boolean"),61 looseClassProps: parseEnv("BABEL_CLASS_PROPS_LOOSE", true, "boolean"),62 envTargets: parseEnv(63 "BABEL_ENV_TARGETS",64 {65 default: {66 ie: 867 },68 node: process.versions.node.split(".")[0]69 },70 "json"71 ),72 target: parseEnv("ENV_TARGET", "default")73};74module.exports = {75 webpack: merge({}, webpackConfigSpec, userConfig.webpack),76 babel: merge({}, babelConfigSpec, userConfig.babel),77 options: merge({}, optionsSpec, userConfig.options),78 AppMode,79 dir80};81module.exports.babel.hasMultiTargets =82 Object.keys(module.exports.babel.envTargets)83 .sort()...
index.js
Source:index.js
...26 // use as few iterations as possible for speed.27 min: env === 'test' ? 1 : 1028});29exports.database = {30 name: parseEnv('DB_NAME', { default: 'smapshot' }),31 host: parseEnv('DB_HOST', { default: 'localhost' }),32 port: parseEnvPort('DB_PORT', { default: 5432 }),33 username: parseEnv('DB_USER', { default: 'smapshot' }),34 password: parseEnv('DB_PASS', { required: false }),35 postgresPassword: parseEnv('POSTGRES_PASSWORD', { required: false })36};37exports.env = env;38exports.facebookAuth = {39 appId: parseEnv('AUTH_FACEBOOK_APP_ID', { required: false }),40 appSecret: parseEnv('AUTH_FACEBOOK_APP_SECRET', { required: false })41};42exports.googleAuth = {43 clientId: parseEnv('AUTH_GOOGLE_CLIENT_ID', { required: false }),44 clientSecret: parseEnv('AUTH_GOOGLE_CLIENT_SECRET', { required: false })45}46exports.jwtSecret = parseEnv('JWT_SECRET');47exports.port = port;48exports.generatedDir = generatedDir;49exports.root = root;50// Return URLs allowed when registering or requesting a new password. This51// defaults to the same base URL as the API (assuming all components are behind52// a reverse proxy), but can be customized if necessary.53const returnUrlsString = parseEnv('RETURN_URLS', { required: false }) || toBaseUrl(apiUrl);54exports.returnUrls = returnUrlsString.split(',');55exports.smtp = {56 from: parseEnvEmail('MAIL_FROM'),57 host: parseEnv('MAIL_HOST'),58 port: parseEnvPort('MAIL_PORT', { default: 587 }),59 secure: parseEnvBoolean('MAIL_SECURE', { default: true }),60 username: parseEnv('MAIL_USER', { required: false }),61 password: parseEnv('MAIL_PASS', { required: false }),62 allowInvalidCertificate: parseEnvBoolean('MAIL_ALLOW_INVALID_CERTIFICATE', { default: false })63};64exports.proxyGeoreferencerMode = parseEnvBoolean('PROXY_GEOREFERENCER_MODE', { required: false });...
test.js
Source:test.js
...46 t.equal(result.length,3)47 t.end()48 })49 t.test('ParseEnv',t=>{50 const parse = parser.parseEnv({51 'a':'1',52 'b':'string',53 'c':'1,2,3',54 'd.e.f.g':'0',55 'e':'a,1',56 '0':'ok',57 })58 t.equal(parse.a,1)59 t.equal(parse.b,'string')60 t.deepEqual(parse.c,[1,2,3])61 t.equal(parse.d.e.f.g,0)62 t.equal(parse[0],'ok')63 t.deepEqual(parse.e,['a',1])64 t.end()65 })66 })67 t.test('parseEnv',t=>{68 const parse = parseEnv({69 'a':'1',70 'b':'string',71 'c':'1,2,3',72 'd.e.f.g':'0',73 'e':'a,1',74 '0':'ok',75 })76 t.equal(parse.a,1)77 t.equal(parse.b,'string')78 t.deepEqual(parse.c,[1,2,3])79 t.equal(parse.d.e.f.g,0)80 t.equal(parse[0],'ok')81 t.deepEqual(parse.e,['a',1])82 t.end()...
parse-env.test.js
Source:parse-env.test.js
...5 airtableBaseId: 'YourBaseId',6 port: 3000,7 };8 it('returns the default config when only API Key and Base ID are set', () => {9 const config = parseEnv({10 AIRTABLE_API_KEY: 'YourApiKey',11 AIRTABLE_BASE_ID: 'YourBaseId',12 });13 expect(config).not.toBeNull();14 expect(config).toEqual(defaultConfig);15 });16 it('throws an error when no env variables set', () => {17 expect(() => {18 parseEnv({});19 }).toThrow(/Please provide AIRTABLE_BASE_ID and AIRTABLE_API_KEY/i);20 });21 it('returns the correct config when env variables are set', () => {22 const expectedConfig = {23 allowedMethods: ['GET', 'POST', 'DELETE'],24 airtableApiKey: 'YourApiKey',25 airtableBaseId: 'YourBaseId',26 port: 3001,27 };28 const config = parseEnv({29 ALLOWED_METHODS: 'GET,POST,DELETE',30 AIRTABLE_API_KEY: 'YourApiKey',31 AIRTABLE_BASE_ID: 'YourBaseId',32 PORT: 3001,33 });34 expect(config).not.toBeNull();35 expect(config).toEqual(expectedConfig);36 });37 it('returns a correct config when READ_ONLY is true', () => {38 const expectedConfig = {39 allowedMethods: ['GET'],40 airtableApiKey: 'YourApiKey',41 airtableBaseId: 'YourBaseId',42 port: 3000,43 };44 const config = parseEnv({45 AIRTABLE_API_KEY: 'YourApiKey',46 AIRTABLE_BASE_ID: 'YourBaseId',47 READ_ONLY: 'true',48 });49 expect(config).not.toBeNull();50 expect(config).toEqual(expectedConfig);51 });...
parsing.js
Source:parsing.js
1// @flow strict2import type {Result} from './result';3import * as result from './result';4import {maybeToResult} from './utils';5export opaque type ParseEnv = {|6 +input: string,7 i: number,8|};9export function withParserEnv<V, E>(10 input: string,11 tooLongError: E,12 f: (ParseEnv) => Result<V, E>13): Result<V, E> {14 const env: ParseEnv = {15 input,16 i: 0,17 };18 return result.bind(f(env), (v) => {19 if (env.i !== env.input.length) {20 return result.err(tooLongError);21 } else {22 return result.ok(v);23 }24 });25}26export function consume(env: ParseEnv, chars: number): string | null {27 const end = env.i + chars;28 if (end > env.input.length) {29 return null;30 }31 const str = env.input.substring(env.i, end);32 env.i = end;33 return str;34}35export function peek(env: ParseEnv, chars: number): string | null {36 const end = env.i + chars;37 if (end > env.input.length) {38 return null;39 }40 return env.input.substring(env.i, end);41}42function isAllNumbers(str: string): boolean {43 return /^\d+$/.test(str);44}45export function consumeInt(env: ParseEnv, chars: number): number | null {46 const text = consume(env, chars);47 if (text == null || !isAllNumbers(text)) {48 return null;49 }50 return parseInt(text);51}52export function parseInteger(env: ParseEnv, length: number): Result<number, null> {53 return maybeToResult(consumeInt(env, length), null);...
serverSettings.js
Source:serverSettings.js
1import parseEnv from './parseEnv';2export default {3 api: parseEnv('API'),4 serverPort: parseEnv('PORT'),...
Using AI Code Generation
1const CypressEnv = require('cypress-env');2const cypressEnv = new CypressEnv();3cypressEnv.parseEnv();4{5 "env": {6 }7}8{9}
Using AI Code Generation
1const env = Cypress.env('parseEnv')('.env');2const env = Cypress.env('parseEnv')('.env');3const env = Cypress.env('parseEnv')('.env');4const env = Cypress.env('parseEnv')('.env');5const env = Cypress.env('parseEnv')('.env');6const env = Cypress.env('parseEnv')('.env');7const env = Cypress.env('parseEnv')('.env');8const env = Cypress.env('parseEnv')('.env');9const env = Cypress.env('parseEnv')('.env');10const env = Cypress.env('parseEnv')('.env');11const env = Cypress.env('parseEnv')('.env');12const env = Cypress.env('parseEnv')('.env');
Using AI Code Generation
1const parseEnv = require('cypress-env').parseEnv;2parseEnv();3console.log(Cypress.env('host'));4| `envFile` | <code>string</code> | <code>"./.env"</code> | Path of the environment file to parse |5| `envKey` | <code>string</code> | <code>"CYPRESS_ENV"</code> | Key of the environment variable to use |6| `envKeySeparator` | <code>string</code> | <code>"__"</code> | Separator to use for the environment variables |7const parseEnv = require('cypress-env').parseEnv;8parseEnv({9});10console.log(Cypress.env('host'));
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!!