-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
getDatabaseFile specifies MIME type and works with db in subfolder
- Loading branch information
1 parent
310329a
commit 5992ed5
Showing
2 changed files
with
55 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
import { SQLocal } from '../src/index'; | ||
|
||
describe('getDatabaseFile', () => { | ||
const fileName = 'get-database-file-test.sqlite3'; | ||
const paths = [[], [''], ['top'], ['one', 'two']]; | ||
|
||
it('should return the requested database file', async () => { | ||
for (let path of paths) { | ||
const databasePath = [...path, fileName].join('/'); | ||
const { sql, getDatabaseFile } = new SQLocal(databasePath); | ||
|
||
await sql`CREATE TABLE nums (num REAL NOT NULL)`; | ||
const file = await getDatabaseFile(); | ||
|
||
expect(file).toBeInstanceOf(File); | ||
expect(file.name).toBe(fileName); | ||
expect(file.size).toBe(16384); | ||
expect(file.type).toBe('application/x-sqlite3'); | ||
|
||
let dirHandle = await navigator.storage.getDirectory(); | ||
|
||
for (let dirName of path) { | ||
if (dirName === '') continue; | ||
dirHandle = await dirHandle.getDirectoryHandle(dirName); | ||
} | ||
|
||
await dirHandle.removeEntry(fileName); | ||
} | ||
}); | ||
|
||
it('should throw when requested database has not been created', async () => { | ||
const { getDatabaseFile } = new SQLocal(fileName); | ||
expect(async () => await getDatabaseFile()).rejects.toThrowError( | ||
'A requested file or directory could not be found at the time an operation was processed.' | ||
); | ||
}); | ||
}); |