Software: Apache/2.4.41 (Ubuntu). PHP/8.0.30 uname -a: Linux apirnd 5.4.0-204-generic #224-Ubuntu SMP Thu Dec 5 13:38:28 UTC 2024 x86_64 uid=33(www-data) gid=33(www-data) groups=33(www-data) Safe-mode: OFF (not secure) /usr/local/share/.cache/yarn/v6/npm-tape-5.6.1-integrity/node_modules/tape/test/ drwxr-xr-x | |
| Viewing file: Select action/file-type: 'use strict';
var tap = require('tap');
var forEach = require('for-each');
var tape = require('../');
var concat = require('concat-stream');
/**
* extract the stack trace for the failed test.
* this will change dependent on the environment
* so no point hard-coding it in the test assertion
* see: https://git.io/v6hGG for example
* @param String rows - the tap output lines
* @returns String stacktrace - just the error stack part
*/
function getStackTrace(rows) {
var stacktrace = ' ---\n';
var extract = false;
forEach(rows.toString('utf8').split('\n'), function (row) {
if (!extract) {
if (row.indexOf('---') > -1) { // start of stack trace
extract = true;
}
} else if (row.indexOf('...') > -1) { // end of stack trace
extract = false;
stacktrace += ' ...';
} else {
stacktrace += row + '\n';
}
});
// console.log(stacktrace);
return stacktrace;
}
function fakeAsyncTask(name, cb) {
cb(null, 'task' + name);
}
function fakeAsyncWrite(name, cb) {
cb(null);
}
function fakeAsyncWriteFail(name, cb) {
cb(new Error('fail'));
}
tap.test('tape assert.end as callback', function (tt) {
var test = tape.createHarness({ exit: false });
test.createStream().pipe(concat(function (rows) {
tt.equal(rows.toString('utf8'), [
'TAP version 13',
'# do a task and write',
'ok 1 null',
'ok 2 should be strictly equal',
'# do a task and write fail',
'ok 3 null',
'ok 4 should be strictly equal',
'not ok 5 Error: fail',
getStackTrace(rows), // tap error stack
'',
'1..5',
'# tests 5',
'# pass 4',
'# fail 1'
].join('\n') + '\n');
tt.end();
}));
test('do a task and write', function (assert) {
fakeAsyncTask('foo', function (err, value) {
assert.ifError(err);
assert.equal(value, 'taskfoo');
fakeAsyncWrite('bar', assert.end);
});
});
test('do a task and write fail', function (assert) {
fakeAsyncTask('bar', function (err, value) {
assert.ifError(err);
assert.equal(value, 'taskbar');
fakeAsyncWriteFail('baz', assert.end);
});
});
});
|
:: Command execute :: | |
--[ c99shell v. 2.5 [PHP 8 Update] [24.05.2025] | Generation time: 0.007 ]-- |