fix: Fix tests on windows (#1419)

Co-authored-by: 강동윤 <kdy1997.dev@gmail.com>
This commit is contained in:
Jakub Koralewski 2021-02-22 16:33:11 +01:00 committed by GitHub
parent f28cd51e22
commit 59bd00d841
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 34 additions and 16 deletions

11
.gitattributes vendored
View File

@ -2,8 +2,9 @@
* text=auto
*.ts text merge=union eol=lf
*.tsx text merge=union eol=lf
*.rs text merge=union eol=lf
*.js text merge=union eol=lf
*.json text merge=union eol=lf
*.ts text eol=lf merge=union
*.tsx text eol=lf merge=union
*.rs text eol=lf merge=union
*.js text eol=lf merge=union
*.json text eol=lf merge=union
*.debug text eol=lf merge=union

View File

@ -33,7 +33,6 @@ fn add_test<F: FnOnce() + Send + 'static>(
}
#[test]
fn fixture() {
let args: Vec<_> = env::args().collect();
let mut tests = Vec::new();
@ -63,7 +62,7 @@ fn add_fixture(tests: &mut Vec<TestDescAndFn>) -> Result<(), Error> {
let fm = cm
.load_file(entry.path())
.expect("failed to load fixtue file");
.expect("failed to load fixture file");
let lexer = Lexer::new(
Syntax::Es(EsConfig {

View File

@ -70,7 +70,7 @@
"@types/node": "^14.0.5",
"axios": "^0.21.1",
"babel-plugin-transform-node-env-inline": "^0.4.3",
"browserslist": "^4.12.0",
"browserslist": "^4.16.3",
"jest": "^23.6.0",
"lodash": "^4.17.11",
"progress": "^2.0.3",

View File

@ -44,5 +44,8 @@ walkdir = "2.3.1"
[target.'cfg(all(unix, not(target_env = "musl")))'.dev-dependencies]
jemallocator = {version = "0.3", features = ["disable_initial_exec_tls"]}
[target.'cfg(windows)'.dependencies]
normpath="0.2"
[target.'cfg(windows)'.dev-dependencies]
mimalloc = {version = "0.1"}

View File

@ -1,4 +1,5 @@
#![cfg_attr(test, feature(test))]
#![feature(or_patterns)]
#[cfg(test)]
extern crate test;

View File

@ -4,13 +4,17 @@
use anyhow::{bail, Context, Error};
use lru::LruCache;
#[cfg(windows)]
use normpath::BasePath;
// use path_slash::{PathBufExt, PathExt};
use serde::Deserialize;
use std::{
fs::File,
io::BufReader,
path::{Path, PathBuf},
path::{Component, Path, PathBuf},
sync::Mutex,
};
use swc_bundler::Resolve;
use swc_common::FileName;
@ -49,7 +53,7 @@ impl NodeResolver {
}
fn wrap(&self, base: &PathBuf, target: &str, path: PathBuf) -> Result<FileName, Error> {
let path = path.canonicalize().context("failaed to canonicalize")?;
let path = path.canonicalize().context("failed to canonicalize")?;
self.store(base, target, path.clone());
Ok(FileName::Real(path))
}
@ -176,12 +180,10 @@ impl Resolve for NodeResolver {
Err(_) => {}
}
}
let target_path = Path::new(target);
// Absolute path
if target.starts_with("/") {
let base_dir = &Path::new("/");
let path = base_dir.join(target);
if target_path.is_absolute() {
let path = PathBuf::from(target_path);
return self
.resolve_as_file(&path)
.or_else(|_| self.resolve_as_directory(&path))
@ -190,8 +192,19 @@ impl Resolve for NodeResolver {
let cwd = &Path::new(".");
let base_dir = base.parent().unwrap_or(&cwd);
let mut components = target_path.components();
if target.starts_with("./") || target.starts_with("../") {
if let Some(Component::CurDir | Component::ParentDir) = components.next() {
#[cfg(windows)]
let path = {
let base_dir = BasePath::new(base_dir).unwrap();
base_dir
.join(target.replace('/', "\\"))
.normalize_virtually()
.unwrap()
.into_path_buf()
};
#[cfg(not(windows))]
let path = base_dir.join(target);
return self
.resolve_as_file(&path)

View File

@ -133,6 +133,7 @@ pub fn expand(test_file: &SourceFile, callee: &Ident, attr: Config) -> Result<Ve
callee,
path_for_name
.to_string_lossy()
.replace("\\", "__")
.replace("/", "__")
.replace(".", "_")
.replace("-", "_")