Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

@putout/plugin-tape

Package Overview
Dependencies
Maintainers
1
Versions
108
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@putout/plugin-tape

putout plugin helps with tests

Source
npmnpm
Version
2.3.0
Version published
Weekly downloads
17K
23.74%
Maintainers
1
Weekly downloads
 
Created
Source

@putout/plugin-tape NPM version Dependency Status

putout plugin helps to apply best parctises for tests written with supertape.

Install

npm i @putout/plugin-tape -D

Rules

{
    "rules": {
        "tape/switch-expected-with-result": "on",
        "tape/convert-tape-to-supertape": "on",
        "tape/convert-throws-to-try-catch": "on",
        "tape/convert-does-not-throw-to-try-catch": "on",
        "tape/convert-called-with-to-called-with-no-args": "on",
        "tape/expand-try-catch-arguments": "on",
        "tape/apply-stub-operator": "on",
        "tape/convert-emitter-to-promise": "on",
        "tape/convert-ok-to-match": "on"
    }
}

switch-expected-with-result

❌ Incorrect code example

test('plugin-apply-destructuring: transform: array: destructuring', (t) => {
    t.eqaul(expected, result);
    t.end();
});

✅ Correct code Example

test('plugin-apply-destructuring: transform: array: destructuring', (t) => {
    t.eqaul(result, expected);
    t.end();
});

convert-tape-to-supertape

❌ Incorrect code example

const test = require('tape');

✅ Correct code Example

const test = require('supertape');

convert-throws-to-try-catch

❌ Incorrect code example

const test = require('supertape');

test('some message', (t) => {
    t.throws(copymitter, /from should be a string!/, 'should throw when no args');
    t.end();
});

✅ Correct code Example

const tryCatch = require('try-catch');
const test = require('supertape');

test('some message', (t) => {
    const [error] = tryCatch(copymitter);
    
    t.equal(error.message, 'from shoulde be a string!', 'should throw when no args');
    t.end();
});

convert-does-not-throw-to-try-catch

❌ Incorrect code example

const test = require('supertape');

test('some message', (t) => {
    t.doesNotThrow(copymitter, 'should throw when no args');
    t.end();
});

✅ Correct code Example

const tryCatch = require('try-catch');
const test = require('supertape');

test('some message', (t) => {
    const [error] = tryCatch(copymitter);
    
    t.nottOk(error, 'should throw when no args');
    t.end();
});

convert-called-with-to-called-with-no-args

❌ Incorrect code example

const test = require('supertape');
const {stub} = test;

test('some message', (t) => {
    const fn = stub();
    
    fn();
    
    t.calledWith(fn);
    t.end();
});

✅ Correct code Example

const test = require('supertape');
const {stub} = test;

test('some message', (t) => {
    const fn = stub();
    
    fn();
    
    t.calledWithNoArgs(fn);
    t.end();
});

convert-emitter-to-promise

❌ Incorrect code example

test('copymitter', (t) => {
    const cp = copymitter(from, to, ['1']);
    
    cp.on('end', (t) => {
        t.end();
    });
});

✅ Correct code Example

const {once} = require('events');
test('copymitter', async (t) => {
    const cp = copymitter(from, to, ['1']);
    
    await once(cp, 'end');
    t.end();
});

expand-try-catch-arguments

❌ Incorrect code example

import tryCatch from 'try-catch';
test('some message', (t) => {
    const fn = () => copymitter('/hello');
    const [error] = tryCatch(fn);
    
    t.equal(error.message, 'to should be a string!');
    t.end();
});

✅ Correct code Example

import tryCatch from 'try-catch';
test('some message', (t) => {
    const [error] = tryCatch(copymitter, '/hello');
    
    t.equal(error.message, 'to should be a string!');
    t.end();
});

apply-stub-operator

❌ Incorrect code example

test('some message', (t) => {
    t.ok(fn.calledWith(a));
    t.end();
});

✅ Correct code Example

test('some message', (t) => {
    t.calledWith(fn, [a]);
    t.end();
});

declare-stub

❌ Incorrect code example

const test = require('supertape');

test('xxx', (t) => {
    const a = stub();
    
    t.end();
});

✅ Correct code Example

const {test, stub} = require('supertape');

test('xxx', (t) => {
    const a = stub();
    
    t.end();
});

convert-ok-to-match

❌ Incorrect code example

t.ok(result.includes('hello'));

✅ Correct code Example

t.match(result, /hello/);

convert-equal-to-not-ok

❌ Incorrect code example

t.equal(error, null);

✅ Correct code Example

t.notOk(error);

License

MIT

Keywords

putout

FAQs

Package last updated on 29 Apr 2021

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