diff --git a/README.md b/README.md index cbf2547..59c5788 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ Simple and intuitive ORM for MySQL -![](https://img.shields.io/npm/v/like-mysql.svg) ![](https://img.shields.io/npm/dt/like-mysql.svg) ![](https://img.shields.io/badge/tested_with-tape-e683ff.svg) ![](https://img.shields.io/github/license/LuKks/like-mysql.svg) +![](https://img.shields.io/npm/v/like-mysql.svg) ![](https://img.shields.io/npm/dt/like-mysql.svg) ![](https://img.shields.io/github/license/LuKks/like-mysql.svg) ```javascript const mysql = require('like-mysql') diff --git a/package.json b/package.json index df106c8..5c50127 100644 --- a/package.json +++ b/package.json @@ -8,13 +8,11 @@ "mysql2": "^2.3.3" }, "devDependencies": { - "standard": "^16.0.4", - "tape": "^5.5.0" + "brittle": "^3.5.0", + "standard": "^16.0.4" }, "scripts": { - "test": "standard && tape test.js", - "tape": "tape test.js", - "lint": "standard" + "test": "standard && brittle test.js" }, "repository": { "type": "git", diff --git a/test.js b/test.js index fd37ed9..7252e76 100644 --- a/test.js +++ b/test.js @@ -1,9 +1,9 @@ -const tape = require('tape') +const test = require('brittle') const mysql = require('./') const cfg = ['127.0.0.1:3305', 'root', 'secret', 'sys'] -tape('able to connect', async function (t) { +test('able to connect', async function (t) { const db = mysql(...cfg) await db.ready() @@ -11,7 +11,7 @@ tape('able to connect', async function (t) { await db.end() }) -tape('ready timeouts', async function (t) { +test('ready timeouts', async function (t) { const db = mysql('127.0.0.1:1234', cfg[1], cfg[2], cfg[3]) try { @@ -24,7 +24,7 @@ tape('ready timeouts', async function (t) { await db.end() }) -tape('should not connect due unexisting database', async function (t) { +test('should not connect due unexisting database', async function (t) { const db = mysql(cfg[0], cfg[1], cfg[2], 'database-not-exists') try { @@ -37,7 +37,7 @@ tape('should not connect due unexisting database', async function (t) { await db.end() }) -tape('should not connect due wrong authentication', async function (t) { +test('should not connect due wrong authentication', async function (t) { const db = mysql(cfg[0], cfg[1], 'wrong-password', cfg[3]) try { @@ -50,7 +50,7 @@ tape('should not connect due wrong authentication', async function (t) { await db.end() }) -tape('limited connections', async function (t) { +test('limited connections', async function (t) { const db = mysql(...cfg, { connectionLimit: 1, waitForConnections: false }) await db.ready() @@ -69,21 +69,21 @@ tape('limited connections', async function (t) { await db.end() }) -tape('createDatabase() and dropDatabase()', async function (t) { +test('createDatabase() and dropDatabase()', async function (t) { const db = mysql(...cfg) await db.ready() t.ok(await db.createDatabase('forex')) - t.notOk(await db.createDatabase('forex')) + t.absent(await db.createDatabase('forex')) t.ok(await db.dropDatabase('forex')) - t.notOk(await db.dropDatabase('forex')) + t.absent(await db.dropDatabase('forex')) await db.end() }) -tape('createDatabase() without any previous database', async function (t) { +test('createDatabase() without any previous database', async function (t) { const db = mysql(cfg[0], cfg[1], cfg[2], '') await db.ready() @@ -94,7 +94,7 @@ tape('createDatabase() without any previous database', async function (t) { await db.end() }) -tape('createTable() and dropTable()', async function (t) { +test('createTable() and dropTable()', async function (t) { const db = mysql(...cfg) await db.ready() @@ -104,17 +104,17 @@ tape('createTable() and dropTable()', async function (t) { } t.ok(await db.createTable('users', columns)) - t.notOk(await db.createTable('users', columns)) + t.absent(await db.createTable('users', columns)) t.ok(await db.dropTable('users')) - t.notOk(await db.dropTable('users')) + t.absent(await db.dropTable('users')) await db.end() }) // + create complex tables -tape('insert() without autoincrement id', async function (t) { +test('insert() without autoincrement id', async function (t) { const db = mysql(...cfg) await db.ready() @@ -132,7 +132,7 @@ tape('insert() without autoincrement id', async function (t) { await db.end() }) -tape('insert() with autoincrement id', async function (t) { +test('insert() with autoincrement id', async function (t) { const db = mysql(...cfg) await db.ready() @@ -150,7 +150,7 @@ tape('insert() with autoincrement id', async function (t) { await db.end() }) -tape('insert()', async function (t) { +test('insert()', async function (t) { const db = mysql(...cfg) await db.ready() @@ -184,7 +184,7 @@ tape('insert()', async function (t) { await db.end() }) -tape('select()', async function (t) { +test('select()', async function (t) { const db = mysql(...cfg) await db.ready() @@ -198,22 +198,22 @@ tape('select()', async function (t) { const rows = await db.select('users') t.ok(rows.length === 2) - t.deepEqual(rows[0], { username: 'joe', password: '123' }) - t.deepEqual(rows[1], { username: 'bob', password: '456' }) + t.alike(rows[0], { username: 'joe', password: '123' }) + t.alike(rows[1], { username: 'bob', password: '456' }) const rows2 = await db.select('users', ['username']) t.ok(rows2.length === 2) - t.deepEqual(rows2[0], { username: 'joe' }) - t.deepEqual(rows2[1], { username: 'bob' }) + t.alike(rows2[0], { username: 'joe' }) + t.alike(rows2[1], { username: 'bob' }) const rows3 = await db.select('users', ['username'], 'LIMIT 1') t.ok(rows3.length === 1) - t.deepEqual(rows3[0], { username: 'joe' }) + t.alike(rows3[0], { username: 'joe' }) const findUsername = 'joe' const rows4 = await db.select('users', ['password'], 'username = ?', findUsername) t.ok(rows4.length === 1) - t.deepEqual(rows4[0], { password: '123' }) + t.alike(rows4[0], { password: '123' }) const rows5 = await db.select('users', ['*'], 'ORDER BY username ASC') t.ok(rows5.length === 2) @@ -239,7 +239,7 @@ tape('select()', async function (t) { await db.end() }) -tape('selectOne()', async function (t) { +test('selectOne()', async function (t) { const db = mysql(...cfg) await db.ready() @@ -252,23 +252,23 @@ tape('selectOne()', async function (t) { await db.insert('users', { username: 'bob', password: '456' }) const row = await db.selectOne('users', ['*'], 'username = ?', 'joe') - t.deepEqual(row, { username: 'joe', password: '123' }) + t.alike(row, { username: 'joe', password: '123' }) const row2 = await db.selectOne('users', ['*'], 'ORDER BY username ASC') - t.deepEqual(row2, { username: 'bob', password: '456' }) + t.alike(row2, { username: 'bob', password: '456' }) const row3 = await db.selectOne('users', ['*'], 'username = ? ORDER BY username ASC', 'joe') - t.deepEqual(row3, { username: 'joe', password: '123' }) + t.alike(row3, { username: 'joe', password: '123' }) const row4 = await db.selectOne('users', ['*'], 'username = ?', 'random-username') - t.deepEqual(row4, undefined) + t.alike(row4, undefined) await db.dropTable('users') await db.end() }) -tape('exists()', async function (t) { +test('exists()', async function (t) { const db = mysql(...cfg) await db.ready() @@ -284,14 +284,14 @@ tape('exists()', async function (t) { t.ok(exists) const exists2 = await db.exists('users', 'username = ?', 'random-username') - t.notOk(exists2) + t.absent(exists2) await db.dropTable('users') await db.end() }) -tape('count()', async function (t) { +test('count()', async function (t) { const db = mysql(...cfg) await db.ready() @@ -317,7 +317,7 @@ tape('count()', async function (t) { await db.end() }) -tape('update()', async function (t) { +test('update()', async function (t) { const db = mysql(...cfg) await db.ready() @@ -343,7 +343,7 @@ tape('update()', async function (t) { await db.end() }) -tape('update() with arithmetic', async function (t) { +test('update() with arithmetic', async function (t) { const db = mysql(...cfg) await db.ready() @@ -355,16 +355,16 @@ tape('update() with arithmetic', async function (t) { await db.insert('users', { username: 'joe', count: 0 }) await db.insert('users', { username: 'bob', count: 0 }) - t.deepEqual({ count: 0 }, await db.selectOne('users', ['count'], 'username = ?', 'bob')) + t.alike({ count: 0 }, await db.selectOne('users', ['count'], 'username = ?', 'bob')) t.ok(await db.update('users', [{ count: 'count + ?' }, 1], 'username = ?', 'bob') === 1) - t.deepEqual({ count: 1 }, await db.selectOne('users', ['count'], 'username = ?', 'bob')) + t.alike({ count: 1 }, await db.selectOne('users', ['count'], 'username = ?', 'bob')) await db.dropTable('users') await db.end() }) -tape('delete()', async function (t) { +test('delete()', async function (t) { const db = mysql(...cfg) await db.ready() @@ -395,7 +395,7 @@ tape('delete()', async function (t) { await db.end() }) -tape('transaction()', async function (t) { +test('transaction()', async function (t) { const db = mysql(...cfg) await db.ready() @@ -420,8 +420,8 @@ tape('transaction()', async function (t) { const user = await db.selectOne('users', ['*'], 'username = ?', 'alice') const profile = await db.selectOne('profiles', ['*'], 'owner = ?', user.id) t.ok(user.id === resultId) - t.deepEqual(user, { id: 3, username: 'alice' }) - t.deepEqual(profile, { owner: 3, name: 'Alice' }) + t.alike(user, { id: 3, username: 'alice' }) + t.alike(profile, { owner: 3, name: 'Alice' }) await db.dropTable('users') await db.dropTable('profiles') @@ -429,7 +429,7 @@ tape('transaction()', async function (t) { await db.end() }) -tape('transaction() with error', async function (t) { +test('transaction() with error', async function (t) { const db = mysql(...cfg) await db.ready() @@ -464,7 +464,7 @@ tape('transaction() with error', async function (t) { await db.end() }) -tape('execute()', async function (t) { +test('execute()', async function (t) { const db = mysql(...cfg) await db.ready() @@ -477,7 +477,7 @@ tape('execute()', async function (t) { await db.insert('users', { username: 'bob' }) const [rows, fields] = await db.execute('SELECT * FROM `users` WHERE `username` = ?', ['joe']) - t.deepEqual(rows, [{ id: 1, username: 'joe' }]) + t.alike(rows, [{ id: 1, username: 'joe' }]) t.ok(fields[0].name === 'id') t.ok(fields[1].name === 'username') @@ -486,7 +486,7 @@ tape('execute()', async function (t) { await db.end() }) -tape('query()', async function (t) { +test('query()', async function (t) { const db = mysql(...cfg) await db.ready() @@ -499,7 +499,7 @@ tape('query()', async function (t) { await db.insert('users', { username: 'bob' }) const [rows, fields] = await db.query('SELECT * FROM `users` WHERE `username` = "joe"') - t.deepEqual(rows, [{ id: 1, username: 'joe' }]) + t.alike(rows, [{ id: 1, username: 'joe' }]) t.ok(fields[0].name === 'id') t.ok(fields[1].name === 'username') @@ -508,7 +508,7 @@ tape('query()', async function (t) { await db.end() }) -tape('without ready()', async function (t) { +test('without ready()', async function (t) { const db = mysql(...cfg) await db.createTable('users', { @@ -519,7 +519,7 @@ tape('without ready()', async function (t) { await db.insert('users', { username: 'bob' }) const [rows, fields] = await db.execute('SELECT * FROM `users` WHERE `username` = ?', ['joe']) - t.deepEqual(rows, [{ id: 1, username: 'joe' }]) + t.alike(rows, [{ id: 1, username: 'joe' }]) t.ok(fields[0].name === 'id') t.ok(fields[1].name === 'username')