From f697095031b7e6b159af62686734b15a5b141c02 Mon Sep 17 00:00:00 2001 From: Erin Dees Date: Mon, 26 Jun 2023 15:19:41 -0400 Subject: [PATCH] Ensure test DB exists at correct path in better-sqlite3 tests --- test/unit/dialects/better-sqlite3.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/test/unit/dialects/better-sqlite3.js b/test/unit/dialects/better-sqlite3.js index 8f16cd716b..4b690cb9d9 100644 --- a/test/unit/dialects/better-sqlite3.js +++ b/test/unit/dialects/better-sqlite3.js @@ -1,6 +1,7 @@ 'use strict'; const path = require('path'); const expect = require('chai').expect; +const fs = require('fs'); const knex = require('../../../knex'); describe('better-sqlite3 unit tests', () => { @@ -50,12 +51,19 @@ describe('better-sqlite3 unit tests', () => { }); describe('readonly', () => { + const dbPath = path.resolve(__dirname, '../test.sqlite3'); + + before(() => { + // Read-only access requires the DB file to exist. + fs.writeFileSync(dbPath, ''); + }); + it('should initialize the DB with the passed-in `readonly` option', async () => { const knexInstance = knex({ client: 'better-sqlite3', useNullAsDefault: true, connection: { - filename: __dirname + '/../test.sqlite3', + filename: dbPath, options: { readonly: true, }, @@ -71,7 +79,7 @@ describe('better-sqlite3 unit tests', () => { client: 'better-sqlite3', useNullAsDefault: true, connection: { - filename: __dirname + '/../test.sqlite3', + filename: dbPath, options: { readonly: true, }, @@ -88,7 +96,7 @@ describe('better-sqlite3 unit tests', () => { client: 'better-sqlite3', useNullAsDefault: true, connection: { - filename: __dirname + '/../test.sqlite3', + filename: dbPath, }, });