Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

acquit-require

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

acquit-require

Pull examples from your test files into markdown or HTML

  • 0.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

acquit-require

Utility to pull mocha tests into markdown, HTML, etc.

transform()

This is the function you want to use. Given a string (markdown, HTML, Jade, etc.) and the raw source code of some mocha tests, this function returns a string with [require:bar] replaced with the source code of the first test that matches the regexp 'bar'.

Given the below markdown article:

Printing "Hello, World" in JavaScript is easy:

```
[require:bar]
```

This is how you print "Bye!" instead:

```
[require:baz]
```

And the below mocha test code:

describe('foo', function() {
  it('bar', function() {
    console.log('Hello, World!');
  });

  it('baz', function() {
    console.log('Bye!');
  });
});

The transform() function will pull the source code of the two tests into your markdown file.


  const output = transform(article, code);

  const logStatements = output.match(/console\.log(.*);/g);

  assert.ok(logStatements);
  assert.equal(logStatements[0].trim(), `console.log('Hello, World!');`);
  assert.equal(logStatements[1].trim(), `console.log('Bye!');`);

findTest()


  assert.equal(findTest('foo', code).trim(),
    `console.log('Hello, World!');`);
  assert.equal(findTest('bar', code).trim(),
    `console.log('Hello, World!');`);
  assert.equal(findTest('foo bar', code).trim(),
    `console.log('Hello, World!');`);
  assert.equal(findTest('baz', code).trim(),
    `console.log('Bye!');`);
  assert.ok(!findTest('bar baz', code));

FAQs

Package last updated on 11 Jun 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc