Skip to content

Commit

Permalink
refactor: running tests for mysql,pg and sqlite drivers
Browse files Browse the repository at this point in the history
  • Loading branch information
thetutlage committed Jan 12, 2020
1 parent f28258e commit aeaf665
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 62 deletions.
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
"scripts": {
"mrm": "mrm --preset=@adonisjs/mrm-preset",
"pretest": "npm run lint",
"test": "node japaFile.js",
"test:sqlite": "DB=sqlite node japaFile.js",
"test:mysql": "DB=mysql node japaFile.js",
"test:pg": "DB=pg node japaFile.js",
"test": "npm run test:sqlite && npm run test:mysql && npm run test:pg",
"prepublishOnly": "npm run build",
"lint": "tslint --project tsconfig.json",
"clean": "del build",
Expand Down
124 changes: 63 additions & 61 deletions test/query-builder.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2640,67 +2640,69 @@ test.group('Query Builder | forShare', (group) => {
})
})

test.group('Query Builder | noWait', (group) => {
group.before(async () => {
await setup()
})

group.after(async () => {
await cleanup()
})

test('add no wait instruction to the query', (assert) => {
const connection = new Connection('primary', getConfig())
connection.connect()

const db = getQueryBuilder(connection)
const { sql, bindings } = db
.from('users')
.forShare()
.noWait()
.toSQL()

const { sql: knexSql, bindings: knexBindings } = connection.client!
.from('users')
.forShare()
.noWait()
.toSQL()

assert.equal(sql, knexSql)
assert.deepEqual(bindings, knexBindings)
})
})

test.group('Query Builder | skipLocked', (group) => {
group.before(async () => {
await setup()
})

group.after(async () => {
await cleanup()
})

test('add skip locked instruction to the query', (assert) => {
const connection = new Connection('primary', getConfig())
connection.connect()

const db = getQueryBuilder(connection)
const { sql, bindings } = db
.from('users')
.forShare()
.skipLocked()
.toSQL()

const { sql: knexSql, bindings: knexBindings } = connection.client!
.from('users')
.forShare()
.skipLocked()
.toSQL()

assert.equal(sql, knexSql)
assert.deepEqual(bindings, knexBindings)
})
})
if (['pg', 'mysql'].includes(process.env.DB!)) {
test.group('Query Builder | noWait', (group) => {
group.before(async () => {
await setup()
})

group.after(async () => {
await cleanup()
})

test('add no wait instruction to the query', (assert) => {
const connection = new Connection('primary', getConfig())
connection.connect()

const db = getQueryBuilder(connection)
const { sql, bindings } = db
.from('users')
.forShare()
.noWait()
.toSQL()

const { sql: knexSql, bindings: knexBindings } = connection.client!
.from('users')
.forShare()
.noWait()
.toSQL()

assert.equal(sql, knexSql)
assert.deepEqual(bindings, knexBindings)
})
})

test.group('Query Builder | skipLocked', (group) => {
group.before(async () => {
await setup()
})

group.after(async () => {
await cleanup()
})

test('add skip locked instruction to the query', (assert) => {
const connection = new Connection('primary', getConfig())
connection.connect()

const db = getQueryBuilder(connection)
const { sql, bindings } = db
.from('users')
.forShare()
.skipLocked()
.toSQL()

const { sql: knexSql, bindings: knexBindings } = connection.client!
.from('users')
.forShare()
.skipLocked()
.toSQL()

assert.equal(sql, knexSql)
assert.deepEqual(bindings, knexBindings)
})
})
}

test.group('Query Builder | having', (group) => {
group.before(async () => {
Expand Down

0 comments on commit aeaf665

Please sign in to comment.