2020-06-13 17:09:45 +03:00
|
|
|
use std::{path::Path, sync::Arc};
|
2020-05-19 14:24:00 +03:00
|
|
|
use swc::{config::Options, Compiler};
|
|
|
|
use testing::{NormalizedOutput, Tester};
|
|
|
|
|
|
|
|
fn file(f: &str) -> NormalizedOutput {
|
|
|
|
Tester::new()
|
|
|
|
.print_errors(|cm, handler| -> Result<NormalizedOutput, _> {
|
2020-06-13 17:09:45 +03:00
|
|
|
let c = Compiler::new(cm.clone(), Arc::new(handler));
|
2020-05-19 14:24:00 +03:00
|
|
|
|
|
|
|
let fm = cm.load_file(Path::new(f)).expect("failed to load file");
|
|
|
|
let s = c.process_js_file(
|
|
|
|
fm,
|
|
|
|
&Options {
|
|
|
|
swcrc: true,
|
|
|
|
is_module: true,
|
|
|
|
..Default::default()
|
|
|
|
},
|
|
|
|
);
|
|
|
|
if let Err(e) = s {
|
|
|
|
return Ok(format!("{:?}", e).into());
|
|
|
|
}
|
|
|
|
|
|
|
|
panic!("invalid swcrc should abort build, but got {:?}", s);
|
|
|
|
})
|
|
|
|
.unwrap()
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn swcrc_simple() {
|
|
|
|
let f = file("tests/swcrc_errors/simple/foo.js");
|
|
|
|
println!("{}", f);
|
|
|
|
}
|