Research
Recent Trends in Malicious Packages Targeting Discord
The Socket research team breaks down a sampling of malicious packages that download and execute files, among other suspicious behaviors, targeting the popular Discord platform.
knest
Advanced tools
Readme
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 6 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.
Research
The Socket research team breaks down a sampling of malicious packages that download and execute files, among other suspicious behaviors, targeting the popular Discord platform.
Security News
Socket CEO Feross Aboukhadijeh joins a16z partners to discuss how modern, sophisticated supply chain attacks require AI-driven defenses and explore the challenges and solutions in leveraging AI for threat detection early in the development life cycle.
Security News
NIST's new AI Risk Management Framework aims to enhance the security and reliability of generative AI systems and address the unique challenges of malicious AI exploits.