//! Test suite for nodejs.
#![cfg(target_arch = "wasm32")]
use mrml_wasm::ToHtmlError;
use wasm_bindgen_test::*;
#[wasm_bindgen_test]
fn it_should_render_template() {
let template = "Hello World";
let engine = mrml_wasm::Engine::new();
let result = engine.to_html(template);
assert!(matches!(result, mrml_wasm::ToHtmlResult::Success { .. }));
}
#[cfg(feature = "async")]
#[wasm_bindgen_test]
async fn it_should_render_template_async() {
let template = "Hello World";
let engine = mrml_wasm::Engine::new();
let result = engine.to_html_async(template).await;
assert!(matches!(result, mrml_wasm::ToHtmlResult::Success { .. }));
}
#[wasm_bindgen_test]
fn it_should_fail_when_render_template() {
let template = "Hello World match inner {
ToHtmlError::Parser { message } => {
assert_eq!(message, "unable to load included template")
}
other => panic!("unexpected error {:?}", other),
},
_ => panic!("shouldn't compile"),
}
}
#[cfg(feature = "async")]
#[wasm_bindgen_test]
async fn it_should_fail_when_render_template_async() {
let template = "Hello World match inner {
ToHtmlError::Parser { message } => {
assert_eq!(message, "unable to load included template")
}
other => panic!("unexpected error {:?}", other),
},
_ => panic!("shouldn't compile"),
}
}
#[wasm_bindgen_test]
fn it_should_disable_comments() {
let template = "Hello World";
let mut engine = mrml_wasm::Engine::new();
engine.set_render_options(mrml_wasm::RenderOptions {
disable_comments: true,
..Default::default()
});
let result = engine.to_html(template);
match result {
mrml_wasm::ToHtmlResult::Success { content } => {
assert_eq!(content.matches("Goodbye").count(), 0);
}
err => panic!("shouldn't fail {:?}", err),
}
}
#[cfg(feature = "async")]
#[wasm_bindgen_test]
async fn it_should_disable_comments_async() {
let template = "Hello World";
let mut engine = mrml_wasm::Engine::new();
engine.set_render_options(mrml_wasm::RenderOptions {
disable_comments: true,
..Default::default()
});
let result = engine.to_html_async(template).await;
match result {
mrml_wasm::ToHtmlResult::Success { content } => {
assert_eq!(content.matches("Goodbye").count(), 0);
}
err => panic!("shouldn't fail {:?}", err),
}
}
#[wasm_bindgen_test]
fn it_should_use_noop_include_loader_by_default() {
let template = "Hello World";
let mut engine = mrml_wasm::Engine::new();
engine.set_render_options(mrml_wasm::RenderOptions {
disable_comments: true,
..Default::default()
});
let result = engine.to_html(template);
match result {
mrml_wasm::ToHtmlResult::Error(inner) => match inner {
ToHtmlError::Parser { message } => {
assert_eq!(message, "unable to load included template")
}
other => panic!("unexpected error {:?}", other),
},
_ => panic!("shouldn't compile"),
}
}
#[cfg(feature = "async")]
#[wasm_bindgen_test]
async fn it_should_use_noop_include_loader_by_default_async() {
let template = "Hello World";
let mut engine = mrml_wasm::Engine::new();
engine.set_render_options(mrml_wasm::RenderOptions {
disable_comments: true,
..Default::default()
});
let result = engine.to_html_async(template).await;
match result {
mrml_wasm::ToHtmlResult::Error(inner) => match inner {
ToHtmlError::Parser { message } => {
assert_eq!(message, "unable to load included template")
}
other => panic!("unexpected error {:?}", other),
},
_ => panic!("shouldn't compile"),
}
}
#[wasm_bindgen_test]
fn it_should_use_memory_include_loader_by_default() {
let template = "";
let mut engine = mrml_wasm::Engine::new();
engine.set_parser_options(mrml_wasm::ParserOptions {
include_loader: mrml_wasm::IncludeLoaderOptions::Memory(
mrml_wasm::MemoryIncludeLoaderOptions {
content: [(
"./header.mjml".to_string(),
"Hello World".to_string(),
)]
.into(),
},
),
});
engine.set_render_options(mrml_wasm::RenderOptions {
disable_comments: true,
..Default::default()
});
let result = engine.to_html(template);
let content = result.into_success();
assert_eq!(content.matches("Hello World").count(), 1);
}
#[cfg(feature = "async")]
#[wasm_bindgen_test]
async fn it_should_use_memory_include_loader_by_default_async() {
let template = "";
let mut engine = mrml_wasm::Engine::new();
engine.set_async_parser_options(mrml_wasm::AsyncParserOptions {
include_loader: mrml_wasm::AsyncIncludeLoaderOptions::Memory(
mrml_wasm::MemoryIncludeLoaderOptions {
content: [(
"./header.mjml".to_string(),
"Hello World".to_string(),
)]
.into(),
},
),
});
engine.set_render_options(mrml_wasm::RenderOptions {
disable_comments: true,
..Default::default()
});
let result = engine.to_html_async(template).await;
let content = result.into_success();
assert_eq!(content.matches("Hello World").count(), 1);
}