Selaa lähdekoodia

Re-enable WASM tests

David Peter 1 vuosi sitten
vanhempi
sitoutus
54c82f4489

+ 4 - 0
.github/workflows/ci.yml

@@ -77,6 +77,10 @@ jobs:
       run: |
         cd numbat-wasm
         bash build.sh
+    - name: Test WASM version
+      run: |
+        cd numbat-wasm
+        bash test.sh
 
   min_version:
     name: Minimum supported rust version

+ 1 - 1
numbat-wasm/README.md

@@ -12,5 +12,5 @@ Then open http://0.0.0.0:8000/ in a browser.
 
 Run tests:
 ``` bash
-wasm-pack test --headless --firefox
+bash test.sh
 ```

+ 4 - 2
numbat-wasm/src/lib.rs

@@ -61,9 +61,11 @@ impl InterpreterOutput {
 
 #[wasm_bindgen]
 impl Numbat {
-    pub fn new(enable_pretty_printing: bool, format_type: FormatType) -> Self {
+    pub fn new(load_prelude: bool, enable_pretty_printing: bool, format_type: FormatType) -> Self {
         let mut ctx = Context::new(BuiltinModuleImporter::default());
-        let _ = ctx.interpret("use prelude", CodeSource::Internal).unwrap();
+        if load_prelude {
+            let _ = ctx.interpret("use prelude", CodeSource::Internal).unwrap();
+        }
         ctx.set_terminal_width(Some(84)); // terminal width with current layout
         Numbat {
             ctx,

+ 3 - 0
numbat-wasm/test.sh

@@ -0,0 +1,3 @@
+#!/bin/bash
+
+wasm-pack test --headless --firefox

+ 6 - 2
numbat-wasm/tests/web.rs

@@ -1,11 +1,15 @@
 #![cfg(target_arch = "wasm32")]
 
-use numbat_wasm::interpret;
+use numbat_wasm::{FormatType, Numbat};
 use wasm_bindgen_test::*;
 
 wasm_bindgen_test_configure!(run_in_browser);
 
 #[wasm_bindgen_test]
 fn basic() {
-    assert_eq!(interpret("2 + 3 * 4"), "14 ");
+    let mut numbat = Numbat::new(false, false, FormatType::Html);
+    assert_eq!(
+        numbat.interpret("2 + 3 * 4").output().trim(),
+        r#"<span class="numbat-operator">=</span> <span class="numbat-value">14</span>"#
+    );
 }

+ 1 - 1
numbat-wasm/www/index.js

@@ -17,7 +17,7 @@ async function fetch_exchange_rates() {
 }
 
 function create_numbat_instance() {
-    return Numbat.new(true, FormatType.JqueryTerminal);
+    return Numbat.new(true, true, FormatType.JqueryTerminal);
 }
 
 function updateUrlQuery(query) {