Skip to content

Commit

Permalink
WIP: Test for sourceFileName
Browse files Browse the repository at this point in the history
  • Loading branch information
kdy1 committed Aug 2, 2021
1 parent 23cdd87 commit 21ac6fa
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions tests/projects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use swc::{
config::{
BuiltConfig, Config, JscConfig, ModuleConfig, Options, SourceMapsConfig, TransformConfig,
},
Compiler,
Compiler, TransformOutput,
};
use swc_common::{chain, comments::Comment, BytePos, FileName};
use swc_ecma_ast::EsVersion;
Expand Down Expand Up @@ -60,6 +60,10 @@ fn file_with_opt(filename: &str, options: Options) -> Result<NormalizedOutput, S
}

fn str_with_opt(content: &str, options: Options) -> Result<NormalizedOutput, StdErr> {
compile_str(content, options).map(|v| v.code.into())
}

fn compile_str(content: &str, options: Options) -> Result<TransformOutput, StdErr> {
Tester::new().print_errors(|cm, handler| {
let c = Compiler::new(cm.clone(), Arc::new(handler));

Expand All @@ -77,7 +81,7 @@ fn str_with_opt(content: &str, options: Options) -> Result<NormalizedOutput, Std
if c.handler.has_errors() {
Err(())
} else {
Ok(v.code.into())
Ok(v)
}
}
Err(err) => panic!("Error: {:?}", err),
Expand Down Expand Up @@ -843,15 +847,16 @@ fn issue_1984() {
})
.unwrap()
fn opt_source_file_name_1() {
let res = str_with_opt(
let map = compile_str(
"import Foo from 'foo';",
Options {
source_file_name: Some("entry".into()),
source_maps: Some(SourceMapsConfig::Bool(true)),
..Default::default()
},
)
.unwrap();
.unwrap()
.map;

assert_eq!(res.to_string(), "")
assert_eq!(map.as_deref(), Some(""))
}

0 comments on commit 21ac6fa

Please sign in to comment.