diff --git a/.codeclimate.yml b/.codeclimate.yml index b4c9862..a04a7a6 100644 --- a/.codeclimate.yml +++ b/.codeclimate.yml @@ -1,17 +1,7 @@ -engines: - duplication: - enabled: true - config: - languages: - - javascript - fixme: - enabled: true +version: 2 -ratings: - paths: - - lib/** - - test/** - -exclude_paths: - - example/**/* - - node_modules/**/* +exclude_patterns: + - example/ + - node_modules/ + - test/ + - "**/*.test.js" diff --git a/README.md b/README.md index c583664..4a9170f 100644 --- a/README.md +++ b/README.md @@ -271,25 +271,37 @@ Worth mentioning, like all options this can be set in package.json under a } ``` -### Silent mode +### Log output -In case you don't want to the output to be cluttered by the script contents, you -can run scripty in silent mode: +Scripty is now quieter by default. +The output can be configured to a level of `verbose`, `info`, `warn`, or `error`. +Any logs equal to or higher than the setting are shown. +All logs are printed to STDERR (to aid in redirection and piping). ``` -$ SCRIPTY_SILENT=true npm run publish:danger:stuff +$ SCRIPTY_LOG_LEVEL=verbose npm run publish:danger:stuff ``` -This will omit printing the path and contents of each script the command executes. +This will print the path and contents of each script the command executes. -If you always want scripty to run your scripts silently, you can set it in -your package.json under a `"scripty"` entry: +If you always want scripty to run your scripts at a certain level, +you can set it in your package.json under a `"scripty"` entry: ```json "scripty": { - "silent": true + "logLevel": "warn" } ``` + +`SCRIPTY_SILENT` and `SCRIPTY_QUIET` are aliases for `SCRIPTY_LOG_LEVEL=silent` +`SCRIPTY_VERBOSE` is an alias for `SCRIPTY_LOG_LEVEL=verbose` +(also `"silent": true`, etc in package.json#scripty) + +`SCRIPTY_DRY_RUN=true` implies log level `info` + +Explicit setting from logLevel takes precedence; otherwise, +conflicting values between silent/verbose/dryRun will respect the highest level. + ## Likely questions * **Is this black magic?** - Nope! For once, instilling some convention didn't diff --git a/cli.js b/cli.js index b15a3c4..088d48f 100755 --- a/cli.js +++ b/cli.js @@ -4,10 +4,8 @@ var lifecycleEvent = process.env.npm_lifecycle_event if (!lifecycleEvent) { console.error( - 'Error: scripty - it seems you may be running scripty from the ' + - 'command-line directly.\n' + - 'At this time, scripty can only be run within an ' + - 'npm script specified in your package.json.\n\n' + + 'scripty ERR! It seems you may be running scripty from the command-line directly.\n' + + 'At this time, scripty can only be run within an npm script specified in your package.json.\n\n' + 'Example package.json entry:\n\n' + ' "scripts": {\n' + ' "foo:bar": "scripty"\n' + @@ -21,12 +19,16 @@ if (!lifecycleEvent) { } else { var scripty = require('./lib/scripty') var loadOption = require('./lib/load-option') + var log = require('./lib/log') scripty(lifecycleEvent, { userArgs: process.argv.slice(2), parallel: loadOption('parallel'), dryRun: loadOption('dryRun'), + logLevel: loadOption('logLevel'), + quiet: loadOption('quiet'), silent: loadOption('silent'), + verbose: loadOption('verbose'), spawn: { stdio: 'inherit' }, @@ -37,7 +39,7 @@ if (!lifecycleEvent) { } }, function (er, code) { if (er) { - console.error(er) + log.error(er) code = code || er.code || 1 } process.exitCode = code diff --git a/lib/derive-log-level.js b/lib/derive-log-level.js new file mode 100644 index 0000000..81797ef --- /dev/null +++ b/lib/derive-log-level.js @@ -0,0 +1,13 @@ +var log = require('./log') + +module.exports = function deriveLogLevel (userOptions) { + if (!userOptions) return + + if (userOptions.logLevel) return userOptions.logLevel + + if (userOptions.verbose) return log.verbose + + if (userOptions.dryRun) return log.info + + if (userOptions.silent || userOptions.quiet) return log.silent +} diff --git a/lib/derive-log-level.test.js b/lib/derive-log-level.test.js new file mode 100644 index 0000000..9e8055e --- /dev/null +++ b/lib/derive-log-level.test.js @@ -0,0 +1,36 @@ +var subject = require('./derive-log-level') +var log = require('./log') + +module.exports = { + 'does not default': function () { + assert.equal(subject(), undefined) + }, + + 'explicit logLevel takes precedence': function () { + assert.equal(subject({ + silent: true, + dryRun: true, + verbose: true, + logLevel: 'warn' }), 'warn') + }, + + 'passes through unrecognized values': function () { + assert.equal(subject({ logLevel: 'worn' }), 'worn') + }, + + 'verbose preempts dry-run and silent': function () { + assert.equal(subject({ silent: true, dryRun: true, verbose: true }), log.verbose) + }, + + 'dry-run preempts silent': function () { + assert.equal(subject({ silent: true, dryRun: true }), log.info) + }, + + 'silent is read last': function () { + assert.equal(subject({ silent: true }), log.silent) + }, + + 'quiet is alias for silent': function () { + assert.equal(subject({ quiet: true }), log.silent) + } +} diff --git a/lib/log.js b/lib/log.js new file mode 100644 index 0000000..34b81f9 --- /dev/null +++ b/lib/log.js @@ -0,0 +1,52 @@ +const util = require('util') + +const constant = val => () => val + +const formatError = args => + args.map(arg => arg instanceof Error ? arg.message : arg) + +const loggerWithPrefix = (prefix, writer) => (...args) => + writer()(prefix, util.format(...formatError(args)) + .replace(/(\r?\n)(?=[\s\S]+)/g, `$1${prefix} `)) + +const silentLogger = (...args) => { + output += util.format(...args) + '\n' +} + +let level +let output + +module.exports = { + get level () { + return level.toString() + }, + + set level (l) { + level = module.exports[String(l).toLowerCase()] + }, + + read: () => output, + + reset: () => { + output = '' + module.exports.level = 'info' + } +} + +;[ + ['verbose', '>'], + ['info', '>'], + ['warn', 'WARN'], + ['error', 'ERR!'], + ['silent'] +].forEach(([name, prefix], index) => { + const logger = loggerWithPrefix(`scripty ${prefix}`, () => + level <= logger ? console.error : silentLogger) + + logger.valueOf = constant(index + 1) + logger.toString = constant(name) + + module.exports[name] = logger +}) + +module.exports.reset() diff --git a/lib/log.test.js b/lib/log.test.js new file mode 100644 index 0000000..0af4f7e --- /dev/null +++ b/lib/log.test.js @@ -0,0 +1,72 @@ +var subject = require('./log') + +module.exports = { + beforeEach: function () { + td.replace(console, 'error') + subject.reset() + }, + writesToStderr: function () { + subject.info('foo') + + td.verify(console.error('scripty >', 'foo')) + }, + setTheLogLevel: { + verbose: function () { + subject.level = subject.verbose + subject.verbose('ity') + td.verify(console.error('scripty >', 'ity')) + }, + info: function () { + subject.level = subject.info + td.when(console.error('ity')).thenThrow(new Error('Should not log verbose calls at INFO level')) + subject.verbose('ity') + subject.info('mation') + td.verify(console.error('scripty >', 'mation')) + }, + warn: function () { + subject.level = subject.warn + td.when(console.error('mation')).thenThrow(new Error('Should not log info calls at WARN level')) + subject.info('mation') + subject.warn('ing') + td.verify(console.error('scripty WARN', 'ing')) + }, + error: function () { + subject.level = subject.error + td.when(console.error('ing')).thenThrow(new Error('Should not log warn calls at ERROR level')) + subject.warn('ing') + subject.error('fail') + td.verify(console.error('scripty ERR!', 'fail')) + }, + silent: function () { + subject.level = subject.silent + td.when(console.error('fail')).thenThrow(new Error('Should not log error calls at SILENT level')) + subject.error('fail') + } + }, + modeSwitchCapturesLogs: function () { + subject.level = subject.silent + + subject.info('bar') + subject.info('baz', 'noz') + + td.verify(console.error(), { ignoreExtraArgs: true, times: 0 }) + assert.equal(subject.read(), 'scripty > bar\nscripty > baz noz\n') + }, + resetResetsMode: function () { + subject.level = subject.silent + + subject.reset() + + subject.info('biz') + td.verify(console.error('scripty >', 'biz')) + }, + resetResetsLog: function () { + subject.level = subject.silent + + subject.info('lalalal') + + subject.reset() + + assert.equal(subject.read(), '') + } +} diff --git a/lib/optionify.js b/lib/optionify.js index efe9664..f4a3a91 100644 --- a/lib/optionify.js +++ b/lib/optionify.js @@ -1,4 +1,5 @@ var _ = require('lodash') +var deriveLogLevel = require('./derive-log-level') var NULL_CB = function () {} module.exports = function (rawFunc, defaultOptions) { @@ -9,6 +10,10 @@ module.exports = function (rawFunc, defaultOptions) { if (!cb) { cb = NULL_CB } + + var logLevel = deriveLogLevel(userOptions) + if (logLevel) userOptions.logLevel = logLevel + var fullOptions = _.defaultsDeep({}, userOptions, defaultOptions) return rawFunc(mainArg, fullOptions, cb) } diff --git a/lib/resolve-script/find-executables.js b/lib/resolve-script/find-executables.js index cd933d7..02082e0 100644 --- a/lib/resolve-script/find-executables.js +++ b/lib/resolve-script/find-executables.js @@ -1,28 +1,21 @@ var _ = require('lodash') -var globFirst = require('./glob-first') -var path = require('path') var async = require('async') +var fs = require('fs') +var path = require('path') +var globFirst = require('./glob-first') +var log = require('../log') -var isExecutable = require('./is-executable') - -module.exports = function (patterns, cb) { - globFirst(patterns, function (er, results) { +module.exports = (patterns, cb) => + globFirst(patterns, (er, results) => { if (er) return cb(er) - async.map(results, function (result, cb) { - isExecutable(result, function (er, itIsExecutable) { - if (itIsExecutable) { - cb(er, path.resolve(result)) - } else { - console.warn( - 'Warning: scripty - ignoring script "' + result + '" because it' + - ' was not executable. Run `chmod +x "' + result + '" if you want' + - ' scripty to run it.' - ) - cb(er, undefined) - } - }) - }, function (er, results) { - cb(er, _.compact(results)) - }) + + async.map(results, + (result, cb) => fs.access(result, fs.constants.R_OK | fs.constants.X_OK, + er => cb(null, er + ? log.warn(`Ignoring script '${result}' because it was not readable/executable.\n` + + `Run \`chmod u+rx '${result}'\` if you want scripty to run it.`) + : path.resolve(result)) + ), + (er, results) => cb(er, _.compact(results)) + ) }) -} diff --git a/lib/resolve-script/find-executables.test.js b/lib/resolve-script/find-executables.test.js index cdf8f2f..5798604 100644 --- a/lib/resolve-script/find-executables.test.js +++ b/lib/resolve-script/find-executables.test.js @@ -1,5 +1,6 @@ var _ = require('lodash') var path = require('path') +var log = require('../log') var base = function (glob) { return path.resolve('test/fixtures/unit/find-executables', glob) @@ -8,7 +9,7 @@ var subject = require('./find-executables') module.exports = { beforeEach: function () { - td.replace(console, 'warn') + log.level = 'silent' }, noFilesFound: function (done) { subject([base('does-not-exist*')], function (er, result) { @@ -26,11 +27,10 @@ module.exports = { if (process.platform === 'win32') return done() subject([base('file.*')], function (er, result) { assert.deepEqual(result, [base('file.executable')]) - td.verify(console.warn( - 'Warning: scripty - ignoring script "' + base('file.not.executable') + - '" because it was not executable. Run `chmod +x "' + - base('file.not.executable') + '" if you want scripty to run it.' - )) + assert.includes(log.read(), + `scripty WARN Ignoring script '${base('file.not.executable')}' because it was not readable/executable.\n` + + `scripty WARN Run \`chmod u+rx '${base('file.not.executable')}'\` if you want scripty to run it.` + ) done(er) }) }, diff --git a/lib/resolve-script/index.js b/lib/resolve-script/index.js index 4aad760..7178374 100644 --- a/lib/resolve-script/index.js +++ b/lib/resolve-script/index.js @@ -14,11 +14,10 @@ module.exports = function (name, options, cb) { if (ourPaths.length > 0) { cb(er, ourPaths) } else { - cb(new Error( - 'Error: scripty - no script found for npm lifecycle "' + name + '"' + - ' matching either "' + userGlob + '" or "' + ourGlob + '". Either' + - ' define a script or remove "scripty" from "' + name + '" under' + - ' "scripts" in your package.json.' + cb(new Error(`No script found for npm lifecycle '${name}' matching any of:\n` + + ` ${String(userGlob).replace(/,/g, '\n ')}\n` + + ` ${String(ourGlob).replace(/,/g, '\n ')}\n` + + `Either define a script or remove "scripty" from 'scripts.${name}' in your package.json.` ), null) } }) diff --git a/lib/resolve-script/index.test.js b/lib/resolve-script/index.test.js index 12e8453..4075310 100644 --- a/lib/resolve-script/index.test.js +++ b/lib/resolve-script/index.test.js @@ -39,10 +39,9 @@ module.exports = { this.subject('fake', OPTIONS, function (er, result) { assert.equal(er.message, - 'Error: scripty - no script found for npm lifecycle "fake" matching ' + - 'either "glob1" or "glob2". Either define a script or remove ' + - '"scripty" from "fake" under "scripts" in your package.json.' - ) + `No script found for npm lifecycle 'fake' matching any of:\n` + + ` glob1\n glob2\n` + + `Either define a script or remove "scripty" from 'scripts.fake' in your package.json.`) assert.equal(result, null) done(null) }) diff --git a/lib/resolve-script/is-executable.js b/lib/resolve-script/is-executable.js deleted file mode 100644 index f06d93b..0000000 --- a/lib/resolve-script/is-executable.js +++ /dev/null @@ -1,15 +0,0 @@ -var fs = require('fs') - -module.exports = function (path, cb) { - if (process.platform === 'win32') return cb(null, true) - fs.stat(path, function (er, stats) { - if (er) return cb(er) - var mode = stats.mode - - var owner = mode >> 6 - var group = (mode << 3) >> 6 - var others = (mode << 6) >> 6 - - cb(er, !!(owner & 1) || !!(group & 1) || !!(others & 1)) - }) -} diff --git a/lib/resolve-script/is-executable.test.js b/lib/resolve-script/is-executable.test.js deleted file mode 100644 index 05f3467..0000000 --- a/lib/resolve-script/is-executable.test.js +++ /dev/null @@ -1,50 +0,0 @@ -var path = require('path') -var fs = require('fs') - -var root = path.resolve('test/fixtures/user-scripts/stats') -var subject = require('./is-executable') -module.exports = { - allXIsX: function (done) { - fs.chmodSync(root + '/all-x', '755') - subject(root + '/all-x', function (er, answer) { - assert.equal(answer, true) - done(er) - }) - }, - userXIsX: function (done) { - fs.chmodSync(root + '/owner-x', '744') - subject(root + '/owner-x', function (er, answer) { - assert.equal(answer, true) - done(er) - }) - }, - groupXIsX: function (done) { - fs.chmodSync(root + '/group-x', '654') - subject(root + '/group-x', function (er, answer) { - assert.equal(answer, true) - done(er) - }) - }, - othersXIsX: function (done) { - fs.chmodSync(root + '/other-x', '645') - subject(root + '/other-x', function (er, answer) { - assert.equal(answer, true) - done(er) - }) - }, - noXIsNotX: function (done) { - if (process.platform === 'win32') return done() - fs.chmodSync(root + '/no-x', '644') - subject(root + '/no-x', function (er, answer) { - assert.equal(answer, false) - done(er) - }) - }, - anyWindowsIsAllX: function (done) { - if (process.platform !== 'win32') return done() - subject(root + '/silly-lololo', function (er, answer) { - assert.equal(answer, true) - done(er) - }) - } -} diff --git a/lib/run/commandify.js b/lib/run/commandify.js deleted file mode 100644 index c93932e..0000000 --- a/lib/run/commandify.js +++ /dev/null @@ -1,9 +0,0 @@ -var _ = require('lodash') - -module.exports = function (func, items, options) { - return _.map(items, function (item) { - return function (cb) { - func(item, options, cb) - } - }) -} diff --git a/lib/run/dry-run.js b/lib/run/dry-run.js index cad38f6..13b857e 100644 --- a/lib/run/dry-run.js +++ b/lib/run/dry-run.js @@ -1,10 +1,10 @@ var _ = require('lodash') var printScript = require('./print-script') -var log = require('./log') +var log = require('../log') module.exports = function (scriptFiles, cb) { - log('This is a dry run. Executed scripts would be:\n') + log.info('This is a dry run. Executed scripts would be:') _.map(scriptFiles, printScript) cb(null, 0) } diff --git a/lib/run/index.js b/lib/run/index.js index 4839ff3..9309261 100644 --- a/lib/run/index.js +++ b/lib/run/index.js @@ -1,7 +1,8 @@ var _ = require('lodash') +const commandify = (func, items, options) => + items.map(item => cb => func(item, options, cb)) var dryRun = require('./dry-run') -var commandify = require('./commandify') var spawnScript = require('./spawn-script') var all = require('./all') diff --git a/lib/run/log.js b/lib/run/log.js deleted file mode 100644 index b015338..0000000 --- a/lib/run/log.js +++ /dev/null @@ -1,29 +0,0 @@ -var _ = require('lodash') - -var isSilent = false -var output = '' - -module.exports = function () { - if (!isSilent) { - if (_.startsWith(arguments[0], 'Error:')) { - console.error.apply(this, arguments) - } else { - console.log.apply(this, arguments) - } - } else { - output += _.toArray(arguments).join(' ') + '\n' - } -} - -module.exports.shush = function () { - isSilent = true -} - -module.exports.read = function () { - return output -} - -module.exports.reset = function () { - isSilent = false - output = '' -} diff --git a/lib/run/log.test.js b/lib/run/log.test.js deleted file mode 100644 index 3158324..0000000 --- a/lib/run/log.test.js +++ /dev/null @@ -1,45 +0,0 @@ -var subject = require('./log') - -module.exports = { - beforeEach: function () { - td.replace(console, 'log') - td.replace(console, 'error') - subject.reset() - }, - normallyJustLogs: function () { - subject('foo') - - td.verify(console.log('foo')) - }, - consoleErrorsWhenStartingWithError: function () { - subject('Error: foo') - - td.verify(console.error('Error: foo')) - }, - modeSwitchCapturesLogs: function () { - subject.shush() - - subject('bar') - subject('baz', 'noz') - - td.verify(console.log(), { ignoreExtraArgs: true, times: 0 }) - assert.equal(subject.read(), 'bar\nbaz noz\n') - }, - resetResetsMode: function () { - subject.shush() - - subject.reset() - - subject('biz') - td.verify(console.log('biz')) - }, - resetResetsLog: function () { - subject.shush() - subject('lalalal') - - subject.reset() - - assert.equal(subject.read(), '') - } - -} diff --git a/lib/run/print-script.js b/lib/run/print-script.js index bc9b719..845ce40 100644 --- a/lib/run/print-script.js +++ b/lib/run/print-script.js @@ -1,25 +1,15 @@ var fs = require('fs') -var _ = require('lodash') - -var log = require('./log') +var log = require('../log') module.exports = function (scriptFile) { - log('Executing "' + scriptFile + '":\n') - var script = read(scriptFile) - if (script) { - log(_.map(script.split('\n'), function (line) { - return '> ' + line - }).join('\n') + '\n\n') - } + log.info(`Executing "${scriptFile}":\n`) + log.verbose(`${read(scriptFile)}`) } function read (scriptFile) { try { return fs.readFileSync(scriptFile).toString() } catch (e) { - log( - 'Error: scripty - failed trying to read "' + scriptFile + '":\n\n' + - e.message - ) + log.warn(`Failed to read '${scriptFile}':\n${e.message}`) } } diff --git a/lib/run/print-script.test.js b/lib/run/print-script.test.js index b5539db..37c4271 100644 --- a/lib/run/print-script.test.js +++ b/lib/run/print-script.test.js @@ -1,10 +1,10 @@ var path = require('path') -var log = require('./log') +var log = require('../log') module.exports = { beforeEach: function () { - log.shush() + log.level = 'silent' this.subject = require('./print-script') }, happyPath: function () { @@ -12,16 +12,16 @@ module.exports = { this.subject(script) - assert.includes(log.read(), 'Executing "' + script + '":\n') - assert.includes(log.read(), '> #!/usr/bin/env sh') - assert.includes(log.read(), '> npm test -- --debug-brk') + assert.includes(log.read(), 'scripty > Executing "' + script + '":\n') + assert.includes(log.read(), 'scripty > #!/usr/bin/env sh') + assert.includes(log.read(), 'scripty > npm test -- --debug-brk') }, sadPath: function () { var script = '/silly/nonsense' this.subject(script) - assert.includes(log.read(), 'Error: scripty - failed trying to read "/silly/nonsense":') - assert.includes(log.read(), 'ENOENT') + assert.includes(log.read(), `scripty WARN Failed to read '/silly/nonsense':`) + assert.includes(log.read(), `scripty WARN ENOENT`) } } diff --git a/lib/run/spawn-script.js b/lib/run/spawn-script.js index 0f0d926..b05fcb8 100644 --- a/lib/run/spawn-script.js +++ b/lib/run/spawn-script.js @@ -3,18 +3,14 @@ var printScript = require('./print-script') var spawn = require('child_process').spawn module.exports = function (scriptFile, options, cb) { - if (!options.silent) printScript(scriptFile) - var userArgs = options.userArgs - var child = spawn(scriptFile, userArgs, options.spawn) - child.on('close', function (code) { - if (code !== 0) { - cb(new Error( - 'Error: scripty - script "fail" failed by exiting ' + - 'with a non-zero code (' + code + ').' - ), code) - } else { - cb(null, code) - } - }) + printScript(scriptFile) + + const child = spawn(scriptFile, options.userArgs, options.spawn) + + child.on('close', code => cb(code !== 0 + ? new Error(`script failed: '${scriptFile}'\nexit status: ${code}`) + : null, code) + ) + _.invoke(options, 'spawn.tap', child) } diff --git a/lib/scripty.js b/lib/scripty.js index c8cd0a7..5b77dff 100644 --- a/lib/scripty.js +++ b/lib/scripty.js @@ -1,8 +1,11 @@ var optionify = require('./optionify') var resolveScript = require('./resolve-script') var run = require('./run') +var log = require('./log') module.exports = optionify(function scripty (npmLifecycle, options, cb) { + log.level = options.logLevel + resolveScript(npmLifecycle, options.resolve, function (er, scriptFiles) { if (er) return cb(er) run(scriptFiles, options, cb) @@ -11,7 +14,7 @@ module.exports = optionify(function scripty (npmLifecycle, options, cb) { userArgs: [], parallel: false, dryRun: false, - silent: false, + logLevel: 'info', spawn: {}, resolve: {} }) diff --git a/test/run-scripty.js b/test/run-scripty.js index 5ae977b..172c97a 100644 --- a/test/run-scripty.js +++ b/test/run-scripty.js @@ -8,6 +8,7 @@ module.exports = function (name, opts, cb) { var stdio = {} scripty(name, _.defaultsDeep({}, opts, { + logLevel: 'silent', resolve: { builtIn: path.resolve('test/fixtures/built-in-scripts'), builtInWin: path.resolve('test/fixtures/built-in-scripts-win'), diff --git a/test/safe-helper.js b/test/safe-helper.js index 13788dc..0b05e90 100644 --- a/test/safe-helper.js +++ b/test/safe-helper.js @@ -1,12 +1,9 @@ var decorateAssertions = require('./decorate-assertions') global.assert = decorateAssertions(require('assert')) -var log = require('../lib/run/log') +var log = require('../lib/log') module.exports = { - beforeEach: function () { - log.shush() - }, afterEach: function () { log.reset() } diff --git a/test/safe/basic-test.js b/test/safe/basic-test.js index 5265416..d275247 100644 --- a/test/safe/basic-test.js +++ b/test/safe/basic-test.js @@ -1,5 +1,6 @@ var runScripty = require('../run-scripty') -var log = require('../../lib/run/log') +var log = require('../../lib/log') +const path = require('path') module.exports = { outputAndRunScript: function (done) { @@ -19,7 +20,7 @@ module.exports = { runScripty('not:a:real:thing', {}, function (er, code, stdio) { assert.notEqual(0, code) assert.includes(er.message, - 'Error: scripty - no script found for npm lifecycle "not:a:real:thing"' + `No script found for npm lifecycle 'not:a:real:thing'` ) done(null) @@ -28,10 +29,7 @@ module.exports = { scriptFoundButFailed: function (done) { runScripty('fail', {}, function (er, code, stdio) { assert.notEqual(0, code) - assert.includes(er.message, - 'Error: scripty - script "fail" failed by exiting ' + - 'with a non-zero code (' + code + ').' - ) + assert.includes(er.message, `script failed: '${path.resolve('test/fixtures/user-scripts/fail')}'\nexit status: ${code}`) if (process.platform === 'win32') { assert.includes(stdio.stderr, 'The system cannot find the path specified.') } else { diff --git a/test/safe/dry-run-test.js b/test/safe/dry-run-test.js index 78fcd50..d8de07a 100644 --- a/test/safe/dry-run-test.js +++ b/test/safe/dry-run-test.js @@ -1,5 +1,5 @@ var runScripty = require('../run-scripty') -var log = require('../../lib/run/log') +var log = require('../../lib/log') module.exports = function doesNotRunButPrintResolvedScripts (done) { runScripty('hello:world', { dryRun: true }, function (er, code, stdio) { diff --git a/test/safe/silent-test.js b/test/safe/silent-test.js index 31d3078..dd3b8ce 100644 --- a/test/safe/silent-test.js +++ b/test/safe/silent-test.js @@ -1,9 +1,11 @@ var runScripty = require('../run-scripty') -var log = require('../../lib/run/log') module.exports = function doesNotEchoScriptContentInSilentMode (done) { - runScripty('hello:world', { silent: true }, function (er, code, stdio) { - assert.equal(log.read(), '') + var oldConsole = global.console + global.console = {} // blow up if a console method is invoked + + runScripty('hello:world', { logLevel: 'silent' }, function (er, code, stdio) { + global.console = oldConsole done(er) }) } diff --git a/test/unit-helper.js b/test/unit-helper.js index 47bc35b..c695b96 100644 --- a/test/unit-helper.js +++ b/test/unit-helper.js @@ -3,7 +3,7 @@ global.td = require('testdouble') var decorateAssertions = require('./decorate-assertions') global.assert = decorateAssertions(require('assert')) -var log = require('../lib/run/log') +var log = require('../lib/log') global.UNSUPPORTED_TDD = require('./is-old-node') if (UNSUPPORTED_TDD) {