From 023e6eabcd5121ff1a231b5e1fcf8e9b2cf607d4 Mon Sep 17 00:00:00 2001 From: Boshen Date: Sun, 26 Nov 2023 15:14:32 +0800 Subject: [PATCH] chore(resolver): add a path alias test (#1549) --- .../test/fixtures/alias/files/a.js | 0 crates/oxc_resolver/src/tests/alias.rs | 27 ++++++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 crates/oxc_resolver/fixtures/enhanced_resolve/test/fixtures/alias/files/a.js diff --git a/crates/oxc_resolver/fixtures/enhanced_resolve/test/fixtures/alias/files/a.js b/crates/oxc_resolver/fixtures/enhanced_resolve/test/fixtures/alias/files/a.js new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/crates/oxc_resolver/src/tests/alias.rs b/crates/oxc_resolver/src/tests/alias.rs index aa9ecd51ef8b3..11d3197d8a589 100644 --- a/crates/oxc_resolver/src/tests/alias.rs +++ b/crates/oxc_resolver/src/tests/alias.rs @@ -1,6 +1,6 @@ //! -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. @@ -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() {