Skip to content

Commit

Permalink
Bundle driver tests
Browse files Browse the repository at this point in the history
  • Loading branch information
benmerckx committed Sep 11, 2024
1 parent 8ff8a0a commit dafe900
Show file tree
Hide file tree
Showing 11 changed files with 109 additions and 109 deletions.
Binary file modified bun.lockb
Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"@types/glob": "^8.1.0",
"@types/pg": "^8.11.8",
"@types/sql.js": "^1.4.9",
"better-sqlite3": "^11.2.1",
"better-sqlite3": "^11.3.0",
"esbuild": "^0.23.1",
"glob": "^11.0.0",
"madge": "^8.0.0",
Expand Down
35 changes: 0 additions & 35 deletions test/TestDriver.ts

This file was deleted.

108 changes: 108 additions & 0 deletions test/driver.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
import * as driver from '@/driver.ts'
import {type DefineTest, type Describe, suite} from '@alinea/suite'
import {isBun, isCi, isNode} from './TestRuntime.ts'
import {testBasic} from './integration/TestBasic.ts'
import {testCTE} from './integration/TestCTE.ts'
import {testColumns} from './integration/TestColumns.ts'
import {testConstraints} from './integration/TestConstraints.ts'
import {testInclude} from './integration/TestInclude.ts'
import {testJoins} from './integration/TestJoins.ts'
import {testJson} from './integration/TestJson.ts'
import {testMigration} from './integration/TestMigration.ts'
import {testPreparedQuery} from './integration/TestPreparedQuery.ts'
import {testSubquery} from './integration/TestSubquery.ts'
import {testTransactions} from './integration/TestTransactions.ts'

const init = {
'better-sqlite3': {
condition: isNode,
supportsDiff: true,
async client() {
const {default: Database} = await import('better-sqlite3')
return new Database(':memory:')
}
},
'bun:sqlite': {
condition: isBun,
supportsDiff: true,
async client() {
const {Database} = await import('bun:sqlite')
return new Database(':memory:')
}
},
mysql2: {
condition: isCi,
supportsDiff: false,
async client() {
const {default: mysql2} = await import('mysql2')
const client = mysql2.createConnection(
'mysql://root:[email protected]:3306/mysql'
)
return client
}
},
'@electric-sql/pglite': {
condition: true,
supportsDiff: true,
async client() {
const {PGlite} = await import('@electric-sql/pglite')
return new PGlite()
}
},
pg: {
condition: isCi,
supportsDiff: true,
async client() {
const {default: pg} = await import('pg')
const client = new pg.Client({
connectionString: 'postgres://postgres:[email protected]:5432/postgres'
})
await client.connect()
return client
}
},
'sql.js': {
condition: true,
supportsDiff: true,
async client() {
const {default: init} = await import('sql.js')
const {Database} = await init()
return new Database()
}
}
}

async function createTests() {
const clients = await Promise.all(
Object.entries(init)
.filter(([name, meta]) => meta.condition)
.map(
async ([name, meta]) =>
[name, await meta.client()] as [keyof typeof init, any]
)
)
return (test: DefineTest) => {
for (const [name, client] of clients) {
const {supportsDiff} = init[name]
const db = driver[name](client)
const prefixed: Describe = (description, fn) =>
test(`${name}: ${description}`, fn)
const withName = Object.assign(prefixed, test)

testBasic(db, withName)
testColumns(db, withName)
testSubquery(db, withName)
testPreparedQuery(db, withName)
testJoins(db, withName)
testJson(db, withName)
testTransactions(db, withName)
testConstraints(db, withName)
testCTE(db, withName)
testInclude(db, withName)

if (supportsDiff) testMigration(db, withName)
}
}
}

suite(import.meta, await createTests())
10 changes: 0 additions & 10 deletions test/driver/@db_sqlite.test.ts

This file was deleted.

7 changes: 0 additions & 7 deletions test/driver/@electric-sql_pglite.test.ts

This file was deleted.

9 changes: 0 additions & 9 deletions test/driver/better-sqlite3.test.ts

This file was deleted.

10 changes: 0 additions & 10 deletions test/driver/bun-sqlite.test.ts

This file was deleted.

16 changes: 0 additions & 16 deletions test/driver/mysql2.test.ts

This file was deleted.

13 changes: 0 additions & 13 deletions test/driver/pg.test.ts

This file was deleted.

8 changes: 0 additions & 8 deletions test/driver/sql.js.test.ts

This file was deleted.

0 comments on commit dafe900

Please sign in to comment.