In memory tests with libsql?

Do you guys know if there's a way to get this working with libsql? I'm using turso, and was hoping to get the DB working in memory for local tests. I have this
import { describe, it, expect, beforeAll } from 'vitest';

import { db } from '$lib/server/db';
import * as userService from '$lib/server/users/service';
import { migrate } from 'drizzle-orm/libsql/migrator';
import { userTable } from '$lib/server/users/schema';

describe('userService test', () => {
beforeAll(async () => {
await migrate(db, { migrationsFolder: 'drizzle' });
});

it('allUsers', async () => {
await userService.allUsers();
});

it('deleteUser', async () => {
await userService.deleteUser('123');
});

it('addUser', async () => {
await userService.addUser({ name: 'test', email: '[email protected]' });
});
});
import { describe, it, expect, beforeAll } from 'vitest';

import { db } from '$lib/server/db';
import * as userService from '$lib/server/users/service';
import { migrate } from 'drizzle-orm/libsql/migrator';
import { userTable } from '$lib/server/users/schema';

describe('userService test', () => {
beforeAll(async () => {
await migrate(db, { migrationsFolder: 'drizzle' });
});

it('allUsers', async () => {
await userService.allUsers();
});

it('deleteUser', async () => {
await userService.deleteUser('123');
});

it('addUser', async () => {
await userService.addUser({ name: 'test', email: '[email protected]' });
});
});
I'm just setting the DATABASE_URL in env and passing that through. I'm basically doing the same thing as mentioned here https://discord.com/channels/1043890932593987624/1137482695862132745/1138184887048867850 however I'm using libsql
2 Replies
softgrip
softgripOP16mo ago
For reference: This works
.env
DATABASE_URL=file:local.db
.env
DATABASE_URL=file:local.db
As does this (on turso)
.env.prod
DATABASE_URL=libsql://blahblahblah.turso.io
DATABASE_AUTH_TOKEN=asdfasdfasd
.env.prod
DATABASE_URL=libsql://blahblahblah.turso.io
DATABASE_AUTH_TOKEN=asdfasdfasd
However this does not work
.env.test
DATABASE_URL=file::memory:
.env.test
DATABASE_URL=file::memory:
And results in
FAIL src/lib/server/users/service.test.ts > userService test
LibsqlError: SQLITE_ERROR: no such table: __drizzle_migrations
❯ mapSqliteError node_modules/.pnpm/@[email protected]/node_modules/@libsql/client/lib-esm/sqlite3.js:296:16
❯ executeStmt node_modules/.pnpm/@[email protected]/node_modules/@libsql/client/lib-esm/sqlite3.js:213:15
❯ Sqlite3Client.execute node_modules/.pnpm/@[email protected]/node_modules/@libsql/client/lib-esm/sqlite3.js:61:20
❯ PreparedQuery.values node_modules/.pnpm/[email protected]_@[email protected]/node_modules/src/libsql/session.ts:188:57
❯ LibSQLSession.values node_modules/.pnpm/[email protected]_@[email protected]/node_modules/src/sqlite-core/session.ts:124:85
❯ SQLiteAsyncDialect.migrate node_modules/.pnpm/[email protected]_@[email protected]/node_modules/src/sqlite-core/dialect.ts:674:38
❯ src/lib/server/users/service.test.ts:10:3
8| describe('userService test', () => {
9| beforeAll(async () => {
10| await migrate(db, { migrationsFolder: 'drizzle' });
| ^
11| });
12|
FAIL src/lib/server/users/service.test.ts > userService test
LibsqlError: SQLITE_ERROR: no such table: __drizzle_migrations
❯ mapSqliteError node_modules/.pnpm/@[email protected]/node_modules/@libsql/client/lib-esm/sqlite3.js:296:16
❯ executeStmt node_modules/.pnpm/@[email protected]/node_modules/@libsql/client/lib-esm/sqlite3.js:213:15
❯ Sqlite3Client.execute node_modules/.pnpm/@[email protected]/node_modules/@libsql/client/lib-esm/sqlite3.js:61:20
❯ PreparedQuery.values node_modules/.pnpm/[email protected]_@[email protected]/node_modules/src/libsql/session.ts:188:57
❯ LibSQLSession.values node_modules/.pnpm/[email protected]_@[email protected]/node_modules/src/sqlite-core/session.ts:124:85
❯ SQLiteAsyncDialect.migrate node_modules/.pnpm/[email protected]_@[email protected]/node_modules/src/sqlite-core/dialect.ts:674:38
❯ src/lib/server/users/service.test.ts:10:3
8| describe('userService test', () => {
9| beforeAll(async () => {
10| await migrate(db, { migrationsFolder: 'drizzle' });
| ^
11| });
12|
Is it that the connection doesn't stay open? I don't know 😦
Vinicius Gonçalves
Have you found an answer?
Want results from more Discord servers?
Add your server