test(es/minifier): Enable size tests created from creduce (#6646)

This commit is contained in:
Donny/강동윤 2022-12-14 18:19:51 +09:00 committed by GitHub
parent b569cee03b
commit 7f3e6983e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
61 changed files with 67 additions and 38 deletions

View File

@ -1,7 +1,6 @@
use std::{
env,
fs::{self, create_dir_all, rename},
path::{Component, Path, PathBuf},
env, fs,
path::{Path, PathBuf},
process::Command,
sync::Arc,
};
@ -16,7 +15,7 @@ use swc_common::{errors::ColorConfig, SourceMap, GLOBALS};
use swc_ecma_ast::EsVersion;
use swc_ecma_parser::{EsConfig, Syntax, TsConfig};
use swc_ecma_testing::{exec_node_js, JsExecOptions};
use testing::{assert_eq, find_executable};
use testing::{assert_eq, find_executable, unignore_fixture};
use tracing::{span, Level};
trait IterExt<T>: Sized + IntoIterator<Item = T>
@ -220,7 +219,7 @@ fn run_fixture_test(entry: PathBuf) {
// Test was successful.
unignore(&entry);
unignore_fixture(&entry);
}
#[testing::fixture("tests/babel-exec/**/exec.js")]
@ -249,7 +248,7 @@ fn run_babel_fixture_exec_test(entry: PathBuf) {
// Test was successful.
unignore(&entry);
unignore_fixture(&entry);
}
fn get_expected_stdout(input: &Path) -> Result<String, Error> {
@ -315,33 +314,6 @@ fn get_expected_stdout(input: &Path) -> Result<String, Error> {
})
}
/// Rename `foo/.bar/exec.js` => `foo/bar/exec.js`
fn unignore(path: &Path) {
if path.components().all(|c| {
!matches!(c, Component::Normal(..)) || !c.as_os_str().to_string_lossy().starts_with('.')
}) {
return;
}
//
let mut new_path = PathBuf::new();
for c in path.components() {
if let Component::Normal(s) = c {
if let Some(s) = s.to_string_lossy().strip_prefix('.') {
new_path.push(s);
continue;
}
}
new_path.push(c);
}
create_dir_all(new_path.parent().unwrap()).expect("failed to create parent dir");
rename(path, &new_path).expect("failed to rename");
}
fn test_file_with_opts(
entry: &Path,
opts: &Options,

View File

@ -42,7 +42,7 @@ use swc_ecma_testing::{exec_node_js, JsExecOptions};
use swc_ecma_transforms_base::{fixer::fixer, hygiene::hygiene, resolver};
use swc_ecma_utils::drop_span;
use swc_ecma_visit::{FoldWith, Visit, VisitMut, VisitMutWith, VisitWith};
use testing::{assert_eq, DebugUsingDisplay, NormalizedOutput};
use testing::{assert_eq, unignore_fixture, DebugUsingDisplay, NormalizedOutput};
fn load_txt(filename: &str) -> Vec<String> {
let lines = read_to_string(filename).unwrap();
@ -431,7 +431,7 @@ fn projects_bench(input: PathBuf) {
Ok(())
})
.unwrap()
.unwrap();
}
/// Tests ported from terser.
@ -1712,7 +1712,8 @@ fn full(input: PathBuf) {
Ok(())
})
.unwrap()
.unwrap();
unignore_fixture(&input);
}
struct DropParens;

View File

@ -0,0 +1 @@
[]({c(){a({c:()=>b})}});

View File

@ -0,0 +1 @@
[](function(){a={b:{c:{"":{d:"Az̧ Z̧aāyin"}}}}});

View File

@ -0,0 +1 @@
[]({a(){b({c:{c:d?{c:{e:". Were working to bring this to a frameworks soon."}}:0}})}});

View File

@ -0,0 +1 @@
[](function(){var n=function(){n[b]}});

View File

@ -0,0 +1 @@
[](function(){var n=function(){0(function(){return n})}});

View File

@ -0,0 +1 @@
[](function(){var n=function(){b(function(){b(n)})}});

View File

@ -0,0 +1 @@
({function:()=>({})})();

View File

@ -0,0 +1 @@
[](function(){var n=function(){n.b}});

View File

@ -0,0 +1 @@
[](function(){var a=b;d.e(a);var r=b;d.e(r);var v=e(v)});

View File

@ -0,0 +1 @@
[]({d(){if(a)try{for(c;;);}catch{}}});

View File

@ -0,0 +1 @@
[](function(){a(function(){})});

View File

@ -0,0 +1 @@
[]({function(){a(function(){b(function(){for(var f;;)if(void 0==d)for(var f=e;;f);})})}});

View File

@ -0,0 +1 @@
self=self||[].push[{8:function(){0()}}];

View File

@ -0,0 +1 @@
[](function(){var n;n=function(){b(n)}});

View File

@ -0,0 +1 @@
a=b?function(){}:function(){};

View File

@ -0,0 +1 @@
[](function(){var n=function(){b(n)}});

View File

@ -0,0 +1 @@
self=self||[].push[{4:function(){0()},80288:0}];

View File

@ -0,0 +1 @@
[]({c(){a=({}).b}});

View File

@ -0,0 +1 @@
[]({b(){a;"use strict"}});

View File

@ -1,9 +1,9 @@
use std::{
env, fmt,
fmt::{Debug, Display, Formatter},
fs::{create_dir_all, File},
fs::{create_dir_all, rename, File},
io::Write,
path::{Path, PathBuf},
path::{Component, Path, PathBuf},
str::FromStr,
sync::RwLock,
thread,
@ -282,3 +282,30 @@ impl<'a> Debug for DebugUsingDisplay<'a> {
Display::fmt(self.0, f)
}
}
/// Rename `foo/.bar/exec.js` => `foo/bar/exec.js`
pub fn unignore_fixture(fixture_path: &Path) {
if fixture_path.components().all(|c| {
!matches!(c, Component::Normal(..)) || !c.as_os_str().to_string_lossy().starts_with('.')
}) {
return;
}
//
let mut new_path = PathBuf::new();
for c in fixture_path.components() {
if let Component::Normal(s) = c {
if let Some(s) = s.to_string_lossy().strip_prefix('.') {
new_path.push(s);
continue;
}
}
new_path.push(c);
}
create_dir_all(new_path.parent().unwrap()).expect("failed to create parent dir");
rename(fixture_path, &new_path).expect("failed to rename");
}