Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Saving database works in browser, fails in UnitTest #56

Open
Stwissel opened this issue Jan 11, 2025 · 0 comments
Open

Saving database works in browser, fails in UnitTest #56

Stwissel opened this issue Jan 11, 2025 · 0 comments

Comments

@Stwissel
Copy link

This is probably less a bug and more a testimony of my lack of understanding. First of all: LOVE your work!

I'm trying to understand kdbxweb, so I setup a simple project that creates, saves and loads a database. Works like a charm in the browser (run npm run dev to see). However I failed to create a unit test using vitest. Creation works, but save fails:

TypeError: Failed to execute 'digest' on 'SubtleCrypto': 2nd argument is not instance of ArrayBuffer, Buffer, TypedArray, or DataView.

The test method looks like this:

import { describe, it, expect, beforeEach, afterEach } from 'vitest';
import { init, createDatabase, saveDatabase, loadDatabase, clearDatabase } from '../src/vault';
import * as kdbxweb from 'kdbxweb';

describe('Vault Kxdb Tests', () => {
  beforeEach(() => {
    init();
  });

  afterEach(() => {
    clearDatabase();
  });

  it('should create a new database', async () => {
    const db = await createDatabase('test');
    expect(db).toBeDefined();
  });

  it('should save the database', async () => {
    const db = await createDatabase('test');
    const arrayBuffer = await saveDatabase(db);
    expect(arrayBuffer).toBeDefined();
  });

  it('should load the database', async () => {
    const db = await createDatabase('test');
    const arrayBuffer = await saveDatabase(db);
    const loadedDb = await loadDatabase(arrayBuffer, 'test');
    expect(loadedDb).toBeDefined();
  });
});

full project here: https://github.com/Stwissel/kxdbtest

What do I miss?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant