From 252f3a8d38f0dca44338267b03df0d15d958c50a Mon Sep 17 00:00:00 2001 From: Dunqing Date: Wed, 27 Mar 2024 11:33:29 +0800 Subject: [PATCH] feat(tasks/transforme_conformance): support for testing oxc's test cases --- tasks/transform_conformance/oxc.snap.md | 9 +++++ tasks/transform_conformance/oxc_exec.snap.md | 6 ++++ tasks/transform_conformance/src/lib.rs | 35 ++++++++++++------- .../test/fixtures/options.json | 3 ++ .../test/fixtures/try-catch-shadow/input.js | 6 ++++ .../test/fixtures/try-catch-shadow/output.js | 6 ++++ 6 files changed, 53 insertions(+), 12 deletions(-) create mode 100644 tasks/transform_conformance/oxc.snap.md create mode 100644 tasks/transform_conformance/oxc_exec.snap.md create mode 100644 tasks/transform_conformance/tests/babel-plugin-transform-optional-catch-binding/test/fixtures/options.json create mode 100644 tasks/transform_conformance/tests/babel-plugin-transform-optional-catch-binding/test/fixtures/try-catch-shadow/input.js create mode 100644 tasks/transform_conformance/tests/babel-plugin-transform-optional-catch-binding/test/fixtures/try-catch-shadow/output.js diff --git a/tasks/transform_conformance/oxc.snap.md b/tasks/transform_conformance/oxc.snap.md new file mode 100644 index 000000000000..3e42de1a55c9 --- /dev/null +++ b/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 + diff --git a/tasks/transform_conformance/oxc_exec.snap.md b/tasks/transform_conformance/oxc_exec.snap.md new file mode 100644 index 000000000000..99fcdd3bacf3 --- /dev/null +++ b/tasks/transform_conformance/oxc_exec.snap.md @@ -0,0 +1,6 @@ +Passed: 0/0 + +# All Passed: + + + diff --git a/tasks/transform_conformance/src/lib.rs b/tasks/transform_conformance/src/lib.rs index d318acbfd27f..8030ef9302af 100644 --- a/tasks/transform_conformance/src/lib.rs +++ b/tasks/transform_conformance/src/lib.rs @@ -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") } @@ -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>, @@ -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); } } @@ -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; @@ -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; diff --git a/tasks/transform_conformance/tests/babel-plugin-transform-optional-catch-binding/test/fixtures/options.json b/tasks/transform_conformance/tests/babel-plugin-transform-optional-catch-binding/test/fixtures/options.json new file mode 100644 index 000000000000..09559345df99 --- /dev/null +++ b/tasks/transform_conformance/tests/babel-plugin-transform-optional-catch-binding/test/fixtures/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["transform-optional-catch-binding"] +} diff --git a/tasks/transform_conformance/tests/babel-plugin-transform-optional-catch-binding/test/fixtures/try-catch-shadow/input.js b/tasks/transform_conformance/tests/babel-plugin-transform-optional-catch-binding/test/fixtures/try-catch-shadow/input.js new file mode 100644 index 000000000000..41ada5aa0876 --- /dev/null +++ b/tasks/transform_conformance/tests/babel-plugin-transform-optional-catch-binding/test/fixtures/try-catch-shadow/input.js @@ -0,0 +1,6 @@ +const _unused = "It's a lie, They gonna use me:("; +try { + throw 0; +} catch { + console.log(_unused); +} \ No newline at end of file diff --git a/tasks/transform_conformance/tests/babel-plugin-transform-optional-catch-binding/test/fixtures/try-catch-shadow/output.js b/tasks/transform_conformance/tests/babel-plugin-transform-optional-catch-binding/test/fixtures/try-catch-shadow/output.js new file mode 100644 index 000000000000..2c90680df6d8 --- /dev/null +++ b/tasks/transform_conformance/tests/babel-plugin-transform-optional-catch-binding/test/fixtures/try-catch-shadow/output.js @@ -0,0 +1,6 @@ +const _unused = "It's a lie, They gonna use me:("; +try { + throw 0; +} catch (_unused2) { + console.log(_unused); +} \ No newline at end of file