Skip to content

Commit 8b9d7a2

Browse files
committed
Test file location too
1 parent 14d2f0b commit 8b9d7a2

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

packages/node/tests/PowerSyncDatabase.test.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as path from 'node:path';
2+
import * as fs from 'node:fs/promises';
23
import { Worker } from 'node:worker_threads';
34

45
import { vi, expect, test } from 'vitest';
@@ -93,16 +94,25 @@ databaseTest('can watch tables', async ({ database }) => {
9394
});
9495

9596
tempDirectoryTest('automatically creates directory', async ({ tmpdir }) => {
97+
const directory = path.join(tmpdir, 'some', 'nested', 'location', 'that', 'does', 'not', 'exist');
98+
9699
const database = new PowerSyncDatabase({
97100
schema: AppSchema,
98101
database: {
99102
dbFilename: 'test.db',
100-
dbLocation: path.join(tmpdir, 'some', 'nested', 'location', 'that', 'does', 'not', 'exist'),
103+
dbLocation: directory,
101104
readWorkerCount: 2
102105
}
103106
});
104107

105-
await database.get('SELECT 1;'); // Make sure the database is ready and works
108+
// Make sure there's a write to the file
109+
await database.writeLock((conn) => conn.execute('pragma user_version = 2'));
110+
111+
// Make sure the file is actually created in the right location
112+
await fs.access(
113+
path.join(directory, 'test.db'),
114+
fs.constants.F_OK | fs.constants.R_OK | fs.constants.W_OK
115+
);
106116
});
107117

108118
databaseTest.skip('can watch queries', async ({ database }) => {

0 commit comments

Comments
 (0)