Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
test: add --fix flag to attempt fixing packages before failing
  • Loading branch information
feross committed Feb 18, 2018
1 parent 50c466c commit 22673fc
Showing 1 changed file with 15 additions and 20 deletions.
35 changes: 15 additions & 20 deletions test/clone.js
Expand Up @@ -26,7 +26,8 @@ var argv = minimist(process.argv.slice(2), {
'disabled',
'offline',
'quick',
'quiet'
'quiet',
'fix'
]
})

Expand Down Expand Up @@ -62,24 +63,19 @@ test('test github repos that use `standard`', function (t) {
var folder = path.join(TMP, name)
return function (cb) {
fs.access(path.join(TMP, name), fs.R_OK | fs.W_OK, function (err) {
if (argv.offline) {
if (err) {
t.pass('SKIPPING (offline): ' + name + ' (' + pkg.repo + ')')
return cb(null)
}
if (argv.offline && err) {
t.pass('SKIPPING (offline): ' + name + ' (' + pkg.repo + ')')
cb(null)
} else if (argv.offline) {
runStandard(cb)
} else {
var downloadPackage = err ? gitClone : gitPull
downloadPackage(function (err) {
if (err) return cb(err)
runStandard(cb)
})
}

function downloadPackage (cb) {
if (err) gitClone(cb)
else gitPull(cb)
}

function gitClone (cb) {
var args = [ 'clone', '--depth', 1, url, path.join(TMP, name) ]
spawn(GIT, args, { stdio: 'ignore' }, function (err) {
Expand All @@ -101,14 +97,12 @@ test('test github repos that use `standard`', function (t) {
if (pkg.args) args.push.apply(args, pkg.args)
spawn(STANDARD, args, { cwd: folder }, function (err) {
var str = name + ' (' + pkg.repo + ')'
if (err) {
if (err.message.indexOf('(indent)') || err.message.indexOf('(no-multi-spaces)') || err.message.indexOf('(space-unary-ops)')) {
t.comment('Attempting to fix eslint breaking changes for ' + str)
runStandardFix(cb)
} else {
t.fail(str)
cb(null)
}
if (err && argv.fix) {
t.comment('Attempting --fix on ' + str)
runStandardFix(cb)
} else if (err) {
t.fail(str)
cb(null)
} else {
t.pass(str)
cb(null)
Expand All @@ -120,7 +114,7 @@ test('test github repos that use `standard`', function (t) {
var args = [ '--fix', '--verbose' ]
if (pkg.args) args.push.apply(args, pkg.args)
spawn(STANDARD, args, { cwd: folder }, function (err) {
var str = name + ' (' + pkg.repo + ') **with --fix'
var str = name + ' (' + pkg.repo + ') ** with --fix'
if (err) { t.fail(str) } else { t.pass(str) }
runGitReset(cb)
})
Expand All @@ -130,6 +124,7 @@ test('test github repos that use `standard`', function (t) {
var args = [ 'reset', '--hard' ]
spawn(GIT, args, { cwd: folder }, function (err) {
if (err) err.message += ' (git reset) (' + name + ')'
// Fatal error if can't git reset
cb(err)
})
}
Expand Down

0 comments on commit 22673fc

Please sign in to comment.