Skip to content

Commit

Permalink
Canonicalize on tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kdy1 committed May 22, 2022
1 parent cdf6263 commit 90dbdaf
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions crates/swc_ecma_transforms_module/tests/path_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ use std::{
};

use indexmap::IndexMap;
use swc_common::FileName;
use swc_common::{chain, FileName};
use swc_ecma_ast::ImportDecl;
use swc_ecma_loader::resolvers::{node::NodeModulesResolver, tsc::TsConfigResolver};
use swc_ecma_parser::Syntax;
use swc_ecma_transforms_module::{
path::{ImportResolver, NodeImportResolver},
rewriter::import_rewriter,
};
use swc_ecma_transforms_testing::test_fixture;
use swc_ecma_visit::{as_folder, VisitMut};
use testing::run_test2;

type TestProvider = NodeImportResolver<NodeModulesResolver>;
Expand All @@ -34,6 +36,18 @@ fn node_modules() {
.unwrap();
}

struct Normalizer;

impl VisitMut for Normalizer {
fn visit_mut_import_decl(&mut self, i: &mut ImportDecl) {
if cfg!(target_os = "windows") {
let path = Path::new(&*i.src.value);
let p = path.canonicalize().unwrap();
i.src.value = p.display().to_string().into()
}
}
}

#[test]
fn issue_4730() {
let dir = Path::new("tests/fixture-manual/issue-4730");
Expand Down Expand Up @@ -79,9 +93,12 @@ fn issue_4730() {

let resolver = paths_resolver(&input_dir, rules);

import_rewriter(
FileName::Real(input_dir.join("src").join("index.js")),
resolver,
chain!(
import_rewriter(
FileName::Real(input_dir.join("src").join("index.js")),
resolver,
),
as_folder(Normalizer)
)
},
&input_dir.join("src").join("index.js"),
Expand Down

0 comments on commit 90dbdaf

Please sign in to comment.