Skip to content

Commit 00d4c1a

Browse files
committed
Improve documentation
1 parent 123a546 commit 00d4c1a

File tree

4 files changed

+60
-31
lines changed

4 files changed

+60
-31
lines changed

.editorconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ indent_size = 4
1212
trim_trailing_whitespace = true
1313
insert_final_newline = true
1414

15-
[{package.json,*.yml}]
15+
[{*.json,*.yml}]
1616
indent_style = space
1717
indent_size = 2

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2018 Thiago Delgado Pinto
3+
Copyright (c) 2018-today Thiago Delgado Pinto
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 56 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,33 +7,37 @@
77
88
This is a [Helper](https://codecept.io/helpers/) for [CodeceptJS](https://codecept.io/) that allows you to execute queries or commands to databases using [database-js](https://github.com/mlaanderson/database-js). That is, your tests written for CodeceptJS now will be able to access databases easily. **It is especially useful for preparing databases before/after executing test cases.**
99

10+
👉 It works with **CodeceptJS 1, 2, and 3**.
11+
1012
## Install
1113

12-
**_Step 1 of 2_: Install the helper**
14+
> You have to install the library and the desired database drivers
15+
16+
Step 1 of 2: **Install the helper**
1317

1418
```bash
15-
npm install --save codeceptjs-dbhelper
19+
npm i -D codeceptjs-dbhelper
1620
```
1721

18-
**_Step 2 of 2_: Install the driver for the database you need to use**
22+
Step 2 of 2: **Install a database driver**
1923

2024
| Driver (wrapper) | Note | Installation command |
2125
| ---------------- | ---- | -------------------- |
22-
| [ActiveX Data Objects](//github.com/mlaanderson/database-js-adodb) | *Windows only* | `npm i database-js-adodb` |
23-
| [CSV files](//github.com/mlaanderson/database-js-csv) | | `npm i database-js-csv` |
24-
| [Excel files](//github.com/mlaanderson/database-js-xlsx) | | `npm i database-js-xlsx` |
25-
| [Firebase](//github.com/mlaanderson/database-js-firebase) | | `npm i database-js-firebase` |
26-
| [INI files](//github.com/mlaanderson/database-js-ini) | | `npm i database-js-ini` |
27-
| [JSON files](//github.com/thiagodp/database-js-json) | | `npm i database-js-json` |
28-
| [MySQL](//github.com/mlaanderson/database-js-mysql) | | `npm i database-js-mysql` |
29-
| [MS SQL Server](https://github.com/thiagodp/database-js-mssql) | | `npm i database-js-mssql` |
30-
| [PostgreSQL](//github.com/mlaanderson/database-js-postgres) | | `npm i database-js-postgres` |
31-
| [SQLite](//github.com/mlaanderson/database-js-sqlite) | | `npm i database-js-sqlite` |
26+
| [ActiveX Data Objects](//github.com/mlaanderson/database-js-adodb) | *Windows only* | `npm i -D database-js-adodb` |
27+
| [CSV files](//github.com/mlaanderson/database-js-csv) | | `npm i -D database-js-csv` |
28+
| [Excel files](//github.com/mlaanderson/database-js-xlsx) | | `npm i -D database-js-xlsx` |
29+
| [Firebase](//github.com/mlaanderson/database-js-firebase) | | `npm i -D database-js-firebase` |
30+
| [INI files](//github.com/mlaanderson/database-js-ini) | | `npm i -D database-js-ini` |
31+
| [JSON files](//github.com/thiagodp/database-js-json) | | `npm i -D database-js-json` |
32+
| [MySQL](//github.com/mlaanderson/database-js-mysql) | | `npm i -D database-js-mysql` |
33+
| [MS SQL Server](https://github.com/thiagodp/database-js-mssql) | | `npm i -D database-js-mssql` |
34+
| [PostgreSQL](//github.com/mlaanderson/database-js-postgres) | | `npm i -D database-js-postgres` |
35+
| [SQLite](//github.com/mlaanderson/database-js-sqlite) | | `npm i -D database-js-sqlite` |
3236

3337
See [database-js](https://github.com/mlaanderson/database-js) for the full list of available drivers.
3438

3539

36-
## Usage
40+
## Configure
3741

3842
### Configuration in CodeceptJS
3943

@@ -49,33 +53,58 @@ In your `codecept.json`, include **DbHelper** in the property **helpers** :
4953
},
5054
...
5155
```
56+
57+
## Usage
58+
59+
60+
### Syntax differences between CodeceptJS 2 and CodeceptJS 3
61+
62+
In CodeceptJS 2, your callbacks receive an `I` argument:
63+
64+
```javascript
65+
Scenario('test something', async ( I ) => { // CodeceptJS 2 notation
66+
/* ... */
67+
} );
68+
```
69+
70+
In CodeceptJS 3, your callbacks receive an object with `I` - that is, `{ I }`:
71+
72+
```javascript
73+
Scenario('test something', async ( { I } ) => { // CodeceptJS 3 notation
74+
/* ... */
75+
} );
76+
```
77+
78+
See the [CodeceptJS docs](https://github.com/codeceptjs/CodeceptJS/wiki/Upgrading-to-CodeceptJS-3) for more information on how to upgrade your codebase.
79+
5280
### Examples
5381

54-
The object `I` of your tests and events will have access to new methods. [See the API](#api).
82+
> The following examples are written with **CodeceptJS 3**.
83+
84+
The object `I` of your tests and events now has to the [methods described in the API](#api).
5585

5686
#### Example 1
5787

5888
```js
59-
BeforeSuite( async( I ) => {
89+
BeforeSuite( async( { I } ) => {
6090
// The first parameter is the key that will hold a reference to the db
6191
I.connect( "testdb", "mysql://root:mypassword@localhost:3306/testdb" );
6292
} );
6393

64-
AfterSuite( async( I ) => {
94+
AfterSuite( async( { I } ) => {
6595
await I.removeConnection( "testdb" ); // also disconnects
6696
} );
6797

6898

69-
Before( async( I ) => {
70-
71-
// Delete all the records of the table user
72-
await I.run( "testdb", "DELETE FROM user" );
99+
Before( async( { I } ) => {
73100

74-
// Insert some users
75-
await I.run( "testdb", "INSERT INTO user ( username, password ) VALUES ( ?, ? )", "admin", "123456" );
76-
await I.run( "testdb", "INSERT INTO user ( username, password ) VALUES ( ?, ? )", "bob", "654321" );
77-
await I.run( "testdb", "INSERT INTO user ( username, password ) VALUES ( ?, ? )", "alice", "4lic3p4s$" );
101+
// Deleting all the records from the table 'user'
102+
await I.run( "testdb", "DELETE FROM user" );
78103

104+
// Inserting some users
105+
await I.run( "testdb", "INSERT INTO user ( username, password ) VALUES ( ?, ? )", "admin", "123456" );
106+
await I.run( "testdb", "INSERT INTO user ( username, password ) VALUES ( ?, ? )", "bob", "654321" );
107+
await I.run( "testdb", "INSERT INTO user ( username, password ) VALUES ( ?, ? )", "alice", "4lic3p4s$" );
79108
} );
80109

81110

@@ -89,9 +118,9 @@ await I.run( "testdb", "INSERT INTO user ( username, password ) VALUES ( ?, ? )"
89118
```js
90119
Feature( 'Foo' );
91120

92-
Scenario( 'Bar', async( I ) => {
121+
Scenario( 'Bar', async( { I } ) => {
93122

94-
// Query a user from the database
123+
// Queries a user from the database
95124
const results = await I.query( "testdb", "SELECT * FROM user WHERE username = ?", "bob" );
96125
const bob = results[ 0 ];
97126

index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
let dbjs = require('database-js'); // npm install database-js --save-dev
1+
let dbjs = require('database-js');
22

33
/**
44
* Database helper
@@ -144,4 +144,4 @@ class DbHelper extends Helper {
144144

145145
}
146146

147-
module.exports = DbHelper;
147+
module.exports = DbHelper;

0 commit comments

Comments
 (0)