Skip to content

Commit

Permalink
refactor(transformer): handle <CWD> in test runner (#7799)
Browse files Browse the repository at this point in the history
We should move the handling of  `<CWD>` to the test runner because this is just only used in testing, and it causes us always get a path by `self.ctx.source_path` like `<CWD>/xxx/xxx.js`, we should get a real path for this.
  • Loading branch information
Dunqing committed Dec 12, 2024
1 parent fb325dc commit b290ebd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
6 changes: 1 addition & 5 deletions crates/oxc_transformer/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,10 @@ impl<'a> TransformCtx<'a> {
.file_stem() // omit file extension
.map_or_else(|| String::from("unknown"), |name| name.to_string_lossy().to_string());

let source_path = source_path
.strip_prefix(&options.cwd)
.map_or_else(|_| source_path.to_path_buf(), |p| Path::new("<CWD>").join(p));

Self {
errors: RefCell::new(vec![]),
filename,
source_path,
source_path: source_path.to_path_buf(),
source_type: SourceType::default(),
source_text: "",
module: options.env.module,
Expand Down
10 changes: 8 additions & 2 deletions tasks/transform_conformance/src/test_case.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,17 @@ impl TestCase {
};

let source_text = fs::read_to_string(path).unwrap();

let project_root = project_root();
let mut options = transform_options.clone();
options.helper_loader.mode = mode;
let mut driver = Driver::new(false, options).execute(&source_text, self.source_type, path);
let cwd_path = self
.options
.cwd
.as_ref()
.and_then(|cwd| path.strip_prefix(cwd).ok().map(|p| Path::new("<CWD>").join(p)))
.unwrap_or(path.clone());
let mut driver =
Driver::new(false, options).execute(&source_text, self.source_type, cwd_path.as_path());
let errors = driver.errors();
if !errors.is_empty() {
let source = NamedSource::new(
Expand Down

0 comments on commit b290ebd

Please sign in to comment.