Skip to content

Commit

Permalink
Organize wasm tests (#995)
Browse files Browse the repository at this point in the history
* organize wasm tests so they all run

* make test organization much better, fix tests

* fix workflow file
  • Loading branch information
insipx committed Aug 26, 2024
1 parent 44a8839 commit d43b891
Show file tree
Hide file tree
Showing 21 changed files with 373 additions and 112 deletions.
1 change: 1 addition & 0 deletions .github/workflows/release-cli.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ jobs:
- name: Configure x86_64-unknown-linux-musl toolchain
if: ${{ matrix.target == 'x86_64-unknown-linux-musl' }}
run: |
sudo apt-get update
sudo apt-get install -y musl-tools
- name: Install openssl windows
Expand Down
31 changes: 26 additions & 5 deletions .github/workflows/test-wasm.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
name: Test DIesel WASM Backend
name: Test Diesel WASM Backend
on:
push:
branches:
- main
pull_request:
# only run tests when related changes are made
paths:
- ".github/workflows/test-workspace.yml"
- ".github/workflows/test-wasm.yml"
- "dev/**"
- "diesel-wasm-sqlite/**"
- "Cargo.toml"
Expand All @@ -15,18 +15,39 @@ on:
jobs:
test:
name: Test
runs-on: warp-ubuntu-latest-x64-16x
# running with macos since it contains the safari driver
runs-on: warp-macos-13-arm64-6x
steps:
- name: Checkout
uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- run: brew install --cask firefox
- name: Update rust toolchains
run: rustup update
- name: Install wasm-pack
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
- name: Setup node and yarn
uses: actions/setup-node@v4
with:
node-version-file: ".node-version"
cache-dependency-path: "diesel-wasm-sqlite/yarn.lock"
cache: "yarn"
env:
SKIP_YARN_COREPACK_CHECK: "1"
- name: Enable corepack
run: corepack enable
- name: Run Yarn install
uses: borales/actions-yarn@v5
with:
cmd: --cwd diesel-wasm-sqlite/ install
- name: Cache
uses: Swatinem/rust-cache@v2
with:
workspaces: |
.
- name: Run cargo test on main workspace
run: wasm-pack test --manifest-path diesel-wasm-sqlite/Cargo.toml --features test-util --features unsafe-debug-query
- run: wasm-pack test --headless --safari --features unsafe-debug-query
working-directory: diesel-wasm-sqlite
- run: wasm-pack test --headless --chrome --features unsafe-debug-query
working-directory: diesel-wasm-sqlite
- run: wasm-pack test --headless --firefox --features unsafe-debug-query
working-directory: diesel-wasm-sqlite
11 changes: 11 additions & 0 deletions diesel-wasm-sqlite/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions diesel-wasm-sqlite/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ resolver = "2"
talc = { version = "4.4", default-features = false, features = ["lock_api"] }
diesel = { version = "2.2", features = ["i-implement-a-third-party-backend-and-opt-into-breaking-changes"] }
diesel_derives = "2.2"
wasm-bindgen = "0.2.92"
wasm-bindgen = "0.2"
wasm-bindgen-futures = "0.4"
js-sys = { version = "0.3" }
tracing = "0.1"
Expand All @@ -27,6 +27,7 @@ chrono = { version = "0.4", features = ["wasmbind", "serde"] }
diesel_migrations = "2.2"
diesel = { version = "2.2", features = ["chrono"]}
tracing-wasm = { version = "0.2" }
ctor = "0.2"


[lib]
Expand All @@ -38,7 +39,6 @@ r2d2 = ["diesel/r2d2"]
# enables a `DebugQueryWrapper` for diesel
# but is unsafe because of mem::transmute
unsafe-debug-query = []
test-util = ["unsafe-debug-query"]

[build]
target = "wasm32-unknown-unknown"
Expand Down
1 change: 1 addition & 0 deletions diesel-wasm-sqlite/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ fn main() {
println!("cargo::rerun-if-changed=package.js");
println!("cargo::rerun-if-changed=package.json");

Command::new("yarn").args(["install"]).status().unwrap();
Command::new("yarn")
.args(["run", "build"])
.status()
Expand Down
4 changes: 4 additions & 0 deletions diesel-wasm-sqlite/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ export class SQLite {
return this.sqlite3.version;
}

filename(db, name) {
return this.sqlite3.capi.sqlite3_db_filename(db, name);
}

extended_errcode(connection) {
return this.sqlite3.capi.sqlite3_extended_errcode(connection);
}
Expand Down
2 changes: 1 addition & 1 deletion diesel-wasm-sqlite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
},
"packageManager": "yarn@4.3.1",
"engines": {
"node": ">=20"
"node": ">=18"
},
"devDependencies": {
"@rollup/plugin-node-resolve": "^15.2.3",
Expand Down
6 changes: 5 additions & 1 deletion diesel-wasm-sqlite/src/connection/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,10 @@ impl WasmSqliteConnection {
fn establish_inner(database_url: &str) -> Result<WasmSqliteConnection, ConnectionError> {
let sqlite3 = crate::get_sqlite_unchecked();
let raw_connection = RawConnection::establish(database_url).unwrap();
tracing::debug!(
"Established database at {}",
sqlite3.filename(&raw_connection.internal_connection, "main".into())
);
sqlite3
.register_diesel_sql_functions(&raw_connection.internal_connection)
.map_err(WasmSqliteError::from)?;
Expand All @@ -322,6 +326,6 @@ pub struct Nothing;

impl Instrumentation for Nothing {
fn on_connection_event(&mut self, event: diesel::connection::InstrumentationEvent<'_>) {
tracing::info!("Inst. Event {:?}", event);
tracing::trace!("{:?}", event);
}
}
2 changes: 1 addition & 1 deletion diesel-wasm-sqlite/src/connection/stmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ impl Statement {
impl Drop for Statement {
fn drop(&mut self) {
let sqlite3 = crate::get_sqlite_unchecked();
tracing::info!("Statement dropped & finalized!");
tracing::trace!("Statement dropped & finalized!");
let _ = sqlite3
.finalize(&self.inner_statement)
.expect("Error finalized SQLite prepared statement");
Expand Down
3 changes: 3 additions & 0 deletions diesel-wasm-sqlite/src/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@ extern "C" {
#[wasm_bindgen(method)]
pub fn version(this: &SQLite) -> JsValue;

#[wasm_bindgen(method)]
pub fn filename(this: &SQLite, db: &JsValue, name: String) -> String;

#[wasm_bindgen(method)]
pub fn errstr(this: &SQLite, code: i32) -> String;

Expand Down
13 changes: 0 additions & 13 deletions diesel-wasm-sqlite/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ pub use query_builder::insert_with_default_sqlite::unsafe_debug_query::DebugQuer
#[cfg(not(target_arch = "wasm32"))]
compile_error!("This crate only suports the `wasm32-unknown-unknown` target");

#[cfg(any(test))]
pub use test_common::*;

use wasm_bindgen::JsValue;

pub use backend::{SqliteType, WasmSqlite};
Expand Down Expand Up @@ -53,13 +50,3 @@ impl From<JsValue> for WasmSqliteError {
WasmSqliteError::Js(err)
}
}

#[cfg(any(test, feature = "test-util"))]
pub mod test_common {
use super::connection::WasmSqliteConnection;
use diesel::Connection;
pub async fn connection() -> WasmSqliteConnection {
crate::init_sqlite().await;
WasmSqliteConnection::establish(":memory:").unwrap()
}
}
2 changes: 1 addition & 1 deletion diesel-wasm-sqlite/src/query_builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use diesel::result::QueryResult;

pub(super) mod insert_with_default_sqlite;
mod limit_offset;
mod query_fragment_impls;
// mod query_fragment_impls;
// mod returning;

/// Constructs SQL queries for use with the SQLite backend
Expand Down
11 changes: 5 additions & 6 deletions diesel-wasm-sqlite/src/query_builder/query_fragment_impls.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/*
// use diesel::query_builder::into_conflict_clause::OnConflictSelectWrapper;
// use diesel::query_builder::where_clause::BoxedWhereClause;
use crate::WasmSqlite;
use diesel::query_builder::into_conflict_clause::OnConflictSelectWrapper;
use diesel::query_builder::where_clause::BoxedWhereClause;
use diesel::query_builder::where_clause::WhereClause;
use diesel::query_builder::AstPass;
use diesel::query_builder::BoxedSelectStatement;
use diesel::query_builder::QueryFragment;
use diesel::query_builder::SelectStatement;
// use diesel::query_builder::WhereClause;
use crate::storage::wasm_sqlite::WasmSqlite;
use diesel::result::QueryResult;
use diesel::QueryId;

// The corresponding impl for`NoWhereClause` is missing because of
// https://www.sqlite.org/lang_UPSERT.html (Parsing Ambiguity)
Expand Down Expand Up @@ -38,4 +38,3 @@ where
})
}
}
*/
Loading

0 comments on commit d43b891

Please sign in to comment.