
Security News
PEP 810 Proposes Explicit Lazy Imports for Python 3.15
An opt-in lazy import keyword aims to speed up Python startups, especially CLIs, without the ecosystem-wide risks that sank PEP 690.
@putout/plugin-tape
Advanced tools
Putout
plugin helps to apply best parctises for tests written with supertape.
npm i @putout/plugin-tape -D
{
"rules": {
"tape/apply-stub-operator": "on",
"tape/apply-with-name": "on",
"tape/add-t-end": "on",
"tape/add-stop-all": "on",
"tape/remove-useless-t-end": "on",
"tape/sync-with-name": "on",
"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-args": "on",
"tape/convert-called-with-to-called-with-no-args": "on",
"tape/convert-called-with-no-args-to-called-with": "on",
"tape/convert-equal-to-called-once": "on",
"tape/convert-deep-equal-to-equal": "on",
"tape/expand-try-catch-arguments": "on",
"tape/convert-emitter-to-promise": "on",
"tape/convert-ok-to-match": "on",
"tape/convert-ok-to-called-with": "on",
"tape/convert-match-regexp-to-string": "on",
"tape/add-args": "on",
"tape/declare": "on",
"tape/remove-default-messages": "on",
"tape/remove-useless-not-called-args": "on",
"tape/remove-only": "on",
"tape/remove-skip": "on"
}
}
test('plugin-apply-destructuring: transform: array: destructuring', (t) => {
t.eqaul(expected, result);
t.end();
});
test('plugin-apply-destructuring: transform: array: destructuring', (t) => {
t.eqaul(result, expected);
t.end();
});
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 shoulde be a string!', 'should throw when no args');
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();
});
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();
});
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();
});
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');
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();
});
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();
});
test('copymitter', (t) => {
const cp = copymitter(from, to, ['1']);
cp.on('end', (t) => {
t.end();
});
});
const {once} = require('events');
test('copymitter', async (t) => {
const cp = copymitter(from, to, ['1']);
await once(cp, 'end');
t.end();
});
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();
});
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();
});
test('some message', (t) => {
t.ok(fn.calledWith(a));
t.end();
});
test('some message', (t) => {
t.calledWith(fn, [a]);
t.end();
});
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();
});
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();
});
test('xxx', (t) => {
const a = stub();
t.end();
});
import {
test,
stub,
} from 'supertape';
test('xxx', (t) => {
const a = stub();
t.end();
});
test('xxx', () => {
t.end();
});
test('xxx', (t) => {
t.end();
});
test('xxx', () => {
});
test('xxx', (t) => {
t.end();
});
When you write test mocking ESM
with mockImport()
never forget to call stopAll()
when you no longer need it. This leads to bugs in tests which are hard to find, each test should be checked with the one which pass when called alone but fail when called with others.
test('stop-all: should be called', () => {
mockImport('fs/promises', {
readFile: stub(),
});
t.end();
});
test('stop-all: should be called', () => {
mockImport('fs/promises', {
readFile: stub(),
});
stopAll();
t.end();
});
test('test: remove me', () => {
t.end();
t.end();
});
test('test: remove me', () => {
t.end();
});
t.ok(result.includes('hello'));
t.match(result, /hello/);
t.ok(set.calledWith(1, 2));
t.calledWith(set, [1, 2]);
t.equal(error, null);
t.notOk(error);
t.equal(result, true);
t.ok(result);
t.match(result, RegExp('hello'));
t.match(result, 'hello');
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);
t.notCalled(fn, []);
t.notCalled(fn);
test.only('some test', (t) => {
t.end();
});
test('some test', (t) => {
t.end();
});
test.skip('some test', (t) => {
t.end();
});
test('some test', (t) => {
t.end();
});
MIT
FAQs
🐊Putout plugin helps with tests
The npm package @putout/plugin-tape receives a total of 16,866 weekly downloads. As such, @putout/plugin-tape popularity was classified as popular.
We found that @putout/plugin-tape demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
An opt-in lazy import keyword aims to speed up Python startups, especially CLIs, without the ecosystem-wide risks that sank PEP 690.
Security News
Socket CEO Feross Aboukhadijeh discusses the recent npm supply chain attacks on PodRocket, covering novel attack vectors and how developers can protect themselves.
Security News
Maintainers back GitHub’s npm security overhaul but raise concerns about CI/CD workflows, enterprise support, and token management.