|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +var tap = require('tap'); |
| 4 | +var path = require('path'); |
| 5 | +var exec = require('child_process').exec; |
| 6 | + |
| 7 | +var stripFullStack = require('./common').stripFullStack; |
| 8 | +var stripDeprecations = require('./common').stripDeprecations; |
| 9 | + |
| 10 | +var tapeBin = 'node ' + path.join(__dirname, '../bin/tape'); |
| 11 | + |
| 12 | +var expectedStackTraceBug = (/^3\.[012]\.\d+$/).test(process.versions.node); // https://github.com/nodejs/node/issues/2581 |
| 13 | + |
| 14 | +tap.test( |
| 15 | + 'should throw error when --strict is passed via cli and no files are found', |
| 16 | + { todo: expectedStackTraceBug ? 'Fails on these node versions' : false }, |
| 17 | + function (tt) { |
| 18 | + tt.plan(3); |
| 19 | + |
| 20 | + exec(tapeBin + ' --strict "no*files*found"', { cwd: path.join(__dirname) }, function (err, stdout, stderr) { |
| 21 | + tt.same(stdout.toString('utf8'), ''); |
| 22 | + tt.match(stripFullStack(stderr.toString('utf8')).join('\n'), /^No test files found!\n$/); |
| 23 | + tt.equal(err.code, 127); |
| 24 | + }); |
| 25 | + } |
| 26 | +); |
| 27 | + |
| 28 | +tap.test( |
| 29 | + 'should not throw error when --no-strict is passed via cli and no files are found', |
| 30 | + { todo: expectedStackTraceBug ? 'Fails on these node versions' : false }, |
| 31 | + function (tt) { |
| 32 | + tt.plan(3); |
| 33 | + |
| 34 | + exec(tapeBin + ' --no-strict "no*files*found"', { cwd: path.join(__dirname) }, function (err, stdout, stderr) { |
| 35 | + tt.equal(stripDeprecations(stderr.toString('utf8')), ''); |
| 36 | + tt.same(stripFullStack(stdout.toString('utf8')), [ |
| 37 | + 'TAP version 13', |
| 38 | + '', |
| 39 | + '1..0', |
| 40 | + '# tests 0', |
| 41 | + '# pass 0', |
| 42 | + '', |
| 43 | + '# ok', |
| 44 | + '', |
| 45 | + '' |
| 46 | + ]); |
| 47 | + tt.equal(err, null); // code 0 |
| 48 | + }); |
| 49 | + } |
| 50 | +); |
| 51 | + |
| 52 | +tap.test( |
| 53 | + 'should not throw error when no files are found', |
| 54 | + { todo: expectedStackTraceBug ? 'Fails on these node versions' : false }, |
| 55 | + function (tt) { |
| 56 | + tt.plan(3); |
| 57 | + |
| 58 | + exec(tapeBin + ' "no*files*found"', { cwd: path.join(__dirname) }, function (err, stdout, stderr) { |
| 59 | + tt.equal(stripDeprecations(stderr.toString('utf8')), ''); |
| 60 | + tt.same(stripFullStack(stdout.toString('utf8')), [ |
| 61 | + 'TAP version 13', |
| 62 | + '', |
| 63 | + '1..0', |
| 64 | + '# tests 0', |
| 65 | + '# pass 0', |
| 66 | + '', |
| 67 | + '# ok', |
| 68 | + '', |
| 69 | + '' |
| 70 | + ]); |
| 71 | + tt.equal(err, null); // code 0 |
| 72 | + }); |
| 73 | + } |
| 74 | +); |
0 commit comments