UNPKG

3.87 kBJavaScriptView Raw
1'use strict';
2
3var tap = require('tap');
4var path = require('path');
5var exec = require('child_process').exec;
6
7var stripFullStack = require('./common').stripFullStack;
8
9var tapeBin = path.join(__dirname, '../bin/tape');
10
11var expectedExitCodeFailure = (/^0\.10\.\d+$/).test(process.versions.node);
12var expectedStackTraceBug = (/^3\.[012]\.\d+$/).test(process.versions.node); // https://github.com/nodejs/node/issues/2581
13
14tap.test(
15 'Should throw error when --no-only is passed via cli and there is a .only test',
16 { todo: expectedExitCodeFailure || expectedStackTraceBug ? 'Fails on these node versions' : false },
17 function (tt) {
18 tt.plan(3);
19
20 exec(tapeBin + ' --no-only "**/*.js"', {
21 cwd: path.join(__dirname, 'no_only')
22 }, function (err, stdout, stderr) {
23 tt.same(stdout.toString('utf8'), '');
24 tt.match(stripFullStack(stderr.toString('utf8')).join('\n'), /Error: `only` tests are prohibited\n/);
25 tt.equal(err.code, 1);
26 });
27 }
28);
29
30tap.test(
31 'Should throw error when NODE_TAPE_NO_ONLY_TEST is passed via envs and there is an .only test',
32 { todo: expectedExitCodeFailure || expectedStackTraceBug ? 'Fails on these node versions' : false },
33 function (tt) {
34 tt.plan(3);
35
36 exec(tapeBin + ' "**/*.js"', {
37 cwd: path.join(__dirname, 'no_only'),
38 env: { PATH: process.env.PATH, NODE_TAPE_NO_ONLY_TEST: 'true' }
39 }, function (err, stdout, stderr) {
40 tt.same(stdout.toString('utf8'), '');
41 tt.match(stripFullStack(stderr.toString('utf8')).join('\n'), /Error: `only` tests are prohibited\n/);
42 tt.equal(err.code, 1);
43 });
44 }
45);
46
47tap.test(
48 'Should override NODE_TAPE_NO_ONLY_TEST env if --no-only is passed from cli',
49 { todo: expectedExitCodeFailure || expectedStackTraceBug ? 'Fails on these node versions' : false },
50 function (tt) {
51 tt.plan(3);
52
53 exec(tapeBin + ' --no-only "**/*.js"', {
54 cwd: path.join(__dirname, 'no_only'),
55 env: { PATH: process.env.PATH, NODE_TAPE_NO_ONLY_TEST: 'false' }
56 }, function (err, stdout, stderr) {
57 tt.same(stdout.toString('utf8'), '');
58 tt.match(stripFullStack(stderr.toString('utf8')).join('\n'), /Error: `only` tests are prohibited\n/);
59 tt.equal(err.code, 1);
60 });
61 }
62);
63
64tap.test('Should run successfully if there is no only test', function (tt) {
65 tt.plan(3);
66
67 exec(tapeBin + ' --no-only "**/test-a.js"', {
68 cwd: path.join(__dirname, 'no_only')
69 }, function (err, stdout, stderr) {
70 tt.match(stderr.toString('utf8'), /^\s*(\(node:\d+\) ExperimentalWarning: The ESM module loader is experimental\.)?\s*$/);
71 tt.same(stripFullStack(stdout.toString('utf8')), [
72 'TAP version 13',
73 '# should pass',
74 'ok 1 should be truthy',
75 '',
76 '1..1',
77 '# tests 1',
78 '# pass 1',
79 '',
80 '# ok',
81 '',
82 ''
83 ]);
84 tt.equal(err, null); // code 0
85 });
86});
87
88tap.test('Should run successfully if there is an only test and no --no-only flag', function (tt) {
89 tt.plan(3);
90
91 exec(tapeBin + ' "**/test-b.js"', {
92 cwd: path.join(__dirname, 'no_only')
93 }, function (err, stdout, stderr) {
94 tt.same(stripFullStack(stdout.toString('utf8')), [
95 'TAP version 13',
96 '# should pass again',
97 'ok 1 should be truthy',
98 '',
99 '1..1',
100 '# tests 1',
101 '# pass 1',
102 '',
103 '# ok',
104 '',
105 ''
106 ]);
107 tt.match(stderr.toString('utf8'), /^\s*(\(node:\d+\) ExperimentalWarning: The ESM module loader is experimental\.)?\s*$/);
108 tt.equal(err, null); // code 0
109 });
110});