Skip to content

Commit

Permalink
Add db reopen test and don't specify full dependency versions (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
devashishdxt authored Aug 12, 2024
1 parent 72234d8 commit 7d8730c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 11 deletions.
18 changes: 9 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ path = "src/lib.rs"
crate-type = ["cdylib", "rlib"]

[dependencies]
idb = { version = "0.6.2", features = ["builder"] }
thiserror = "1.0.61"
wasm-bindgen = "0.2.92"
idb = { version = "0.6", features = ["builder"] }
thiserror = "1"
wasm-bindgen = "0.2"

[dev-dependencies]
serde = { version = "1.0.164", features = ["derive"] }
serde_json = "1.0.97"
serde-wasm-bindgen = "0.5.0"
wasm-bindgen-test = "0.3.37"
js-sys = "0.3.69"
num-traits = { version = "0.2.19", default-features = false }
serde = { version = "1", features = ["derive"] }
serde_json = "1"
serde-wasm-bindgen = "0.6"
wasm-bindgen-test = "0.3"
js-sys = "0.3"
num-traits = { version = "0.2", default-features = false }

[profile.release]
# Tell `rustc` to optimize for small code size.
Expand Down
23 changes: 21 additions & 2 deletions tests/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,12 @@ struct InvoiceRequest<'a> {
/// Creates a database
async fn create_db() -> Rexie {
assert!(Rexie::delete("test").await.is_ok());
create_db_with_version(1).await
}

async fn create_db_with_version(version: u32) -> Rexie {
let rexie = Rexie::builder("test")
.version(1)
.version(version)
.add_object_store(
ObjectStore::new("employees")
.key_path("id")
Expand All @@ -69,8 +72,12 @@ async fn create_db() -> Rexie {

/// Checks basic details of the database
async fn basic_test_db(rexie: &Rexie) {
basic_test_db_with_version(rexie, 1).await;
}

async fn basic_test_db_with_version(rexie: &Rexie, version: u32) {
assert_eq!(rexie.name(), "test");
assert_eq!(rexie.version(), Ok(1));
assert_eq!(rexie.version(), Ok(version));
assert_eq!(
rexie.store_names(),
vec!["departments", "employees", "invoices"]
Expand Down Expand Up @@ -524,3 +531,15 @@ async fn test_add_all_pass() {

close_and_delete_db(rexie).await;
}

#[wasm_bindgen_test]
async fn test_db_reopen() {
let rexie = create_db().await;
basic_test_db(&rexie).await;
rexie.close();

let rexie = create_db_with_version(2).await;
basic_test_db_with_version(&rexie, 2).await;

close_and_delete_db(rexie).await;
}

0 comments on commit 7d8730c

Please sign in to comment.