Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const getArguments = cliArgs => {
la(is.strings(cliArgs), 'expected list of strings', cliArgs)
let start = 'start'
let test = 'test'
let url
if (cliArgs.length === 1 && isUrlOrPort(cliArgs[0])) {
// passed just single url or port number, for example
// "start": "http://localhost:8080"
url = normalizeUrl(cliArgs[0])
} else if (cliArgs.length === 2) {
if (isUrlOrPort(cliArgs[0])) {
// passed port and custom test command
// like ":8080 test-ci"
url = normalizeUrl(cliArgs[0])
test = cliArgs[1]
}
deploy (filenames) {
debug('deploying %d files', filenames.length)
debug(filenames)
la(is.strings(filenames), 'missing file names', filenames)
la(is.not.empty(filenames), 'expected list of files', filenames)
filenames.forEach(name => {
la(fs.existsSync(name), 'cannot find file', name)
})
const isPackageJson = R.test(/package\.json$/)
const packageJsonPresent = R.any(isPackageJson)
la(packageJsonPresent(filenames),
'missing package.json file in the list', filenames)
const packageJsonFilename = filenames.find(isPackageJson)
const packageJsonFolder = path.dirname(packageJsonFilename)
debug('package.json filename is', packageJsonFilename)
debug('in folder', packageJsonFolder)
// TODO make sure all files exist
if (!currentTest) {
throw new Error('Missing current test, cannot make snapshot')
}
const fullTitle = getTestTitle(currentTest)
la(
is.unemptyString(fullTitle),
'could not get full title from test',
currentTest
)
debug('snapshot in test "%s"', fullTitle)
debug('from file "%s"', currentTest.file)
const fullTitleParts = getTestTitleParts(currentTest)
la(
is.strings(fullTitleParts),
'could not get test title strings',
currentTest
)
debug('full title in parts %o', fullTitleParts)
// eslint-disable-next-line immutable/no-let
let savedTestTitle = fullTitle
let snapshotOptions = {}
if (isDataDriven(arguments)) {
// value is a function
debug('data-driven test for %s', value.name)
value = dataDriven(value, Array.from(arguments).slice(1))
savedTestTitle += ' ' + value.name
debug('extended save name to include function name')
debug('snapshot name "%s"', savedTestTitle)
function findModules (searchNames) {
la(is.strings(searchNames), 'expected names to find', searchNames)
// names could potentially have version part
const parsedNames = searchNames.map(parse)
const names = R.pluck('name', parsedNames)
debug('just names', names)
const searches = names.map(name => `${rootFolder}/*/node_modules/${name}`)
const folders = glob.sync(searches)
return Promise.all(folders.map(getVersionSafe))
.then(R.filter(R.is(Object)))
.then(R.groupBy(R.prop('name')))
.then(pickFoundVersions(parsedNames))
.then(results => {
const found = R.pickBy(is.object, results)
const foundNames = R.keys(found)
const missing = findMissing(parsedNames, foundNames)
function findMissing (names, found) {
la(is.array(names), 'wrong names', names)
la(is.strings(found), 'wrong installed', found)
// each object in "names" is parsed object
// {name, version}
const missingNames = difference(R.pluck('name', names), found)
return missingNames.map(name => R.find(R.propEq('name', name), names))
}
const la = require('lazy-ass')
const is = require('check-more-types')
const falafel = require('falafel')
const debug = require('debug')('comment-value')
const commentStarts = require('./comments').starts
la(is.strings(commentStarts), 'invalid comment starts', commentStarts)
const {parseCommentVariables, initExpressionParser} = require('./comment-parser')
const {isWhiteSpace} = require('./comments')
const R = require('ramda')
const beautifySource = require('./beautify')
// emit events when finding comment / instrumenting
// allows quick testing
if (!global.instrument) {
const EventEmitter = require('events')
global.instrument = new EventEmitter()
}
const emitter = global.instrument
function storeInIIFE (reference, value, typeReference) {
return `(function () {
if (typeof ${value} === 'function') {
function checkJsonFile (filename) {
la(is.unemptyString(filename), 'expected filename', filename)
const jsonFilename = path.join(logsFolder, filename)
la(fs.existsSync(jsonFilename), 'cannot find json file', jsonFilename)
const result = require(jsonFilename)
la(is.object(result), 'expected an object from', jsonFilename, result)
la(is.unemptyString(result.specName), 'missing spec file name', result)
la(is.unemptyString(result.title), 'missing test title', result)
la(is.unemptyString(result.suiteName), 'missing suite name', result)
la(is.unemptyString(result.testError), 'missing test error', result)
la(is.strings(result.testCommands), 'missing test commands', result)
la(is.unempty(result.testCommands),
'should have test commands in', filename, result)
la(is.strings(result.testCommands),
'test commands should be strings', filename, result)
la(result.testCommands[0].startsWith('visit'),
'expected first command to be visit', result.testCommands)
const screenshot = result.screenshot
la(is.unemptyString(screenshot), 'could not find screenshot', result)
const screenshotFilename = path.join(screenshotsFolder, screenshot)
la(fs.existsSync(screenshotFilename),
'could not find screenshot image', screenshotFilename)
console.log('file %s looks ok', jsonFilename)
function haveModules (list, options = []) {
la(is.strings(options), 'expected list of options', options)
const nameAndVersion = R.project(['name', 'version'])(list)
return Promise.all(list.map(installMain))
.then(() => {
list.forEach(p => {
console.log(`have ${p.name}@${p.version}`)
})
})
.then(() => {
if (saveDependencies(options)) {
debug('saving as dependencies in package.json')
saveVersions(nameAndVersion)
} else if (saveDevDependencies(options)) {
debug('saving as devDependencies in package.json')
saveVersions(nameAndVersion, true)
function npmInstall (list, options) {
la(is.array(list), 'expected list of modules to npm install', list)
la(is.strings(options), 'expected list of CLI options', options)
if (is.empty(list)) {
return Promise.resolve()
}
const flags = options.join(' ')
const names = list.map(fullInstallName).join(' ')
const cmd = `npm install ${flags} ${names}`
console.log(cmd)
return execa.shell(cmd)
}
function safeName (names) {
la(is.strings(names), 'expected list of names', names)
return slugify(names.join('-'))
}