feat(resolver): port incorrect description file test (#557)

This commit is contained in:
Boshen 2023-07-16 17:13:32 +08:00 committed by GitHub
parent c4de3675f1
commit e0a17ace8f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 50 additions and 21 deletions

View file

@ -48,7 +48,7 @@ Tests ported from [enhanced-resolve](https://github.com/webpack/enhanced-resolve
- [ ] getPaths.test.js
- [ ] identifier.test.js
- [ ] importsField.test.js
- [ ] incorrect-description-file.test.js
- [x] incorrect-description-file.test.js (need to add ctx.fileDependencies)
- [ ] missing.test.js
- [ ] path.test.js
- [ ] plugins.test.js

View file

@ -50,8 +50,8 @@ fn extension_alias() -> Result<(), ResolveError> {
}
#[test]
// should not apply extension alias to extensions or mainFiles field
fn not_apply_to_extension_nor_main_files() -> Result<(), ResolveError> {
// should not apply extension alias to extensions or mainFiles field
let options = ResolveOptions {
extensions: vec![".js".into()],
main_files: vec!["index.js".into()],

View file

@ -0,0 +1,47 @@
//! <https://github.com/webpack/enhanced-resolve/blob/main/test/incorrect-description-file.test.js>
use std::path::PathBuf;
use oxc_resolver::{JSONError, ResolveError, Resolver};
fn fixture() -> PathBuf {
super::fixture().join("incorrect-package")
}
// TODO: add `ctx with fileDependencies and then check file dependencies
#[test]
fn incorrect_description_file_1() {
// should not resolve main in incorrect description file #1
let f = fixture();
let resolution = Resolver::default().resolve(f.join("pack1"), ".");
let error = ResolveError::JSON(JSONError {
path: f.join("pack1/package.json"),
message: String::from("EOF while parsing a value at line 3 column 0"),
line: 3,
column: 0,
});
assert_eq!(resolution, Err(error));
}
#[test]
fn incorrect_description_file_2() {
// should not resolve main in incorrect description file #2
let f = fixture();
let resolution = Resolver::default().resolve(f.join("pack2"), ".");
let error = ResolveError::JSON(JSONError {
path: f.join("pack2/package.json"),
message: String::from("EOF while parsing a value at line 1 column 0"),
line: 1,
column: 0,
});
assert_eq!(resolution, Err(error));
}
#[test]
fn incorrect_description_file_3() {
// should not resolve main in incorrect description file #3
let f = fixture();
let resolution = Resolver::default().resolve(f.join("pack2"), ".");
assert!(resolution.is_err());
}

View file

@ -1,5 +1,6 @@
mod extension_alias;
mod extensions;
mod incorrect_description_file;
mod resolve;
mod simple;

View file

@ -1,17 +0,0 @@
use std::env;
use oxc_resolver::{JSONError, ResolveError, Resolver};
#[test]
fn broken_json() {
let dir = env::current_dir().unwrap().join("tests/error_handling/");
let resolver = Resolver::default();
let resolution = resolver.resolve(&dir, "./broken_package_json");
let error = ResolveError::JSON(JSONError {
path: dir.join("broken_package_json").join("package.json"),
message: String::from("expected value at line 1 column 1"),
line: 1,
column: 1,
});
assert_eq!(resolution, Err(error));
}

View file

@ -1,5 +1,4 @@
mod enhanced_resolve;
mod error_handling;
use std::{env, sync::Arc, thread};