logo

tape-lite

tape shim based on node:test+node:assert with no dependencies git clone https://anongit.hacktivis.me/git/tape-lite.git/

index.js (5210B)


  1. // SPDX-FileCopyrightText: 2023 Haelwenn (lanodan) Monnier <contact+tape-lite@hacktivis.me>
  2. // SPDX-License-Identifier: MIT
  3. 'use strict';
  4. const test = require('node:test');
  5. function notOk(value, msg) { return assert.ok(!value, msg); };
  6. var onFailure = [];
  7. // test([name], [opts], cb)
  8. module.exports = function(name, opts, cb) {
  9. function setup_cb(t)
  10. {
  11. const assert = require('node:assert/strict');
  12. // t.plan(n)
  13. t.plan = (n) => console.log("t.plan called with:", n);
  14. // t.end(err)
  15. t.end = (err) => console.log("t.end called with:", err);
  16. // t.teardown(cb) → after([fn][, options])
  17. t.teardown = test.after;
  18. // t.fail(msg)
  19. t.fail = assert.fail;
  20. // t.pass(msg) → context.skip([message])
  21. // technically not the same thing but close enough
  22. t.pass = t.skip;
  23. // t.timeoutAfter(ms)
  24. // t.skip(msg) → context.skip([message])
  25. // t.ok(value, msg) → assert.ok(value[, message])
  26. // Aliases: t.true(), t.assert()
  27. t.ok = assert.ok;
  28. t.true = t.ok;
  29. t.assert = t.ok;
  30. // t.notOk(value, msg) → assert.ok(!value[, message])
  31. // Aliases: t.false(), t.notok()
  32. t.notOk = notOk;
  33. t.false = t.notOk;
  34. t.notok = t.notOk;
  35. // t.error(err, msg) → assert.ifError(value)
  36. // Aliases: t.ifError(), t.ifErr(), t.iferror()
  37. t.error = (err, msg) => assert.ifError(err);
  38. t.ifError = t.error;
  39. t.ifErr = t.error;
  40. t.iferror = t.error;
  41. // t.equal(actual, expected, msg) → assert.equal(actual, expected[, message])
  42. // Aliases: t.equals(), t.isEqual(), t.strictEqual(), t.strictEquals(), t.is()
  43. t.equal = assert.strictEqual;
  44. t.equals = t.equal;
  45. t.isEqual = t.equal;
  46. t.strictEqual = t.equal;
  47. t.strictEquals = t.equal;
  48. t.is = t.equal;
  49. // t.notEqual(actual, expected, msg) → assert.notStrictEqual(actual, expected[, message])
  50. // Aliases: t.notEquals(), t.isNotEqual(), t.doesNotEqual(), t.isInequal(), t.notStrictEqual(), t.notStrictEquals(), t.isNot(), t.not()
  51. t.notEqual = assert.notStrictEqual;
  52. t.notEquals = t.notEqual;
  53. t.doesNotEqual = t.notEqual;
  54. t.isInequal = t.notEqual;
  55. t.notStrictEqual = t.notEqual;
  56. t.notStrictEquals = t.notEqual;
  57. t.isNot = t.notEqual;
  58. t.not = t.notEqual;
  59. // t.looseEqual(actual, expected, msg) → assert.Equal(actual, expected[, message])
  60. // Aliases: t.looseEquals()
  61. t.looseEqual = assert.Equal;
  62. t.looseEquals = t.looseEqual;
  63. // t.notLooseEqual(actual, expected, msg) → assert.notEqual(actual, expected[, message])
  64. // Aliases: t.notLooseEquals()
  65. t.notLooseEqual = assert.notEqual;
  66. t.notLooseEquals = t.notLooseEqual;
  67. // t.deepEqual(actual, expected, msg) → assert.deepStrictEqual(actual, expected[, message])
  68. // Aliases: t.deepEquals(), t.isEquivalent(), t.same()
  69. t.deepEqual = assert.deepStrictEqual;
  70. t.deepEquals = t.deepEqual;
  71. t.isEquivalent = t.deepEqual;
  72. t.same = t.deepEqual;
  73. // t.notDeepEqual(actual, expected, msg) → assert.notDeepStrictEqual(actual, expected[, message])
  74. // Aliases: t.notDeepEquals, t.notEquivalent(), t.notDeeply(), t.notSame(), t.isNotDeepEqual(), t.isNotDeeply(), t.isNotEquivalent(), t.isInequivalent()
  75. t.notDeepEqual = assert.notDeepStrictEqual;
  76. t.notDeepEquals = t.notDeepEqual;
  77. t.notEquivalent = t.notDeepEqual;
  78. t.notDeeply = t.notDeepEqual;
  79. t.notSame = t.notDeepEqual;
  80. t.isNotDeepEqual = t.notDeepEqual;
  81. t.isNotDeeply = t.notDeepEqual;
  82. t.isNotEquivalent = t.notDeepEqual;
  83. t.isInequivalent = t.notDeepEqual;
  84. // t.deepLooseEqual(actual, expected, msg) → assert.deepEqual(actual, expected[, message])
  85. t.deepLooseEqual = assert.deepEqual;
  86. // t.notDeepLooseEqual(actual, expected, msg) → assert.notDeepEqual(actual, expected[, message])
  87. // Aliases: t.notLooseEqual(), t.notLooseEquals()
  88. t.notDeepLooseEqual = assert.notDeepEqual;
  89. t.notLooseEqual = t.notDeepLooseEqual;
  90. t.notLooseEquals = t.notDeepLooseEqual;
  91. // t.throws(fn, expected, msg) → assert.throws(fn[, error][, message])
  92. t.throws = assert.throws;
  93. // t.doesNotThrow(fn, expected, msg)
  94. // t.test(name, [opts], cb)
  95. // t.comment(message)
  96. t.comment = (msg) => console.log("t.comment called with:", msg);
  97. // t.match(string, regexp, message) → assert.match(string, regexp[, message])
  98. t.match = assert.match;
  99. // t.doesNotMatch(string, regexp, message) → assert.doesNotMatch(string, regexp[, message])
  100. t.doesNotMatch = assert.doesNotMatch;
  101. // npm:tap compatibility
  102. t.strictSame = t.same;
  103. };
  104. switch(arguments.length)
  105. {
  106. case 1:
  107. test((t) => {
  108. setup_cb(t);
  109. arguments[0](t)
  110. });
  111. break;
  112. case 2:
  113. test(arguments[0], (t) => {
  114. setup_cb(t);
  115. arguments[1](t)
  116. });
  117. break;
  118. case 3:
  119. test(arguments[0], arguments[1], (t) => {
  120. setup_cb(t);
  121. arguments[2](t)
  122. });
  123. break;
  124. default:
  125. abort();
  126. }
  127. };
  128. // test.skip([name], [opts], cb)
  129. // test.onFinish(fn)
  130. module.exports.onFinish = test.after;
  131. // test.onFailure(fn)
  132. module.exports.onFailure = (fn) => {
  133. onFailure.push(fn);
  134. // TODO: Call each on event:fail
  135. };
  136. // var htest = test.createHarness()
  137. // test.only([name], [opts], cb)
  138. // var stream = test.createStream(opts)