Skip to content

Commit

Permalink
refactor(resolver): move tests folder to fixtures (#964)
Browse files Browse the repository at this point in the history
  • Loading branch information
Boshen authored Oct 8, 2023
1 parent 30c2b91 commit 7e84369
Show file tree
Hide file tree
Showing 234 changed files with 31 additions and 29 deletions.
File renamed without changes.
10 changes: 5 additions & 5 deletions crates/oxc_resolver/src/tests/alias.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
//! <https://github.com/webpack/enhanced-resolve/blob/main/test/alias.test.js>
use std::path::{Path, PathBuf};

use crate::{AliasValue, ResolveError, ResolveOptions, Resolver, ResolverGeneric};

use super::memory_fs::MemoryFS;
use crate::{AliasValue, ResolveError, ResolveOptions, Resolver};

#[test]
#[cfg(not(target_os = "windows"))] // MemoryFS's path separator is always `/` so the test will not pass in windows.
fn alias() {
use super::memory_fs::MemoryFS;
use crate::ResolverGeneric;
use std::path::{Path, PathBuf};

let f = Path::new("/");

let file_system = MemoryFS::new(&[
Expand Down
10 changes: 4 additions & 6 deletions crates/oxc_resolver/src/tests/fallback.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
//! https://github.com/webpack/enhanced-resolve/blob/main/test/fallback.test.js
use std::path::{Path, PathBuf};

use crate::{AliasValue, ResolveError, ResolveOptions, ResolverGeneric};

use super::memory_fs::MemoryFS;

#[test]
#[cfg(not(target_os = "windows"))] // MemoryFS's path separator is always `/` so the test will not pass in windows.
fn fallback() {
use super::memory_fs::MemoryFS;
use crate::{AliasValue, ResolveError, ResolveOptions, ResolverGeneric};
use std::path::{Path, PathBuf};

let f = Path::new("/");

let file_system = MemoryFS::new(&[
Expand Down
4 changes: 1 addition & 3 deletions crates/oxc_resolver/src/tests/incorrect_description_file.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
//! <https://github.com/webpack/enhanced-resolve/blob/main/test/incorrect-description-file.test.js>
use std::env;

use crate::{JSONError, Resolution, ResolveError, ResolveOptions, Resolver};

// TODO: add `ctx with fileDependencies and then check file dependencies
Expand Down Expand Up @@ -45,7 +43,7 @@ fn incorrect_description_file_3() {
// `enhanced_resolve` does not have this test case
#[test]
fn no_description_file() {
let f = env::current_dir().unwrap().join("tests/enhanced_resolve");
let f = super::fixture_root().join("enhanced_resolve");

// has description file
let resolver = Resolver::default();
Expand Down
6 changes: 5 additions & 1 deletion crates/oxc_resolver/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,12 @@ mod tsconfig_project_references;
use crate::Resolver;
use std::{env, path::PathBuf, sync::Arc, thread};

pub fn fixture_root() -> PathBuf {
env::current_dir().unwrap().join("fixtures")
}

pub fn fixture() -> PathBuf {
env::current_dir().unwrap().join("tests/enhanced_resolve/test/fixtures")
fixture_root().join("enhanced_resolve/test/fixtures")
}

#[test]
Expand Down
4 changes: 2 additions & 2 deletions crates/oxc_resolver/src/tests/roots.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
//! <https://github.com/webpack/enhanced-resolve/blob/main/test/roots.test.js>
use std::{env, path::PathBuf};
use std::path::PathBuf;

use crate::{AliasValue, ResolveError, ResolveOptions, Resolver};

fn dirname() -> PathBuf {
env::current_dir().unwrap().join("tests/enhanced_resolve/test")
super::fixture_root().join("enhanced_resolve/test")
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_resolver/src/tests/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::Resolver;
#[test]
fn simple() {
// mimic `enhanced-resolve/test/simple.test.js`
let dirname = env::current_dir().unwrap().join("tests");
let dirname = env::current_dir().unwrap().join("fixtures");
let f = dirname.join("enhanced_resolve/test");

let resolver = Resolver::default();
Expand Down
4 changes: 2 additions & 2 deletions crates/oxc_resolver/src/tests/symlink.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{env, fs, io, path::Path};
use std::{fs, io, path::Path};

use crate::{ResolveOptions, Resolver};

Expand Down Expand Up @@ -63,7 +63,7 @@ fn cleanup_symlinks(temp_path: &Path) {

#[test]
fn test() -> io::Result<()> {
let root = env::current_dir().unwrap().join("tests/enhanced_resolve");
let root = super::fixture_root().join("enhanced_resolve");
let dirname = root.join("test");
let temp_path = dirname.join("temp");
if !temp_path.exists() {
Expand Down
9 changes: 3 additions & 6 deletions crates/oxc_resolver/src/tests/tsconfig_paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,12 @@
use super::memory_fs::MemoryFS;
use crate::{ResolveError, ResolveOptions, Resolver, ResolverGeneric, TsConfig};
use std::{
env,
path::{Path, PathBuf},
};
use std::path::{Path, PathBuf};

// <https://github.com/parcel-bundler/parcel/blob/b6224fd519f95e68d8b93ba90376fd94c8b76e69/packages/utils/node-resolver-rs/src/lib.rs#L2303>
#[test]
fn tsconfig() {
let f = env::current_dir().unwrap().join("tests/parcel");
let f = super::fixture_root().join("parcel");

#[rustfmt::skip]
let pass = [
Expand Down Expand Up @@ -51,7 +48,7 @@ fn tsconfig() {

#[test]
fn json_with_comments() {
let f = env::current_dir().unwrap().join("tests/parcel/tsconfig/trailing-comma");
let f = super::fixture_root().join("parcel/tsconfig/trailing-comma");

let resolver = Resolver::new(ResolveOptions {
tsconfig: Some(f.join("tsconfig.json")),
Expand Down
3 changes: 1 addition & 2 deletions crates/oxc_resolver/src/tests/tsconfig_project_references.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
//! Tests for tsconfig project references
use crate::{ResolveOptions, Resolver};
use std::env;

#[test]
fn test() {
let f = env::current_dir().unwrap().join("tests/tsconfig_project_references");
let f = super::fixture_root().join("tsconfig_project_references");

let resolver = Resolver::new(ResolveOptions {
tsconfig: Some(f.join("app")),
Expand Down
1 change: 1 addition & 0 deletions crates/oxc_resolver/tests/enhanced_resolve/test/temp/lib
1 change: 1 addition & 0 deletions crates/oxc_resolver/tests/enhanced_resolve/test/temp/that
1 change: 1 addition & 0 deletions crates/oxc_resolver/tests/enhanced_resolve/test/temp/this
2 changes: 1 addition & 1 deletion tasks/benchmark/benches/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use oxc_tasks_common::project_root;
use rayon::prelude::*;

fn data() -> Vec<(PathBuf, &'static str)> {
let cwd = project_root().join("crates/oxc_resolver/tests/enhanced_resolve");
let cwd = project_root().join("crates/oxc_resolver/fixtures/enhanced_resolve");
let f = cwd.join("test/fixtures");
vec![
(cwd.clone(), "./"),
Expand Down

0 comments on commit 7e84369

Please sign in to comment.