Full Code of juliangruber/tape-run for AI

master 885b7f433e75 cached
17 files
14.2 KB
4.5k tokens
1 symbols
1 requests
Download .txt
Repository: juliangruber/tape-run
Branch: master
Commit: 885b7f433e75
Files: 17
Total size: 14.2 KB

Directory structure:
gitextract_jkpx161j/

├── .github/
│   └── workflows/
│       └── ci.yml
├── .gitignore
├── .travis.yml
├── History.md
├── Makefile
├── README.md
├── bin/
│   └── run.js
├── example/
│   ├── api.js
│   └── coverify.sh
├── index.js
├── package.json
├── tea.yaml
└── test/
    ├── api.js
    ├── cli.js
    └── fixtures/
        ├── error.js
        ├── fail.js
        └── one.js

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

================================================
FILE: .github/workflows/ci.yml
================================================
name: CI
on:
  - push
  - pull_request
jobs:
  test:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        node: ['14', '16', '18']
    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-node@v2
        with:
          node-version: ${{ matrix.node }}
      - run: npm ci
      - run: xvfb-run npm test
        timeout-minutes: 5

================================================
FILE: .gitignore
================================================
node_modules
yarn.lock


================================================
FILE: .travis.yml
================================================
language: node_js
node_js:
  - 12
  - 14
addons:
  apt:
    packages:
      - xvfb
install:
  - export DISPLAY=':99.0'
  - Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 &
  - npm install


================================================
FILE: History.md
================================================

0.3.0 / 2014-08-13 
==================

 * bump browser-run for security reasons
 * add history

0.2.0 / 2014-07-13 
==================

 * ignore node_modules
 * update browser-run


================================================
FILE: Makefile
================================================

test:
	@node_modules/.bin/tape test/*.js

.PHONY: test



================================================
FILE: README.md
================================================

# tape-run

A [tape](https://github.com/substack/tape) test runner that runs your tests in
a (headless) browser and returns 0/1 as exit code, so you can use it as your
`npm test` script.

[![CI](https://github.com/juliangruber/tape-run/actions/workflows/ci.yml/badge.svg)](https://github.com/juliangruber/tape-run/actions/workflows/ci.yml)
[![downloads](https://img.shields.io/npm/dm/tape-run.svg)](https://www.npmjs.org/package/tape-run)

## Usage

First write a test utilizing [tape](https://github.com/substack/tape) and save
it to `test/test.js`:

```js
var test = require('tape');

test('a test', function (t) {
  t.ok(true);
  t.end();
});
```

Then run this command using tape-run and
[browserify](https://github.com/substack/node-browserify) and watch the magic happen
as the TAP results stream in from a browser (default: electron):

```bash
$ browserify test/*.js | tape-run
TAP version 13
# one
ok 1 true

1..1
# tests 1
# pass  1

# ok

$ echo $?
0
```

## rollup

In simple cases you can run `rollup` and `tape-run` right from command line:
```bash
$ rollup test/test.js -f iife  | tape-run
```
If you want to use a configuration file, here's an example for `rollup -c | tape-run`:
```js
import resolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';
import builtins from 'rollup-plugin-node-builtins';
import istanbul from 'rollup-plugin-istanbul';

export default {
  input: 'test/test.js',
  output: { format: 'iife', sourcemap: 'inline' },
  plugins: [
    resolve(),
    commonjs(),
    builtins(),
    istanbul({ exclude: ['dist'] })
  ]
}
```

## With webpack

To use with [webpack](https://webpack.github.io/), set up a `webpack.test.config.js` to bundle your tape tests. Then, include [webpack-tape-run](https://github.com/syarul/webpack-tape-run) plugin in it. As a result, `$ webpack --config webpack.test.config.js` builds your tests with webpack, runs them in a headless browser, and outputs tap into console with correct exit code. Neat!

## API

You can use tape-run from JavaScript too:

```js
var run = require('tape-run');
var browserify = require('browserify');

browserify(__dirname + '/test/test.js')
  .bundle()
  .pipe(run())
  .on('results', console.log)
  .pipe(process.stdout);
```

And run it:

```bash
$ node example/api.js
TAP version 13
# one
ok 1 true

1..1
# tests 1
# pass  1

# ok
{ ok: true,
  asserts: [ { ok: true, number: 1, name: 'true' } ],
  pass: [ { ok: true, number: 1, name: 'true' } ],
  fail: [],
  errors: [],
  plan: { start: 1, end: 1 } }
```

### run([opts])

`opts` can be:

* `wait (Number) [Default: 1000]`: Make `tap-finished` wait longer for results.
Increase this value if tests finish without all tests being run.
* `port (Number)`: If you specify a port it will wait for you to open a browser
on `http://localhost:<port>` and tests will be run there.
* `static (String)`: Serve static files from this directory.
* `browser (String)`: Browser to use. Defaults to `electron`. Available if installed:
  * `chrome`
  * `firefox`
  * `ie`
  * `phantom`
  * `safari`
* `keepOpen (Boolean)`: Leave the browser open for debugging after running tests.
* `node (Boolean)` Enable nodejs integration for electron.
* `sandbox (Boolean) [Default: true]`: Enable electron sandbox.
* `basedir` (String): Set this if you need to require node modules in `node` mode.

The **CLI** takes the same arguments, plus `--render` (see blow):

```bash
$ tape-run --help
Pipe a browserify stream into this.
browserify [opts] [files] | tape-run [opts]

Options:
  --wait       Timeout for tap-finished
  --port       Wait to be opened by a browser on that port
  --static     Serve static files from this directory
  --browser    Browser to use. Always available: electron. Available if installed: chrome, firefox, ie, phantom, safari  [default: "electron"]
  --render     Command to pipe tap output to for custom rendering
  --keep-open  Leave the browser open for debugging after running tests
  --node       Enable nodejs integration for electron
  --sandbox    Enable electron sandbox                                                                                   [default: true]
  --basedir    Set this if you need to require node modules in node mode
  --help       Print usage instructions
```

...or any of the [other options you can pass to browser-run](https://github.com/juliangruber/browser-run#runopts).

## Custom Rendering

In order to apply custom transformations to tap output without sacrificing the proper exit code, pass `--render` with a command like [tap-spec](https://npmjs.org/package/tap-spec):

```bash
$ browserify test.js | tape-run --render="tap-spec"

  one

    ✔ true

```

## Headless testing

In environments without a screen, you can use `Xvfb` to simulate one. We recommend using the default electron browser, 
which however requires you to add additional parts to your headless configurations.

### GitHub Actions

This is a full example to run `npm test`. Refer to the last 2 lines in the YAML config:

```yml
on:
  - pull_request
  - push

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4
    - run: npm install
    - run: xvfb-run npm test
      timeout-minutes: 5 # If the tests fails, the browser will hang open indefinitely
```

### Travis

Add this to your travis.yml:

```yml
addons:
  apt:
    packages:
      - xvfb
install:
  - export DISPLAY=':99.0'
  - Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 &
  - npm install
```

[Full example](https://github.com/rhysd/Shiba/blob/055a11a0a2b4f727577fe61371a88d8db9277de5/.travis.yml).

### Any gnu/linux box

```bash
$ sudo apt-get install xvfb # or equivalent
$ export DISPLAY=':99.0'
$ Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 &
$ browser-run ...
```

### Docker

There is also an example [Docker image](https://hub.docker.com/r/kipparker/docker-tape-run). [Source](https://github.com/fraserxu/docker-tape-run)

## Installation

With [npm](http://npmjs.org) do

```bash
$ npm install tape-run -g # for cli
$ npm install tape-run    # for api
```

## Sponsors

This module is proudly supported by my [Sponsors](https://github.com/juliangruber/sponsors)!

Do you want to support modules like this to improve their quality, stability and weigh in on new features? Then please consider donating to my [Patreon](https://www.patreon.com/juliangruber). Not sure how much of my modules you're using? Try [feross/thanks](https://github.com/feross/thanks)!

## Security contact information

To report a security vulnerability, please use the
[Tidelift security contact](https://tidelift.com/security).
Tidelift will coordinate the fix and disclosure.

## License

(MIT)

Copyright (c) 2013 Julian Gruber &lt;julian@juliangruber.com&gt;

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.


================================================
FILE: bin/run.js
================================================
#!/usr/bin/env node

var run = require('..');
var yargs = require('yargs/yargs');
var { hideBin } = require('yargs/helpers');
var spawn = require('child_process').spawn;

var argv = yargs(hideBin(process.argv))
  .usage('Pipe a browserify stream into this.\nbrowserify [opts] [files] | $0 [opts]')

  .option('wait', {
    alias: 'w',
    type: 'number',
    description: 'Timeout for tap-finished'
  })
  .option('port', {
    alias: 'p',
    type: 'number',
    description: 'Wait to be opened by a browser on that port'
  })
  .option('static', {
    alias: 's',
    type: 'string',
    description: 'Serve static files from this directory'
  })
  .option('browser', {
    alias: 'b',
    type: 'string',
    default: 'electron',
    description: 'Browser to use. ' +
    'Always available: electron. ' +
    'Available if installed: chrome, firefox, ie, phantom, safari'
  })
  .option('render', {
    alias: 'r',
    type: 'string',
    description: 'Command to pipe tap output to for custom rendering'
  })
  .option('keep-open', {
    alias: ['k', 'keepOpen'],
    type: 'boolean',
    description: 'Leave the browser open for debugging after running tests'
  })
  .option('node', {
    alias: ['n', 'node-integration', 'nodeIntegration'],
    type: 'boolean',
    description: 'Enable nodejs integration for electron'
  })
  .option('sandbox', {
    type: 'boolean',
    default: true,
    description: 'Enable electron sandbox'
  })
  .option('basedir', {
    description: 'Set this if you need to require node modules in node mode'
  })
  .parse();

var runner = run(argv);

process.stdin
  .pipe(runner)
  .on('results', function (results) {
    process.exit(Number(!results.ok));
  });

if (argv.render) {
  var ps = spawn(argv.render);
  runner.pipe(ps.stdin);
  ps.stdout.pipe(process.stdout, { end: false });
  ps.stderr.pipe(process.stderr, { end: false });
} else {
  runner.pipe(process.stdout);
}


================================================
FILE: example/api.js
================================================
var run = require('..');
var browserify = require('browserify');
var resolve = require('path').resolve;

var script = process.argv[2] || __dirname + '/../test/fixtures/one.js';
script = resolve(script);

browserify(script)
  .bundle()
  .pipe(run())
  .on('results', console.log)
  .pipe(process.stdout);


================================================
FILE: example/coverify.sh
================================================
#!/usr/bin/env bash
BIN="../node_modules/.bin"

$BIN/browserify -t coverify ../test/fixtures/one.js | ../bin/run.js | $BIN/coverify



================================================
FILE: index.js
================================================
var browserRun = require('browser-run')
var finished = require('@juliangruber/tap-finished');
var through = require('through');
var throughout = require('throughout');

module.exports = run;

function run (opts) {
  if (!opts) opts = {};

  var input = through();
  var browser = browserRun(opts);
  var dpl = throughout(input, browser);

  browser
    .pipe(finished(opts, function (results) {
      if(!opts.keepOpen) browser.stop();
      dpl.emit('results', results);
    }));

  return dpl;
}


================================================
FILE: package.json
================================================
{
  "name": "tape-run",
  "description": "Headless tape test runner",
  "version": "11.0.0",
  "repository": {
    "type": "git",
    "url": "git://github.com/juliangruber/tape-run.git"
  },
  "homepage": "https://github.com/juliangruber/tape-run",
  "main": "index.js",
  "scripts": {
    "test": "make test"
  },
  "bin": {
    "tape-run": "./bin/run.js"
  },
  "dependencies": {
    "@juliangruber/tap-finished": "0.0.2",
    "browser-run": "^12.0.0",
    "through": "^2.3.8",
    "throughout": "0.0.0",
    "yargs": "^17.4.1"
  },
  "devDependencies": {
    "browserify": "^14.0.0",
    "coverify": "^1.4.1",
    "tape": "^4.6.0"
  },
  "keywords": [
    "tape",
    "test",
    "tap",
    "runner",
    "phantomjs",
    "headless"
  ],
  "author": {
    "name": "Julian Gruber",
    "email": "mail@juliangruber.com",
    "url": "http://juliangruber.com"
  },
  "license": "MIT",
  "engines": {
    "node": ">=14"
  }
}


================================================
FILE: tea.yaml
================================================
# https://tea.xyz/what-is-this-file
---
version: 1.0.0
codeOwners:
  - '0xE7DEE1B8Bb97C3065850Cf582D6DED57C6009587'
quorum: 1


================================================
FILE: test/api.js
================================================
var test = require('tape');
var run = require('..');
var browserify = require('browserify');

test('api: one', function (t) {
  t.plan(1);

  browserify(__dirname + '/fixtures/one.js')
    .bundle()
    .pipe(run())
    .on('results', function (results) {
      t.equal(results.ok, true);
    })
});

test('api: fail', function (t) {
  t.plan(1);

  browserify(__dirname + '/fixtures/fail.js')
    .bundle()
    .pipe(run())
    .on('results', function (results) {
      t.equal(results.ok, false);
    });
});

test('api: error', function (t) {
  t.plan(1);

  browserify(__dirname + '/fixtures/error.js')
    .bundle()
    .pipe(run())
    .on('results', function (results) {
      t.equal(results.ok, false);
    });
});



================================================
FILE: test/cli.js
================================================
var test = require('tape');
var spawn = require('child_process').spawn;
var browserify = require('browserify');

test('cli: one', function (t) {
  t.plan(1);

  var run = spawn('node', [ __dirname + '/../bin/run.js' ]);
  run.stderr.pipe(process.stderr, { end: false });

  run.on('exit', function (code) {
    t.equals(code, 0);
  });

  browserify(__dirname + '/fixtures/one.js')
    .bundle()
    .pipe(run.stdin);
});

test('cli: fail', function (t) {
  t.plan(1);

  var run = spawn('node', [ __dirname + '/../bin/run.js' ]);
  run.stderr.pipe(process.stderr, { end: false });

  run.on('exit', function (code) {
    t.equals(code, 1);
  });

  browserify(__dirname + '/fixtures/fail.js')
    .bundle()
    .pipe(run.stdin);
});

test('cli: error', function (t) {
  t.plan(1);

  var run = spawn('node', [ __dirname + '/../bin/run.js' ]);
  run.stderr.pipe(process.stderr, { end: false });

  run.on('exit', function (code) {
    t.equals(code, 1);
  });

  browserify(__dirname + '/fixtures/error.js')
    .bundle()
    .pipe(run.stdin);
});


================================================
FILE: test/fixtures/error.js
================================================
var test = require('tape')

test('...', function (t) {
  t.ok(true);
  throw new Error('hmm')
  t.end()
})


================================================
FILE: test/fixtures/fail.js
================================================
var test = require('tape');

test('fail', function (t) {
  t.plan(1);
  t.ok(false);
});


================================================
FILE: test/fixtures/one.js
================================================
var test = require('tape');

test('one', function (t) {
  t.plan(1);
  t.ok(true, 'true');
});
Download .txt
gitextract_jkpx161j/

├── .github/
│   └── workflows/
│       └── ci.yml
├── .gitignore
├── .travis.yml
├── History.md
├── Makefile
├── README.md
├── bin/
│   └── run.js
├── example/
│   ├── api.js
│   └── coverify.sh
├── index.js
├── package.json
├── tea.yaml
└── test/
    ├── api.js
    ├── cli.js
    └── fixtures/
        ├── error.js
        ├── fail.js
        └── one.js
Download .txt
SYMBOL INDEX (1 symbols across 1 files)

FILE: index.js
  function run (line 8) | function run (opts) {
Condensed preview — 17 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (16K chars).
[
  {
    "path": ".github/workflows/ci.yml",
    "chars": 356,
    "preview": "name: CI\non:\n  - push\n  - pull_request\njobs:\n  test:\n    runs-on: ubuntu-latest\n    strategy:\n      matrix:\n        node"
  },
  {
    "path": ".gitignore",
    "chars": 23,
    "preview": "node_modules\nyarn.lock\n"
  },
  {
    "path": ".travis.yml",
    "chars": 189,
    "preview": "language: node_js\nnode_js:\n  - 12\n  - 14\naddons:\n  apt:\n    packages:\n      - xvfb\ninstall:\n  - export DISPLAY=':99.0'\n "
  },
  {
    "path": "History.md",
    "chars": 183,
    "preview": "\n0.3.0 / 2014-08-13 \n==================\n\n * bump browser-run for security reasons\n * add history\n\n0.2.0 / 2014-07-13 \n=="
  },
  {
    "path": "Makefile",
    "chars": 57,
    "preview": "\ntest:\n\t@node_modules/.bin/tape test/*.js\n\n.PHONY: test\n\n"
  },
  {
    "path": "README.md",
    "chars": 7770,
    "preview": "\n# tape-run\n\nA [tape](https://github.com/substack/tape) test runner that runs your tests in\na (headless) browser and ret"
  },
  {
    "path": "bin/run.js",
    "chars": 1916,
    "preview": "#!/usr/bin/env node\n\nvar run = require('..');\nvar yargs = require('yargs/yargs');\nvar { hideBin } = require('yargs/helpe"
  },
  {
    "path": "example/api.js",
    "chars": 305,
    "preview": "var run = require('..');\nvar browserify = require('browserify');\nvar resolve = require('path').resolve;\n\nvar script = pr"
  },
  {
    "path": "example/coverify.sh",
    "chars": 133,
    "preview": "#!/usr/bin/env bash\nBIN=\"../node_modules/.bin\"\n\n$BIN/browserify -t coverify ../test/fixtures/one.js | ../bin/run.js | $B"
  },
  {
    "path": "index.js",
    "chars": 498,
    "preview": "var browserRun = require('browser-run')\nvar finished = require('@juliangruber/tap-finished');\nvar through = require('thr"
  },
  {
    "path": "package.json",
    "chars": 924,
    "preview": "{\n  \"name\": \"tape-run\",\n  \"description\": \"Headless tape test runner\",\n  \"version\": \"11.0.0\",\n  \"repository\": {\n    \"type"
  },
  {
    "path": "tea.yaml",
    "chars": 126,
    "preview": "# https://tea.xyz/what-is-this-file\n---\nversion: 1.0.0\ncodeOwners:\n  - '0xE7DEE1B8Bb97C3065850Cf582D6DED57C6009587'\nquor"
  },
  {
    "path": "test/api.js",
    "chars": 725,
    "preview": "var test = require('tape');\nvar run = require('..');\nvar browserify = require('browserify');\n\ntest('api: one', function "
  },
  {
    "path": "test/cli.js",
    "chars": 1048,
    "preview": "var test = require('tape');\nvar spawn = require('child_process').spawn;\nvar browserify = require('browserify');\n\ntest('c"
  },
  {
    "path": "test/fixtures/error.js",
    "chars": 107,
    "preview": "var test = require('tape')\n\ntest('...', function (t) {\n  t.ok(true);\n  throw new Error('hmm')\n  t.end()\n})\n"
  },
  {
    "path": "test/fixtures/fail.js",
    "chars": 89,
    "preview": "var test = require('tape');\n\ntest('fail', function (t) {\n  t.plan(1);\n  t.ok(false);\n});\n"
  },
  {
    "path": "test/fixtures/one.js",
    "chars": 95,
    "preview": "var test = require('tape');\n\ntest('one', function (t) {\n  t.plan(1);\n  t.ok(true, 'true');\n});\n"
  }
]

About this extraction

This page contains the full source code of the juliangruber/tape-run GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 17 files (14.2 KB), approximately 4.5k tokens, and a symbol index with 1 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!