File: integration.rs

package info (click to toggle)
rust-swc-core 35.0.0~ds-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 62,816 kB
  • sloc: javascript: 873; xml: 538; sh: 358; makefile: 35; python: 5
file content (53 lines) | stat: -rw-r--r-- 1,253 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
use std::{
    env,
    path::{Path, PathBuf},
    process::{Command, Stdio},
};

use anyhow::{anyhow, Error};

fn build_fixture_binary(dir: &Path, target: Option<&str>) -> Result<(), Error> {
    let mut args = vec!["build".to_string()];
    if let Some(target) = target {
        args.push(format!("--target={target}"));
    };

    let mut cmd = Command::new("cargo");
    cmd.current_dir(dir);
    cmd.args(args).stderr(Stdio::inherit());
    cmd.output()?;

    if !cmd
        .status()
        .expect("Exit code should be available")
        .success()
    {
        return Err(anyhow!("Failed to build binary"));
    }

    Ok(())
}

#[cfg(feature = "base_node")]
#[test]
fn swc_core_napi_integration_build() -> Result<(), Error> {
    build_fixture_binary(
        &PathBuf::from(env::var("CARGO_MANIFEST_DIR")?)
            .join("tests")
            .join("fixture")
            .join("stub_napi"),
        None,
    )
}

#[cfg(feature = "browserslist")]
#[test]
fn swc_core_wasm_integration_build() -> Result<(), Error> {
    build_fixture_binary(
        &PathBuf::from(env::var("CARGO_MANIFEST_DIR")?)
            .join("tests")
            .join("fixture")
            .join("stub_wasm"),
        Some("wasm32-unknown-unknown"),
    )
}