Skip to content
This repository was archived by the owner on Aug 31, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 54 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ This example is part of the knex mocha [tests](./index.mocha.spec.js). They
can be run using using the following npm script.

```bash
npm run test-mocha
npm install npx -g && npx mocha ./index.mocha.spec.js
```

```js
Expand Down Expand Up @@ -52,6 +52,49 @@ describe('Mocha & Knest', () => {
})
```

You can consider using `async / await` syntax as the knex helper returns
a promise.

```bash
node index.async.spec.js
```

```js
const assert = require('assert')
const {
mysql,
users,
resetDatabase,
findUsers,
createUsers,
createUser,
} = require('./index.spec')

const knest = require('./index').bind(null, mysql)

async function tests() {
await resetDatabase(mysql)

await knest(async trx => {
const user = await createUser(trx, users[0])

assert.deepEqual(user, users[0])
})

knest(async trx => {
const created = await createUsers(trx, users)

assert.deepEqual(created, users)
})

const foundUsers = await findUsers(mysql)

assert.deepEqual(foundUsers, [])
}

tests().then(() => process.exit())
```

# Reference

Knest exports a single function.
Expand Down Expand Up @@ -85,14 +128,14 @@ 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.

```bash
#!/bin/bash

npm install
sudo mysql -p < ./setup.sql
```sql
DROP DATABASE IF EXISTS knest;
CREATE DATABASE knest;
GRANT ALL PRIVILEGES ON knest.* TO knest@localhost IDENTIFIED BY 'knest';
FLUSH PRIVILEGES;
```

Once the test requirements are setup you can run the tests using `npm test`
Once the test requirements are setup you can run the tests using `npm test`.

# Changelog

Expand All @@ -115,3 +158,7 @@ Some suggestions for contributing to this library are:
- Write tests for other databases knex supports.
- Support for multiple connections/transactions
- Contribute what you feel is important.

# License

[MIT License](./LICENSE)
2 changes: 2 additions & 0 deletions doc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@ require ./doc/section/test.md
require ./doc/section/changelog.md

require ./doc/section/contribute.md

require ./doc/section/license.md
1 change: 1 addition & 0 deletions doc/script/async-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node index.async.spec.js
2 changes: 1 addition & 1 deletion doc/script/mocha-tests.sh
Original file line number Diff line number Diff line change
@@ -1 +1 @@
npm run test-mocha
npm install npx -g && npx mocha ./index.mocha.spec.js
4 changes: 0 additions & 4 deletions doc/script/setup-test.sh

This file was deleted.

3 changes: 3 additions & 0 deletions doc/section/license.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# License

require-run bash -c 'echo "[$(head -n 1 ./LICENSE)](./LICENSE)"'
6 changes: 3 additions & 3 deletions doc/section/test.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ 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.

```bash
require ./doc/script/setup-test.sh
```sql
require ./setup.sql
```

Once the test requirements are setup you can run the tests using `npm test`
Once the test requirements are setup you can run the tests using `npm test`.
11 changes: 11 additions & 0 deletions doc/section/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,14 @@ require ./doc/script/mocha-tests.sh
```js
require ./index.mocha.spec.js
```

You can consider using `async / await` syntax as the knex helper returns
a promise.

```bash
require ./doc/script/async-tests.sh
```

```js
require ./index.async.spec.js
```
33 changes: 33 additions & 0 deletions index.async.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
const assert = require('assert')
const {
mysql,
users,
resetDatabase,
findUsers,
createUsers,
createUser,
} = require('./index.spec')

const knest = require('./index').bind(null, mysql)

async function tests() {
await resetDatabase(mysql)

await knest(async trx => {
const user = await createUser(trx, users[0])

assert.deepEqual(user, users[0])
})

knest(async trx => {
const created = await createUsers(trx, users)

assert.deepEqual(created, users)
})

const foundUsers = await findUsers(mysql)

assert.deepEqual(foundUsers, [])
}

tests().then(() => process.exit())
Loading