|
| 1 | +// Copyright 2019-2024 Tauri Programme within The Commons Conservancy |
| 2 | +// SPDX-License-Identifier: Apache-2.0 |
| 3 | +// SPDX-License-Identifier: MIT |
| 4 | + |
| 5 | +use std::fs; |
| 6 | +use std::process::Command; |
| 7 | + |
| 8 | +#[test] |
| 9 | +fn init_non_interactive_works() { |
| 10 | + let temp_dir = tempfile::tempdir().unwrap(); |
| 11 | + let dir = temp_dir.path(); |
| 12 | + |
| 13 | + // Determine the path to the cargo-tauri binary. |
| 14 | + // The test binary is in target/debug/deps/, so we navigate up to target/debug/ |
| 15 | + let current_exe = std::env::current_exe().unwrap(); |
| 16 | + let target_debug = current_exe.parent().unwrap().parent().unwrap(); |
| 17 | + let cargo_tauri = if cfg!(windows) { |
| 18 | + target_debug.join("cargo-tauri.exe") |
| 19 | + } else { |
| 20 | + target_debug.join("cargo-tauri") |
| 21 | + }; |
| 22 | + |
| 23 | + assert!( |
| 24 | + cargo_tauri.exists(), |
| 25 | + "cargo-tauri binary not found at {:?}", |
| 26 | + cargo_tauri |
| 27 | + ); |
| 28 | + |
| 29 | + // Run `init` without --force or --ci; since stdin is not a terminal in tests, |
| 30 | + // it should automatically skip prompts and use defaults. |
| 31 | + let output = Command::new(&cargo_tauri) |
| 32 | + .arg("init") |
| 33 | + .arg("--app-name") |
| 34 | + .arg("testapp") |
| 35 | + .arg("--frontend-dist") |
| 36 | + .arg("../dist") |
| 37 | + .arg("--dev-url") |
| 38 | + .arg("http://localhost:3000") |
| 39 | + .current_dir(dir) |
| 40 | + .output() |
| 41 | + .expect("failed to run cargo-tauri init"); |
| 42 | + |
| 43 | + assert!(output.status.success(), "init failed: {:?}", output); |
| 44 | + |
| 45 | + // Verify that src-tauri was created. |
| 46 | + let src_tauri = dir.join("src-tauri"); |
| 47 | + assert!(src_tauri.exists(), "src-tauri directory was not created"); |
| 48 | + |
| 49 | + // Verify that the tauri.conf.json contains the app name we set. |
| 50 | + let conf_path = src_tauri.join("tauri.conf.json"); |
| 51 | + assert!(conf_path.exists(), "tauri.conf.json not found"); |
| 52 | + let content = fs::read_to_string(&conf_path).unwrap(); |
| 53 | + assert!(content.contains("testapp"), "app name not found in config"); |
| 54 | +} |
0 commit comments