
Product
Announcing Precomputed Reachability Analysis in Socket
Socket’s precomputed reachability slashes false positives by flagging up to 80% of vulnerabilities as irrelevant, with no setup and instant results.
Enable rollback for your tests that use knex.
Knest works with most test frameworks out there.
npm install knest --save-dev
Example using mocha as the testing framework
This example is part of the knex mocha tests. They can be run using the following npm script.
const assert = require('assert')
const {
mysql,
users,
resetDatabase,
findUsers,
createUsers,
createUser
} = require('./index.spec')
const knest = require('./index').bind(null, mysql)
describe('Mocha & Knest', () => {
it('should reset the database user table', () => resetDatabase(mysql))
it('should create user in user table', () =>
knest(trx =>
createUser(trx, users[0]).then(record => {
assert.strictEqual(record.name, users[0].name)
assert.strictEqual(record.email, users[0].email)
})
))
it('should create users using multiple transactions', () =>
knest(trx => createUsers(trx, users)))
it('should have rolled back all the insert queries', () =>
findUsers(mysql).then(result => assert.deepStrictEqual(result, [])))
after(() => process.exit())
})
Knest exports a single function.
What Knest basically does is wrap the test function and adds a knex transaction as the first argument of the test callback function.
returns a promise which will rollback the transaction when it resolves. This is required. Throws if a promise is not returned.
This value should be a knex-connection or a knex transaction object.
The testFn is called when the tests are run. It is called with the following arguments
knexTransaction is an instance of a knex transaction that uses the previously configured knex connection.
Knest is tested using MySQL. Make sure you have MySQL installed. The
./setup.sql
file makes it easy to setup a database and user for running the
tests.
sudo mysql -p < setup.sql
Then install, prune and run the tests.
{ npm i && npm prune; } > /dev/null
npm t
> knest@1.1.3 test
> npx standard && npm run test-tape && npm run test-mocha
> knest@1.1.3 test-tape
> tape index.tape.spec.js
TAP version 13
# should reset the database user table
# should create user in user table
ok 1 should be loosely deeply equivalent
# should create users using multiple transactions
# should have rolled back all the insert queries
ok 2 should be loosely deeply equivalent
1..2
# tests 2
# pass 2
# ok
> knest@1.1.3 test-mocha
> mocha index.mocha.spec.js
Mocha & Knest
✔ should reset the database user table (115ms)
✔ should create user in user table
✔ should create users using multiple transactions
✔ should have rolled back all the insert queries
Feel free to contribute in whatever way you deem to be valuable.
Read more in the CONTRIBUTING.md
FAQs
Rollback db after knex test finishes
The npm package knest receives a total of 2 weekly downloads. As such, knest popularity was classified as not popular.
We found that knest demonstrated a not healthy version release cadence and project activity because the last version was released 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.
Product
Socket’s precomputed reachability slashes false positives by flagging up to 80% of vulnerabilities as irrelevant, with no setup and instant results.
Product
Socket is launching experimental protection for Chrome extensions, scanning for malware and risky permissions to prevent silent supply chain attacks.
Product
Add secure dependency scanning to Claude Desktop with Socket MCP, a one-click extension that keeps your coding conversations safe from malicious packages.