Full Code of spion/blue-tape for AI

master 166a86de731e cached
8 files
6.3 KB
2.1k tokens
6 symbols
1 requests
Download .txt
Repository: spion/blue-tape
Branch: master
Commit: 166a86de731e
Files: 8
Total size: 6.3 KB

Directory structure:
gitextract_nw7nc_0v/

├── .github/
│   └── ISSUE_TEMPLATE/
│       └── project-not-maintained.md
├── .gitignore
├── .npmignore
├── README.md
├── bin/
│   └── blue-tape.js
├── blue-tape.js
├── package.json
└── test/
    └── index.js

================================================
FILE CONTENTS
================================================

================================================
FILE: .github/ISSUE_TEMPLATE/project-not-maintained.md
================================================
---
name: Project not maintained
about: This project is no longer maintained
title: ''
labels: ''
assignees: ''

---

The best option is to switch to a library that supports promises - either https://github.com/jprichardson/tape-promise or https://www.node-tap.org/ - or perhaps its time to revisit substack/tape/issues/262 and add promise support to tape.


================================================
FILE: .gitignore
================================================
node_modules


================================================
FILE: .npmignore
================================================
test
.gitignore


================================================
FILE: README.md
================================================
#### This project is no longer maintained.

The best option is to switch to a library that supports promises - either https://github.com/jprichardson/tape-promise or https://github.com/tapjs/node-tap - or perhaps its time to revisit https://github.com/substack/tape/issues/262 and add promise support to tape.

--------------

# blue-tape

Tape with promise support.

### Usage

Same as [tape](https://github.com/substack/tape), except if you return a promise from a test,
it will be checked for errors. If there are no errors, the test will end. Otherwise the test
will fail. This means there is no need to use `t.plan()` or `t.end()`.

Also provides `t.shouldFail(promise P, optional class|regex expected, optional message)` (as
well as the alias `shouldReject`) which returns a new promise that resolves successfully if `P`
rejects. If you provide the optional class, or regex then it additionally ensures that `err` is
an instance of that class or that the message matches the regular expression. The behaviour is
identical to tape's `throws` assertion.

### Examples

Assuming `delay()` returns a promise:

```js
const test = require('blue-tape');

test("simple delay", function(t) {
    return delay(1);
});

test("should fail", function(t) {
    return delay(1).then(function() {
        throw new Error("Failed!");
    });
});
```

Assuming `failDelay()` returns a promise that rejects with a DerpError:

```js
test("promise fails but test succeeds", function(t) {
    return t.shouldFail(failDelay(), DerpError);
});
```

### License

MIT


================================================
FILE: bin/blue-tape.js
================================================
#!/usr/bin/env node

require('tape/bin/tape')


================================================
FILE: blue-tape.js
================================================
var Test = require('tape/lib/test')

function checkPromise (p) {
  return p && p.then && typeof p.then === 'function'
}

Test.prototype.run = function () {
  if (this._skip) {
    return this.end()
  }
  this.emit('prerun')
  try {
    var p = this._cb && this._cb(this)
    var isPromise = checkPromise(p)
    var self = this
    if (isPromise) {
      p.then(function () {
        self.end()
      }, function (err) {
        err ? self.error(err) : self.fail(err)
        self.end()
      })
    }
  } catch (err) {
    if (err) {
      this.error(err)
    } else {
      this.fail(err)
    }
    this.end()
    return
  }
  this.emit('run')
}

function noop() {}

Test.prototype.shouldFail =
Test.prototype.shouldReject =
function (promise, expected, message, extra) {
  var self = this
  return promise.then(function () {
    self.throws(noop, expected, message, extra)
  }, function (err) {
    function f() {throw err}
    self.throws(f, expected, message, extra)
  })
}


module.exports = require('tape')


================================================
FILE: package.json
================================================
{
  "name": "blue-tape",
  "version": "1.0.0",
  "description": "Tape test runner with promise support",
  "main": "blue-tape.js",
  "bin": {
    "blue-tape": "./bin/blue-tape.js"
  },
  "scripts": {
    "test": "standard && node test/index.js"
  },
  "keywords": [
    "tape",
    "bluebird",
    "promises"
  ],
  "author": "spion",
  "license": "MIT",
  "dependencies": {
    "tape": ">=2.0.0 <5.0.0"
  },
  "directories": {
    "test": "test"
  },
  "repository": {
    "type": "git",
    "url": "git://github.com/spion/blue-tape.git"
  },
  "bugs": {
    "url": "https://github.com/spion/blue-tape/issues"
  },
  "devDependencies": {
    "bl": "^4.0.3",
    "bluebird": "^2.1.2",
    "standard": "*"
  }
}


================================================
FILE: test/index.js
================================================
var tape = require('../blue-tape')
var bl = require('bl')
var P = require('bluebird')
P.longStackTraces()

function test (name, test, checkErrors) {
  tape.test(name, function (t) {
    var htest = tape.createHarness()
    htest.createStream().pipe(bl(function (_, data) {
      checkErrors && checkErrors(data.toString().split('\n'), t)
    }))
    htest(function (t) {
      return test(t, htest)
    })
  })
}

function verifyAsserts (counts) {
  return function (lines, t) {
    t.equal(count(lines, /^ok/), counts.ok, 'should have ' + counts.ok + ' ok asserts')
    t.equal(count(lines, /^not ok/), counts.fail, 'should have ' + counts.fail + ' failed asserts')
    t.end()
  }
}

function count (lines, regex) {
  var c = 0
  for (var k = 0; k < lines.length; ++k) {
    if (regex.test(lines[k])) {
      ++c
    }
  }
  return c
}

test('non-promise test', function (t) {
  t.ok(true)
  t.end()
},
  verifyAsserts({ok: 1, fail: 0}))

test('simple delay', function (t) {
  return P.delay(1)
},
  verifyAsserts({ok: 0, fail: 0}))

test('should not affect plan', function (t) {
  t.plan(2)
  t.ok(true)
  t.ok(true)
  return P.delay(1)
},
  verifyAsserts({ok: 2, fail: 0}))

test('nested tests with promises', function (t) {
  t.test('delay1', function (t) {
    return P.delay(1)
  })
  t.test('delay2', function () {
    return P.delay(1)
  })
},
  verifyAsserts({ok: 0, fail: 0}))

test('should error', function (t) {
  return P.delay(1).then(function () {
    throw new Error('Failed!')
  })
},
  verifyAsserts({ok: 0, fail: 1}))

test('should fail', function (t) {
  return P.delay(1).then(function () {
    return P.reject()
  })
},
  verifyAsserts({ok: 0, fail: 1}))

test('run test with only', function (t, htest) {
  var count = 0
  htest('first', function (t) {
    t.equal(++count, 1)
    t.end()
  })
  htest.only('second', function (t) {
    t.equal(++count, 1)
    t.end()
  })
  t.end()
},
  verifyAsserts({ok: 1, fail: 0}))

test('test that expects promise to fail', function (t) {
  return t.shouldFail(P.delay(1).then(function () {
    return P.reject(new Error("Test"))
  }))
},
  verifyAsserts({ok: 1, fail: 0}))

test('test that expects promise to fail, but it succeeds', function (t) {
  return t.shouldFail(P.delay(1).then(function () {
    return P.resolve()
  }))
},
  verifyAsserts({ok: 0, fail: 1}))

test('test that expects specific exception', function (t) {
  return t.shouldFail(P.delay(1).then(function () {
    var f = 5
    f.toFixed(100) // RangeError
  }), RangeError)
},
  verifyAsserts({ok: 1, fail: 0}))

test('test that expects wrong exception', function (t) {
  return t.shouldFail(P.delay(1).then(function () {
    var f = 5
    f.toFixed(100) // RangeError
  }), SyntaxError)
},
  verifyAsserts({ok: 0, fail: 1}))
Download .txt
gitextract_nw7nc_0v/

├── .github/
│   └── ISSUE_TEMPLATE/
│       └── project-not-maintained.md
├── .gitignore
├── .npmignore
├── README.md
├── bin/
│   └── blue-tape.js
├── blue-tape.js
├── package.json
└── test/
    └── index.js
Download .txt
SYMBOL INDEX (6 symbols across 2 files)

FILE: blue-tape.js
  function checkPromise (line 3) | function checkPromise (p) {
  function noop (line 36) | function noop() {}
  function f (line 45) | function f() {throw err}

FILE: test/index.js
  function test (line 6) | function test (name, test, checkErrors) {
  function verifyAsserts (line 18) | function verifyAsserts (counts) {
  function count (line 26) | function count (lines, regex) {
Condensed preview — 8 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (7K chars).
[
  {
    "path": ".github/ISSUE_TEMPLATE/project-not-maintained.md",
    "chars": 357,
    "preview": "---\nname: Project not maintained\nabout: This project is no longer maintained\ntitle: ''\nlabels: ''\nassignees: ''\n\n---\n\nTh"
  },
  {
    "path": ".gitignore",
    "chars": 13,
    "preview": "node_modules\n"
  },
  {
    "path": ".npmignore",
    "chars": 16,
    "preview": "test\n.gitignore\n"
  },
  {
    "path": "README.md",
    "chars": 1548,
    "preview": "#### This project is no longer maintained.\n\nThe best option is to switch to a library that supports promises - either ht"
  },
  {
    "path": "bin/blue-tape.js",
    "chars": 46,
    "preview": "#!/usr/bin/env node\n\nrequire('tape/bin/tape')\n"
  },
  {
    "path": "blue-tape.js",
    "chars": 1013,
    "preview": "var Test = require('tape/lib/test')\n\nfunction checkPromise (p) {\n  return p && p.then && typeof p.then === 'function'\n}\n"
  },
  {
    "path": "package.json",
    "chars": 711,
    "preview": "{\n  \"name\": \"blue-tape\",\n  \"version\": \"1.0.0\",\n  \"description\": \"Tape test runner with promise support\",\n  \"main\": \"blue"
  },
  {
    "path": "test/index.js",
    "chars": 2761,
    "preview": "var tape = require('../blue-tape')\nvar bl = require('bl')\nvar P = require('bluebird')\nP.longStackTraces()\n\nfunction test"
  }
]

About this extraction

This page contains the full source code of the spion/blue-tape GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 8 files (6.3 KB), approximately 2.1k tokens, and a symbol index with 6 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.

Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.

Copied to clipboard!