Skip to content

Commit

Permalink
refactor(cli/node): migrate jest to vitest for tests (#11034)
Browse files Browse the repository at this point in the history
* refactor(cli/node): migrate `jest` to `vitest` for tests

* fix js audit
  • Loading branch information
amrbashir committed Sep 17, 2024
1 parent 5f694c3 commit 09de8c6
Show file tree
Hide file tree
Showing 17 changed files with 321 additions and 2,010 deletions.
2 changes: 1 addition & 1 deletion crates/tauri-cli/config.schema.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "tauri-config-2.0.0-rc.14",
"$id": "https://schema.tauri.app/config/2.0.0-rc.14",
"title": "Config",
"description": "The Tauri configuration object.\n It is read from a file where you can define your frontend assets,\n configure the bundler and define a tray icon.\n\n The configuration file is generated by the\n [`tauri init`](https://tauri.app/v1/api/cli#init) command that lives in\n your Tauri application source directory (src-tauri).\n\n Once generated, you may modify it at will to customize your Tauri application.\n\n ## File Formats\n\n By default, the configuration is defined as a JSON file named `tauri.conf.json`.\n\n Tauri also supports JSON5 and TOML files via the `config-json5` and `config-toml` Cargo features, respectively.\n The JSON5 file name must be either `tauri.conf.json` or `tauri.conf.json5`.\n The TOML file name is `Tauri.toml`.\n\n ## Platform-Specific Configuration\n\n In addition to the default configuration file, Tauri can\n read a platform-specific configuration from `tauri.linux.conf.json`,\n `tauri.windows.conf.json`, `tauri.macos.conf.json`, `tauri.android.conf.json` and `tauri.ios.conf.json`\n (or `Tauri.linux.toml`, `Tauri.windows.toml`, `Tauri.macos.toml`, `Tauri.android.toml` and `Tauri.ios.toml` if the `Tauri.toml` format is used),\n which gets merged with the main configuration object.\n\n ## Configuration Structure\n\n The configuration is composed of the following objects:\n\n - [`app`](#appconfig): The Tauri configuration\n - [`build`](#buildconfig): The build configuration\n - [`bundle`](#bundleconfig): The bundle configurations\n - [`plugins`](#pluginconfig): The plugins configuration\n\n Example tauri.config.json file:\n\n ```json\n {\n \"productName\": \"tauri-app\",\n \"version\": \"0.1.0\",\n \"build\": {\n \"beforeBuildCommand\": \"\",\n \"beforeDevCommand\": \"\",\n \"devUrl\": \"../dist\",\n \"frontendDist\": \"../dist\"\n },\n \"app\": {\n \"security\": {\n \"csp\": null\n },\n \"windows\": [\n {\n \"fullscreen\": false,\n \"height\": 600,\n \"resizable\": true,\n \"title\": \"Tauri App\",\n \"width\": 800\n }\n ]\n },\n \"bundle\": {},\n \"plugins\": {}\n }\n ```",
"type": "object",
Expand Down
2 changes: 1 addition & 1 deletion crates/tauri-schema-generator/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub fn main() -> Result<(), Box<dyn Error>> {
// set id for generated schema
let (filename, mut config_schema) = schema!("config", Config);
let schema_metadata = config_schema.schema.metadata.as_mut().unwrap();
schema_metadata.id = Some(format!("tauri-config-{}", tauri_ver));
schema_metadata.id = Some(format!("https://schema.tauri.app/config/{tauri_ver}"));

let config_schema = serde_json::to_string_pretty(&config_schema)?;
write_if_changed(schemas_dir.join(filename), &config_schema)?;
Expand Down
2 changes: 1 addition & 1 deletion crates/tauri-schema-generator/schemas/config.schema.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "tauri-config-2.0.0-rc.14",
"$id": "https://schema.tauri.app/config/2.0.0-rc.14",
"title": "Config",
"description": "The Tauri configuration object.\n It is read from a file where you can define your frontend assets,\n configure the bundler and define a tray icon.\n\n The configuration file is generated by the\n [`tauri init`](https://tauri.app/v1/api/cli#init) command that lives in\n your Tauri application source directory (src-tauri).\n\n Once generated, you may modify it at will to customize your Tauri application.\n\n ## File Formats\n\n By default, the configuration is defined as a JSON file named `tauri.conf.json`.\n\n Tauri also supports JSON5 and TOML files via the `config-json5` and `config-toml` Cargo features, respectively.\n The JSON5 file name must be either `tauri.conf.json` or `tauri.conf.json5`.\n The TOML file name is `Tauri.toml`.\n\n ## Platform-Specific Configuration\n\n In addition to the default configuration file, Tauri can\n read a platform-specific configuration from `tauri.linux.conf.json`,\n `tauri.windows.conf.json`, `tauri.macos.conf.json`, `tauri.android.conf.json` and `tauri.ios.conf.json`\n (or `Tauri.linux.toml`, `Tauri.windows.toml`, `Tauri.macos.toml`, `Tauri.android.toml` and `Tauri.ios.toml` if the `Tauri.toml` format is used),\n which gets merged with the main configuration object.\n\n ## Configuration Structure\n\n The configuration is composed of the following objects:\n\n - [`app`](#appconfig): The Tauri configuration\n - [`build`](#buildconfig): The build configuration\n - [`bundle`](#bundleconfig): The bundle configurations\n - [`plugins`](#pluginconfig): The plugins configuration\n\n Example tauri.config.json file:\n\n ```json\n {\n \"productName\": \"tauri-app\",\n \"version\": \"0.1.0\",\n \"build\": {\n \"beforeBuildCommand\": \"\",\n \"beforeDevCommand\": \"\",\n \"devUrl\": \"../dist\",\n \"frontendDist\": \"../dist\"\n },\n \"app\": {\n \"security\": {\n \"csp\": null\n },\n \"windows\": [\n {\n \"fullscreen\": false,\n \"height\": 600,\n \"resizable\": true,\n \"title\": \"Tauri App\",\n \"width\": 800\n }\n ]\n },\n \"bundle\": {},\n \"plugins\": {}\n }\n ```",
"type": "object",
Expand Down
2 changes: 1 addition & 1 deletion crates/tauri-schema-worker/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
"dev": "wrangler dev"
},
"devDependencies": {
"wrangler": "^3.73"
"wrangler": "^3.75"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,33 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT

const fixtureSetup = require('../fixtures/app-test-setup.js')
const { resolve } = require('path')
const { existsSync, readFileSync, writeFileSync, rmSync } = require('fs')
const { move } = require('fs-extra')
const cli = require('~/main.js')

const currentDirName = __dirname
import { resolve } from 'node:path'
import {
existsSync,
readFileSync,
writeFileSync,
rmSync,
renameSync
} from 'node:fs'
import cli from '../main.js'
import { describe, it } from 'vitest'

describe('[CLI] @tauri-apps/cli template', () => {
it('init a project and builds it', async () => {
it('init a project and builds it', { timeout: 200000 }, async () => {
const cwd = process.cwd()
const fixturePath = resolve(currentDirName, '../fixtures/empty')
const fixturePath = resolve(__dirname, './fixtures/empty')
const tauriFixturePath = resolve(fixturePath, 'src-tauri')
const outPath = resolve(tauriFixturePath, 'target')
const cacheOutPath = resolve(fixturePath, 'target')

fixtureSetup.initJest('empty')

process.chdir(fixturePath)

const outExists = existsSync(outPath)
if (outExists) {
if (existsSync(cacheOutPath)) {
rmSync(cacheOutPath, { recursive: true, force: true })
}
await move(outPath, cacheOutPath)
renameSync(outPath, cacheOutPath)
}

await cli.run([
Expand All @@ -36,7 +37,7 @@ describe('[CLI] @tauri-apps/cli template', () => {
process.cwd(),
'--force',
'--tauri-path',
resolve(currentDirName, '../../../../..'),
resolve(__dirname, '../../..'),
'--before-build-command',
'',
'--before-dev-command',
Expand All @@ -45,7 +46,7 @@ describe('[CLI] @tauri-apps/cli template', () => {
])

if (outExists) {
await move(cacheOutPath, outPath)
renameSync(cacheOutPath, outPath)
}

process.chdir(tauriFixturePath)
Expand Down
18 changes: 0 additions & 18 deletions packages/cli/jest.config.js

This file was deleted.

2 changes: 1 addition & 1 deletion packages/cli/main.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@

export function run(
args: Array<string>,
binName: string | undefined | null
binName?: string | undefined | null
): Promise<void>
9 changes: 3 additions & 6 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,9 @@
},
"devDependencies": {
"@napi-rs/cli": "2.18.3",
"@types/node": "20.16.1",
"cross-env": "7.0.3",
"cross-spawn": "7.0.3",
"fs-extra": "11.2.0",
"jest": "29.7.0",
"jest-transform-toml": "1.0.0",
"prettier": "3.3.2"
"vitest": "^2.1.1"
},
"engines": {
"node": ">= 10"
Expand All @@ -58,8 +55,8 @@
"build": "cross-env TARGET=node napi build --platform",
"prepublishOnly": "napi prepublish -t npm --gh-release-id $RELEASE_ID",
"prepack": "cp ../../crates/tauri-schema-generator/schemas/config.schema.json .",
"test": "jest --runInBand --forceExit --no-cache",
"version": "napi version",
"test": "vitest run",
"tauri": "node ./tauri.js"
}
}
2 changes: 1 addition & 1 deletion packages/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub fn run(args: Vec<String>, bin_name: Option<String>, callback: JsFunction) ->
// can do work while `tauri dev` is running.
std::thread::spawn(move || {
let res = match std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
tauri_cli::try_run(args, bin_name)
tauri_cli::try_run(args, bin_name).inspect_err(|e| eprintln!("{e:#}"))
})) {
Ok(t) => t,
Err(_) => {
Expand Down
90 changes: 0 additions & 90 deletions packages/cli/test/jest/fixtures/app-test-setup.js

This file was deleted.

25 changes: 0 additions & 25 deletions packages/cli/test/jest/helpers/logger.js

This file was deleted.

63 changes: 0 additions & 63 deletions packages/cli/test/jest/helpers/spawn.js

This file was deleted.

10 changes: 0 additions & 10 deletions packages/cli/test/jest/jest.setup.js

This file was deleted.

Loading

0 comments on commit 09de8c6

Please sign in to comment.