Skip to content

Commit

Permalink
chore(resolver): add a path alias test (#1549)
Browse files Browse the repository at this point in the history
  • Loading branch information
Boshen authored Nov 26, 2023
1 parent 08b6594 commit 023e6ea
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
Empty file.
27 changes: 26 additions & 1 deletion crates/oxc_resolver/src/tests/alias.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! <https://github.com/webpack/enhanced-resolve/blob/main/test/alias.test.js>
use crate::{AliasValue, ResolveError, ResolveOptions, Resolver};
use crate::{AliasValue, Resolution, ResolveError, ResolveOptions, Resolver};

#[test]
#[cfg(not(target_os = "windows"))] // MemoryFS's path separator is always `/` so the test will not pass in windows.
Expand Down Expand Up @@ -127,6 +127,31 @@ fn absolute_path() {
assert_eq!(resolution, Err(ResolveError::Ignored(f.join("foo"))));
}

#[test]
fn system_path() {
let f = super::fixture();
let resolver = Resolver::new(ResolveOptions {
alias: vec![(
"@app".into(),
vec![AliasValue::Path(f.join("alias").to_str().unwrap().to_string())],
)],
..ResolveOptions::default()
});
let resolution = resolver.resolve(&f, "@app/files/a").map(Resolution::into_path_buf);
assert_eq!(resolution, Ok(f.join("alias/files/a.js")));
let string = resolution.unwrap().to_string_lossy().to_string();
#[cfg(target_os = "windows")]
{
assert!(!string.contains('/'));
assert!(string.contains('\\'));
}
#[cfg(not(target_os = "windows"))]
{
assert!(string.contains('/'));
assert!(!string.contains('\\'));
}
}

// Not part of enhanced-resolve
#[test]
fn infinite_recursion() {
Expand Down

0 comments on commit 023e6ea

Please sign in to comment.