Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function init () {
// find out the source for all test -> this spec file
const sites = callsites()
la(sites.length, 'missing callsite')
const specFileUrl = sites[1].filename
la(is.webUrl(specFileUrl), 'missing spec url', specFileUrl)
console.log('loading spec from', specFileUrl)
// specFileUrl is something like
// http://localhost:49829/__cypress/tests?p=cypress/integration/spec.js-438
// we will need to get "true" filename which in this case should be
// cypress/integration/spec.js
const pIndex = specFileUrl.indexOf('?p=')
const dotJsIndex = specFileUrl.indexOf('.js-', pIndex)
const specFile = specFileUrl.substr(pIndex + 3, dotJsIndex - pIndex)
console.log('specFile is "%s"', specFile)
// ignore arguments for now
api.fromCurrentFolder = () => specFile
// cache the fetched source, otherwise every test fetches it
const shouldFetch = api.readFileSync === dummyReadFileSync
registryUrl().then(function (npmUrl) {
log('NPM registry url', npmUrl)
la(check.webUrl(npmUrl), 'need npm registry url, got', npmUrl)
npmUrl = npmUrl.replace(/^https:/, 'http:').trim()
var url = (options.registry || npmUrl) + escapeName(name)
// TODO how to detect if the registry is not responding?
log('getting url', url)
request.get(url, onNPMversions)
var timer = setTimeout(rejectOnTimeout, MAX_WAIT_TIMEOUT)
function onNPMversions (err, response, body) {
log('got response for', url)
clearTimeout(timer)
if (err) {
console.error('ERROR when fetching info for package', name)
function init () {
// find out the source for all test -> this spec file
const sites = callsites()
la(sites.length, 'missing callsite')
const specFileUrl = sites[1].filename
la(is.webUrl(specFileUrl), 'missing spec url', specFileUrl)
console.log('loading spec from', specFileUrl)
// specFileUrl is something like
// http://localhost:49829/__cypress/tests?p=cypress/integration/spec.js-438
// we will need to get "true" filename which in this case should be
// cypress/integration/spec.js
const pIndex = specFileUrl.indexOf('?p=')
const dotJsIndex = specFileUrl.indexOf('.js-', pIndex)
const specFile = specFileUrl.substr(pIndex + 3, dotJsIndex - pIndex)
console.log('specFile is "%s"', specFile)
// ignore arguments for now
api.fromCurrentFolder = () => specFile
// cache the fetched source, otherwise every test fetches it
const shouldFetch = api.readFileSync === dummyReadFileSync
function formUrl (npmUrl, name) {
la(check.unemptyString(name), 'missing name string', name)
la(check.webUrl(npmUrl), 'need npm registry url, got', npmUrl)
npmUrl = npmUrl.replace(/^https:/, 'http:').trim()
// for scoped package names that have @user/foo
var url = npmUrl + name.replace('/', '%2f')
return url
}
.then(function (registry) {
la(is.webUrl(registry.url), 'missing registry url', registry)
la(is.object(registry.server), 'missing server itself', registry)
return npm.install({
name: found.name,
flags: options.flags,
registry: registry.url
}).then(function () {
debug('finished install', found.name)
registry.server.close()
// if (saveFlag(options.flags)) {
// setInstalledVersion(options.name, found.folder)
// }
})
})
}
function clean (version, silent) {
var originalVersion = version
verify.unemptyString(version, 'missing version string' + version)
if (check.webUrl(version)) {
return
}
if (isKeyword(version)) {
return
}
version = version.replace('~', '')
var twoDigitVersion = /^\d+\.\d+$/
if (twoDigitVersion.test(version)) {
version += '.0'
}
if (version === 'latest' || version === '*') {
return
}
try {
version = semver.clean(version)
function isSupportedVersionFormat (version) {
la(is.unemptyString(version), 'expected version string')
return !is.webUrl(version) &&
!gitUrl(version) &&
!isGitAtVersion(version) &&
!isVersionKeyword(version) &&
!isPrefixed(version)
}