Some checks failed
Test examples / Test Examples (20) (push) Has been cancelled
Test examples / Test Examples (22) (push) Has been cancelled
Lock Threads / action (push) Has been cancelled
Trigger Release / start (push) Has been cancelled
Stale issue handler / stale (push) Has been cancelled
Update Font Data / create-pull-request (push) Has been cancelled
build-and-deploy / deploy-target (push) Has been cancelled
build-and-deploy / build (push) Has been cancelled
build-and-deploy / stable - aarch64-unknown-linux-musl - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-unknown-linux-musl - node@16 (push) Has been cancelled
build-and-deploy / stable - aarch64-unknown-linux-gnu - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-unknown-linux-gnu - node@16 (push) Has been cancelled
build-and-deploy / stable - aarch64-pc-windows-msvc - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-pc-windows-msvc - node@16 (push) Has been cancelled
build-and-deploy / stable - aarch64-apple-darwin - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-apple-darwin - node@16 (push) Has been cancelled
build-and-deploy / build-wasm (nodejs) (push) Has been cancelled
build-and-deploy / build-wasm (web) (push) Has been cancelled
build-and-deploy / Deploy preview tarball (push) Has been cancelled
build-and-deploy / Potentially publish release (push) Has been cancelled
build-and-deploy / publish-turbopack-npm-packages (push) Has been cancelled
build-and-deploy / Deploy examples (push) Has been cancelled
build-and-deploy / thank you, build (push) Has been cancelled
build-and-deploy / Upload Turbopack Bytesize metrics to Datadog (push) Has been cancelled
Rspack Next.js development integration tests / Rspack integration tests (push) Has been cancelled
Rspack Next.js production integration tests / Rspack integration tests (push) Has been cancelled
Turbopack Next.js development integration tests / Next.js integration tests (push) Has been cancelled
Turbopack Next.js production integration tests / Next.js integration tests (push) Has been cancelled
Update Rspack test manifest / Update and upload Rspack development test manifest (push) Has been cancelled
Update Rspack test manifest / Update and upload Rspack production test manifest (push) Has been cancelled
Upload bundler test manifests to areweturboyet.com / Upload test results (push) Has been cancelled
Update React / create-pull-request (push) Has been cancelled
test-e2e-project-reset-cron / reset-test-project (push) Has been cancelled
Notify about the top 15 issues/PRs/feature requests (most reacted) in the last 90 days / run (push) Has been cancelled
132 lines
4.3 KiB
Rust
132 lines
4.3 KiB
Rust
use std::path::{Path, PathBuf};
|
|
|
|
use next_custom_transforms::chain_transforms::{TransformOptions, custom_before_pass};
|
|
use serde::de::DeserializeOwned;
|
|
use swc_core::{
|
|
base::Compiler,
|
|
common::{Mark, comments::SingleThreadedComments},
|
|
ecma::{
|
|
ast::noop_pass,
|
|
parser::{Syntax, TsSyntax},
|
|
},
|
|
};
|
|
use testing::{NormalizedOutput, Tester};
|
|
|
|
#[testing::fixture("tests/full/**/input.js")]
|
|
fn full(input: PathBuf) {
|
|
test(&input, true);
|
|
}
|
|
|
|
#[testing::fixture("tests/loader/**/input.js")]
|
|
fn loader(input: PathBuf) {
|
|
test(&input, false);
|
|
}
|
|
|
|
fn test(input: &Path, minify: bool) {
|
|
let output = input.parent().unwrap().join("output.js");
|
|
|
|
Tester::new()
|
|
.print_errors(|cm, handler| {
|
|
let c = Compiler::new(cm.clone());
|
|
|
|
let fm = cm.load_file(input).expect("failed to load file");
|
|
|
|
let options = TransformOptions {
|
|
lint_codemod_comments: true,
|
|
swc: swc_core::base::config::Options {
|
|
swcrc: true,
|
|
output_path: Some(output.clone()),
|
|
|
|
config: swc_core::base::config::Config {
|
|
is_module: Some(swc_core::base::config::IsModule::Unknown),
|
|
|
|
jsc: swc_core::base::config::JscConfig {
|
|
minify: if minify {
|
|
Some(assert_json("{ \"compress\": true, \"mangle\": true }"))
|
|
} else {
|
|
None
|
|
},
|
|
syntax: Some(Syntax::Typescript(TsSyntax {
|
|
tsx: true,
|
|
..Default::default()
|
|
})),
|
|
external_helpers: true.into(),
|
|
..Default::default()
|
|
},
|
|
..Default::default()
|
|
},
|
|
..Default::default()
|
|
},
|
|
disable_next_ssg: false,
|
|
pages_dir: None,
|
|
is_page_file: false,
|
|
is_development: true,
|
|
is_server_compiler: false,
|
|
server_components: None,
|
|
styled_components: Some(assert_json("{}")),
|
|
styled_jsx: assert_json("{}"),
|
|
remove_console: None,
|
|
react_remove_properties: None,
|
|
relay: None,
|
|
shake_exports: None,
|
|
emotion: Some(assert_json("{}")),
|
|
modularize_imports: None,
|
|
font_loaders: None,
|
|
app_dir: None,
|
|
server_actions: None,
|
|
cjs_require_optimizer: None,
|
|
auto_modularize_imports: None,
|
|
optimize_barrel_exports: None,
|
|
optimize_server_react: None,
|
|
prefer_esm: false,
|
|
debug_function_name: false,
|
|
css_env: None,
|
|
track_dynamic_imports: false,
|
|
};
|
|
|
|
let unresolved_mark = Mark::new();
|
|
let mut options = options.patch(&fm);
|
|
options.swc.unresolved_mark = Some(unresolved_mark);
|
|
|
|
let comments = SingleThreadedComments::default();
|
|
match c.process_js_with_custom_pass(
|
|
fm.clone(),
|
|
None,
|
|
&handler,
|
|
&options.swc,
|
|
comments.clone(),
|
|
|_| {
|
|
custom_before_pass(
|
|
cm.clone(),
|
|
fm.clone(),
|
|
&options,
|
|
comments.clone(),
|
|
Default::default(),
|
|
unresolved_mark,
|
|
Default::default(),
|
|
)
|
|
},
|
|
|_| noop_pass(),
|
|
) {
|
|
Ok(v) => {
|
|
NormalizedOutput::from(v.code)
|
|
.compare_to_file(output)
|
|
.unwrap();
|
|
}
|
|
Err(err) => panic!("Error: {:?}", err),
|
|
};
|
|
|
|
Ok(())
|
|
})
|
|
.map(|_| ())
|
|
.expect("failed");
|
|
}
|
|
|
|
/// Using this, we don't have to break code by adding field.s
|
|
fn assert_json<T>(json_str: &str) -> T
|
|
where
|
|
T: DeserializeOwned,
|
|
{
|
|
serde_json::from_str(json_str).expect("failed to deserialize")
|
|
}
|