// Copyright 2019-2023 Tauri Programme within The Commons Conservancy // SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: MIT import { execFileSync, spawnSync } from 'node:child_process' import { parseArgs } from 'node:util' const { values } = parseArgs({ options: { exclude: { type: 'string', multiple: true, default: [] } } }) const { packages, workspace_members: workspaceMembers } = JSON.parse( execFileSync('cargo', ['metadata', '--format-version', '1', '--no-deps'], { encoding: 'utf8', maxBuffer: 16 * 1024 * 1024, stdio: ['ignore', 'pipe', 'inherit'] }) ) for (const pkg of packages) { if (!workspaceMembers.includes(pkg.id) || values.exclude.includes(pkg.name)) { continue } const tests = pkg.targets.filter((target) => target.kind.includes('test')) if (tests.length === 0) continue // Run one package at a time so Cargo resolves its features independently. const args = [ 'test', '--package', pkg.name, '--no-fail-fast', ...tests.flatMap((target) => ['--test', target.name]), '--', // Only run ignored tests, other tests runs in Test Rust (.github/workflows/test-rust.yml) '--ignored' ] console.log(`cargo ${args.join(' ')}`) const result = spawnSync('cargo', args, { stdio: 'inherit' }) if (result.error) throw result.error if (result.signal) { throw new Error(`cargo test for ${pkg.name} stopped with ${result.signal}`) } if (result.status !== 0) process.exitCode = 1 }