Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(tasks/transforme_conformance): support for testing oxc's test cases #2835

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions tasks/transform_conformance/oxc.snap.md
@@ -0,0 +1,9 @@
Passed: 0/1

# All Passed:



# babel-plugin-transform-optional-catch-binding (0/1)
* try-catch-shadow/input.js

6 changes: 6 additions & 0 deletions tasks/transform_conformance/oxc_exec.snap.md
@@ -0,0 +1,6 @@
Passed: 0/0

# All Passed:



35 changes: 23 additions & 12 deletions tasks/transform_conformance/src/lib.rs
Expand Up @@ -32,6 +32,10 @@ fn root() -> PathBuf {
project_root().join("tasks/coverage/babel/packages")
}

fn oxc_test_root() -> PathBuf {
project_root().join("tasks/transform_conformance/tests")
}

fn snap_root() -> PathBuf {
project_root().join("tasks/transform_conformance")
}
Expand Down Expand Up @@ -96,7 +100,9 @@ const CASES: &[&str] = &[
const EXCLUDE_TESTS: &[&str] = &["babel-plugin-transform-typescript/test/fixtures/enum"];

const CONFORMANCE_SNAPSHOT: &str = "babel.snap.md";
const OXC_CONFORMANCE_SNAPSHOT: &str = "oxc.snap.md";
const EXEC_SNAPSHOT: &str = "babel_exec.snap.md";
const OXC_EXEC_SNAPSHOT: &str = "oxc_exec.snap.md";

struct SnapshotOption {
paths: IndexMap<String, Vec<TestCaseKind>>,
Expand All @@ -116,17 +122,22 @@ impl TestRunner {

/// # Panics
pub fn run(self) {
let root = root();
let (transform_paths, exec_files) = Self::glob_files(&root, self.options.filter.as_ref());
self.generate_snapshot(SnapshotOption::new(transform_paths, CONFORMANCE_SNAPSHOT));

if self.options.exec {
let fixture_root = fixture_root();
if !fixture_root.exists() {
fs::create_dir(&fixture_root).unwrap();
for (root, snapshot, exec_snapshot) in &[
(root(), CONFORMANCE_SNAPSHOT, EXEC_SNAPSHOT),
(oxc_test_root(), OXC_CONFORMANCE_SNAPSHOT, OXC_EXEC_SNAPSHOT),
] {
let (transform_paths, exec_files) =
Self::glob_files(root, self.options.filter.as_ref());
self.generate_snapshot(root, SnapshotOption::new(transform_paths, snapshot));

if self.options.exec {
let fixture_root = fixture_root();
if !fixture_root.exists() {
fs::create_dir(&fixture_root).unwrap();
}
self.generate_snapshot(root, SnapshotOption::new(exec_files, exec_snapshot));
let _ = fs::remove_dir_all(fixture_root);
}
self.generate_snapshot(SnapshotOption::new(exec_files, EXEC_SNAPSHOT));
let _ = fs::remove_dir_all(fixture_root);
}
}

Expand Down Expand Up @@ -178,7 +189,7 @@ impl TestRunner {
(transform_files, exec_files)
}

fn generate_snapshot(&self, option: SnapshotOption) {
fn generate_snapshot(&self, root: &Path, option: SnapshotOption) {
let SnapshotOption { paths, dest } = option;
let mut snapshot = String::new();
let mut total = 0;
Expand All @@ -191,7 +202,7 @@ impl TestRunner {
continue;
}

let case_root = root().join(&case).join("test/fixtures");
let case_root = root.join(&case).join("test/fixtures");
let num_of_tests = test_cases.len();
total += num_of_tests;

Expand Down
@@ -0,0 +1,3 @@
{
"plugins": ["transform-optional-catch-binding"]
}
@@ -0,0 +1,6 @@
const _unused = "It's a lie, They gonna use me:(";
try {
throw 0;
} catch {
console.log(_unused);
}
@@ -0,0 +1,6 @@
const _unused = "It's a lie, They gonna use me:(";
try {
throw 0;
} catch (_unused2) {
console.log(_unused);
}