Skip to content

Commit

Permalink
Move test for swc-project#225
Browse files Browse the repository at this point in the history
  • Loading branch information
kdy1 committed Nov 25, 2019
1 parent 3c93a07 commit 25b6e18
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
29 changes: 28 additions & 1 deletion tests/projects.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,26 @@
use swc::{config::Options, Compiler};
use testing::Tester;
use testing::{NormalizedOutput, StdErr, Tester};
use walkdir::WalkDir;

fn file(f: &str) -> Result<NormalizedOutput, StdErr> {
Tester::new().print_errors(|cm, handler| {
let c = Compiler::new(cm.clone(), handler);

let fm = cm.load_file(entry.path()).expect("failed to load file");
let s = c.process_js_file(
fm,
Options {
swcrc: true,
..Default::default()
},
);
match s {
Ok(v) => Ok(v.code.into()),
Err(e) => Err(()),
}
})
}

fn project(dir: &str) {
Tester::new()
.print_errors(|cm, handler| {
Expand Down Expand Up @@ -45,6 +64,14 @@ fn angular_core() {
project("tests/projects/angular-core");
}

/// should respect modules config in .swcrc
#[test]
fn issue_225() {
let s = file("tests/issue-225/input.js").unwrap();
assert!(s.contains("function _interopRequireDefault"));
assert!(s.contains("var _foo = _interopRequireDefault(require('foo'))"));
}

#[test]
fn issue_466_1() {
project("tests/projects/issue-466-1");
Expand Down
5 changes: 5 additions & 0 deletions tests/projects/issue-225/.swcrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"module": {
"type": "commonjs"
}
}
1 change: 1 addition & 0 deletions tests/projects/issue-225/input.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import foo from "foo"

0 comments on commit 25b6e18

Please sign in to comment.