$ npm install @putout/plugin-tape
Tape-inspired TAP-compatible simplest high speed test runner with superpowers.
(c) πΌSupertape
πPutout plugin helps to apply best parctises for tests written with πΌSupertape.
npm i @putout/plugin-tape -D
{
"rules": {
"tape/add-args": "on",
"tape/add-t-end": "on",
"tape/apply-assertions-order": "on",
"tape/apply-destructuring": "on",
"tape/apply-stringify": "on",
"tape/apply-stub": "on",
"tape/apply-with-name": "on",
"tape/convert-called-with-args": "on",
"tape/convert-called-with-no-args-to-called-with": "on",
"tape/convert-called-with-to-called-with-no-args": "on",
"tape/convert-deep-equal-to-equal": "on",
"tape/convert-does-not-throw-to-try-catch": "on",
"tape/convert-emitter-to-promise": "on",
"tape/convert-equal-length-to-match-string": "on",
"tape/convert-equal-to-called-once": "on",
"tape/convert-equal-to-deep-equal": "on",
"tape/convert-equals-to-equal": "on",
"tape/convert-match-regexp-to-string": "on",
"tape/convert-ok-to-called-with": "on",
"tape/convert-ok-to-match": "on",
"tape/convert-ok-to-pass": "on",
"tape/convert-tape-to-supertape": "on",
"tape/convert-throws-to-try-catch": "on",
"tape/declare": "on",
"tape/extract-args-from-called-with": "on",
"tape/extract-result-from-assertion": "on",
"tape/jest": "on",
"tape/remove-default-messages": "on",
"tape/remove-only": ["on", {
"allowed": ["test"]
}],
"tape/remove-skip": ["on", {
"allowed": ["test"]
}],
"tape/remove-t-from-async": "on",
"tape/remove-useless-not-called-args": "on",
"tape/remove-useless-t-end": "on",
"tape/remove-useless-undefined": "on",
"tape/switch-expected-with-result": "on",
"tape/sync-with-name": "on"
}
}
test('xxx', () => {
t.end();
});
test('hello: world', async () => {
const result = await get();
deepEqual(result, []);
});
test('xxx', (t) => {
t.end();
});
test('hello: world', async ({deepEqual}) => {
const result = await get();
deepEqual(result, []);
});
test('xxx', () => {});
test('xxx', (t) => {
t.end();
});
Check out in πPutout Editor.
t.equal(result, expected);
cleanup();
t.end();
cleanup();
t.equal(result, expected);
t.end();
Check out in πPutout Editor.
const test = require('supertape');
const {test} = require('supertape');
Checkout in πPutout Editor
const read = stub().returns('{"checkCoverage": true}');
const read = stub().returns(stringify({
checkCoverage: true,
}));
Apply stub functions created. Look how it works in πPutout Editor.
const a = async () => true;
const b = async () => {};
const c = async () => throwError('hello');
const d = async () => {
throw Error('hello');
};
const a = stub().resolves(true);
const b = stub().resolves();
const c = stub().rejects(Error('hello'));
const d = stub().rejects(Error('hello'));
test('should call init before show', (t) => {
const init = stub();
const show = stub();
t.calledInOrder([init, show]);
t.end();
});
test('should call init before show', (t) => {
const init = stub().withName('init');
const show = stub().withName('show');
t.calledInOrder([init, show]);
t.end();
});
const test = require('supertape');
const {stub} = test;
test('some message', (t) => {
const fn = stub();
fn();
t.calledWith(fn, 'hello');
t.end();
});
const test = require('supertape');
const {stub} = test;
test('some message', (t) => {
const fn = stub();
fn();
t.calledWith(fn, ['hello']);
t.end();
});
const test = require('supertape');
const {stub} = test;
test('some message', (t) => {
const fn = stub();
fn();
t.calledWithNoArgs(fn, [1, 2]);
t.end();
});
const test = require('supertape');
const {stub} = test;
test('some message', (t) => {
const fn = stub();
fn();
t.calledWith(fn, [1, 2]);
t.end();
});
const test = require('supertape');
const {stub} = test;
test('some message', (t) => {
const fn = stub();
fn();
t.calledWith(fn);
t.end();
});
const test = require('supertape');
const {stub} = test;
test('some message', (t) => {
const fn = stub();
fn();
t.calledWithNoArgs(fn);
t.end();
});
Use equal when comparing with primitives, deepEqual for Objects and Arrays;
const test = require('supertape');
const {stub} = test;
test('some message', (t) => {
t.deepEqual(x, 5);
t.end();
});
const test = require('supertape');
const {stub} = test;
test('some message', (t) => {
t.equal(x, 5);
t.end();
});
const test = require('supertape');
test('some message', (t) => {
t.doesNotThrow(copymitter, 'should throw when no args');
t.end();
});
const test = require('supertape');
const {tryCatch} = require('try-catch');
test('some test', (t) => {
const [error] = tryCatch(copymitter);
t.notOk(error, 'should not throw when no args');
t.end();
});
test('copymitter', (t) => {
const cp = copymitter(from, to, ['1']);
cp.on('end', (t) => {
t.end();
});
});
const {once} = require('node:events');
test('copymitter', async (t) => {
const cp = copymitter(from, to, ['1']);
await once(cp, 'end');
t.end();
});
Checkout in πPutout Editor.
test('hello: world', (t) => {
const count = (written.match(/## my-rule/) || []).length;
t.equal(count, 1);
t.end();
});
test('hello: world', (t) => {
t.match(written, /## my-rule/);
t.end();
});
No need to use equal, supertape supports calledOnce.
const test = require('supertape');
const {stub} = test;
test('some message', (t) => {
const fn = stub();
fn();
t.equal(fn.callCount, 1);
t.end();
});
const test = require('supertape');
const {stub} = test;
test('some message', (t) => {
const fn = stub();
fn();
t.calledOnce(fn);
t.end();
});
const expected = {
hello: 'world',
};
t.equal(error, expected);
t.end();
const expected = {
hello: 'world',
};
t.deepEqual(error, expected);
t.end();
t.equal(error, null);
t.notOk(error);
t.equal(result, true);
t.ok(result);
Checkout in πPutout Editor.
t.equals(e.message, 'token should be a string!', 'should throw');
t.equal(e.message, 'token should be a string!', 'should throw');
t.match(result, RegExp('hello'));
t.match(result, 'hello');
t.ok(set.calledWith(1, 2));
t.calledWith(set, [1, 2]);
t.ok(result.includes('hello'));
t.match(result, /hello/);
const test = require('tape');
const test = require('supertape');
const test = require('supertape');
test('some message', (t) => {
t.throws(copymitter, /from should be a string!/, 'should throw when no args');
t.end();
});
const {tryCatch} = require('try-catch');
const test = require('supertape');
test('some message', (t) => {
const [error] = tryCatch(copymitter);
t.equal(error.message, 'from should be a string!');
t.end();
});
test('xxx', (t) => {
const a = stub();
t.end();
});
import {test, stub} from 'supertape';
test('xxx', (t) => {
const a = stub();
t.end();
});
Checkout in πPutout Editor.
test('abc: def', (t) => {
t.calledWith(executeFn, [
['tape', 'test.js'], {
exit,
},
]);
});
test('abc: def', (t) => {
const args = [
['tape', 'test.js'], {
exit,
},
];
t.calledWith(executeFn, args);
});
Checkout in πPutout Editor.
t.notOk(screen.getByRole('button').disabled);
t.deepEqual(readState({
getItem,
}), {
a: 1,
});
const {disabled} = screen.getByRole('button');
t.notOk(disabled);
const result = readState({
getItem,
});
const expected = {
a: 1,
};
t.deepEqual(result, expected);
πPutout gives ability to switch easily from Jest to πΌSupertape. Checkout in πPutout Editor.
it('should equal', () => {
expect(a).toEqual(b);
});
import {test} from 'supertape';
test('should equal', () => {
t.equal(a, b);
t.end();
});
πΌSupertape will put this information for you, and it is always the same. No need to repeat the same information twice on one line, better to avoid it.
t.equal(result, expected, 'should equal');
t.equal(result, expected);
test.only('some test', (t) => {
t.end();
});
testDeclareBeforeReference.only('some test', (t) => {
t.end();
});
test('some test', (t) => {
t.end();
});
testDeclareBeforeReference('some test', (t) => {
t.end();
});
test.skip('some test', (t) => {
t.end();
});
test('some test', (t) => {
t.end();
});
test('sqlite: all returns empty array', async (t) => {
const db = await createDb();
await db.exec('CREATE TABLE t (id INTEGER PRIMARY KEY, x TEXT)');
const rows = await db.all('SELECT x FROM t WHERE x = :x', {
x: 'missing',
});
await t.dbAll(rows, []);
t.end();
});
test('sqlite: all returns empty array', async ({dbAll}) => {
const db = await createDb();
await db.exec('CREATE TABLE t (id INTEGER PRIMARY KEY, x TEXT)');
const rows = await db.all('SELECT x FROM t WHERE x = :x', {
x: 'missing',
});
await dbAll(rows, []);
});
t.notCalled(fn, []);
t.notCalled(fn);
test('test: remove me', () => {
t.end();
t.end();
});
test('test: remove me', () => {
t.end();
});
stub().returns(undefined);
stub().resolves(undefined);
stub();
stub().resolves();
πΌSupertape uses more natural way of
comparing: first you pass result and then expected.
It gives you ability to use value instead of expected and
understand code faster: no need to search for a second argument.
While result is always a variable, so it most likely much shorter.
test('plugin-apply-destructuring: transform: array: destructuring', (t) => {
t.equal(expected, result);
t.end();
});
test('plugin-apply-destructuring: transform: array: destructuring', (t) => {
t.equal(result, expected);
t.end();
});
test('should call init before show', (t) => {
const init = stub().withName('show');
const show = stub().withName('show');
t.calledInOrder([init, show]);
t.end();
});
test('should call init before show', (t) => {
const init = stub().withName('init');
const show = stub().withName('show');
t.calledInOrder([init, show]);
t.end();
});
Checkout in πPutout Editor.
t.ok(true);
t.pass();
MIT
© 2010 - cnpmjs.org x YWFE | Home | YWFE