1var fs = require('graceful-fs') 2var path = require('path') 3 4var mkdirp = require('mkdirp') 5var test = require('tap').test 6 7var common = require('../common-tap') 8 9var pkg = common.pkg 10var tmp = path.resolve(pkg, 'tmp') 11var cache = common.cache 12var dep = path.resolve(pkg, 'dep') 13 14var EXEC_OPTS = { cwd: pkg } 15 16var json = { 17 name: 'scripts-whitespace-windows', 18 version: '1.0.0', 19 description: 'a test', 20 repository: 'git://github.com/robertkowalski/bogus', 21 scripts: { 22 foo: 'foo --title "Analysis of" --recurse -d report src' 23 }, 24 dependencies: { 25 'scripts-whitespace-windows-dep': '0.0.1' 26 }, 27 license: 'WTFPL' 28} 29 30var dependency = { 31 name: 'scripts-whitespace-windows-dep', 32 version: '0.0.1', 33 bin: [ 'bin/foo' ] 34} 35 36var foo = function () { /* 37#!/usr/bin/env node 38 39if (process.argv.length === 8) 40 console.log('npm-test-fine') 41*/ }.toString().split('\n').slice(1, -1).join('\n') 42 43test('setup', function (t) { 44 mkdirp.sync(tmp) 45 fs.writeFileSync( 46 path.join(pkg, 'package.json'), 47 JSON.stringify(json, null, 2) 48 ) 49 fs.writeFileSync( 50 path.join(pkg, 'README.md'), 51 "### THAT'S RIGHT\n" 52 ) 53 54 mkdirp.sync(path.join(dep, 'bin')) 55 fs.writeFileSync( 56 path.join(dep, 'package.json'), 57 JSON.stringify(dependency, null, 2) 58 ) 59 fs.writeFileSync(path.join(dep, 'bin', 'foo'), foo) 60 61 common.npm(['i', dep], { 62 cwd: pkg, 63 env: Object.assign({ 64 npm_config_cache: cache, 65 npm_config_tmp: tmp, 66 npm_config_prefix: pkg, 67 npm_config_global: 'false' 68 }, process.env) 69 }, function (err, code, stdout, stderr) { 70 t.ifErr(err, 'npm i ' + dep + ' finished without error') 71 t.equal(code, 0, 'npm i ' + dep + ' exited ok') 72 t.notOk(stderr, 'no output stderr') 73 t.end() 74 }) 75}) 76 77test('test', function (t) { 78 common.npm(['run', 'foo'], EXEC_OPTS, function (err, code, stdout, stderr) { 79 stderr = stderr.trim() 80 if (stderr) console.error(stderr) 81 t.ifErr(err, 'npm run finished without error') 82 t.equal(code, 0, 'npm run exited ok') 83 t.notOk(stderr, 'no output stderr: ' + stderr) 84 stdout = stdout.trim() 85 t.ok(/npm-test-fine/.test(stdout)) 86 t.end() 87 }) 88}) 89