-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathmissing.rs
More file actions
120 lines (106 loc) · 3.1 KB
/
missing.rs
File metadata and controls
120 lines (106 loc) · 3.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
//! https://github.com/webpack/enhanced-resolve/blob/main/test/missing.test.js
use normalize_path::NormalizePath;
use crate::{AliasValue, ResolveContext, ResolveOptions, Resolver};
#[tokio::test]
async fn test() {
let f = super::fixture();
let data = [
(
"./missing-file",
vec![
f.join("missing-file"),
f.join("missing-file.js"),
f.join("missing-file.node"),
],
),
(
"missing-module",
vec![
f.join("node_modules/missing-module"),
f.parent().unwrap().join("node_modules"), // enhanced-resolve is "node_modules/missing-module"
],
),
(
"missing-module/missing-file",
vec![
f.join("node_modules/missing-module"),
// f.parent().unwrap().join("node_modules/missing-module"), // we don't report this
],
),
(
"m1/missing-file",
vec![
f.join("node_modules/m1/missing-file"),
f.join("node_modules/m1/missing-file.js"),
f.join("node_modules/m1/missing-file.node"),
// f.parent().unwrap().join("node_modules/m1"), // we don't report this
],
),
(
"m1/",
vec![
f.join("node_modules/m1/index"),
f.join("node_modules/m1/index.js"),
f.join("node_modules/m1/index.json"),
f.join("node_modules/m1/index.node"),
],
),
("m1/a", vec![f.join("node_modules/m1/a")]),
];
let resolver = Resolver::default();
for (specifier, missing_dependencies) in data {
let mut ctx = ResolveContext::default();
let _ = resolver.resolve_with_context(&f, specifier, &mut ctx).await;
for path in ctx.file_dependencies {
assert_eq!(path, path.normalize(), "{path:?}");
}
for path in missing_dependencies {
assert_eq!(path, path.normalize(), "{path:?}");
assert!(
ctx.missing_dependencies.contains(&path),
"{specifier}: {path:?} not in {:?}",
&ctx.missing_dependencies
);
}
}
}
#[tokio::test]
async fn alias_and_extensions() {
let f = super::fixture();
let resolver = Resolver::new(ResolveOptions {
alias: vec![
(
"@scope-js/package-name/dir$".into(),
vec![AliasValue::Path(
f.join("foo/index.js")
.to_str()
.expect("path should be UTF-8")
.to_string(),
)],
),
(
"react-dom".into(),
vec![AliasValue::Path(
f.join("foo/index.js")
.to_str()
.expect("path should be UTF-8")
.to_string(),
)],
),
],
extensions: vec![".server.ts".into()],
..ResolveOptions::default()
});
let mut ctx = ResolveContext::default();
let _ = resolver.resolve_with_context(&f, "@scope-js/package-name/dir/router", &mut ctx);
let _ = resolver.resolve_with_context(&f, "react-dom/client", &mut ctx);
for path in ctx.file_dependencies {
assert_eq!(path, path.normalize(), "{path:?}");
}
for path in ctx.missing_dependencies {
assert_eq!(path, path.normalize(), "{path:?}");
if let Some(path) = path.parent() {
assert!(!path.is_file(), "{path:?} must not be a file");
}
}
}