This repository was archived by the owner on Jul 10, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
test: adds setup and teardown #13
Merged
xorsal
merged 13 commits into
defi-wonderland:dev
from
alejoamiras:test/improve-js-testing
Aug 7, 2025
Merged
Changes from 11 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
48438ec
test: adds setup and teardown
alejoamiras 550e1bd
fix: checking version with started sandbox
alejoamiras cd56cb5
fix: stops sending environment to aztec sandbox
alejoamiras a9645a0
fix: handle gracefully stops when not our sandbox
alejoamiras 46c58d6
refactor: centralized timeouts and error handling
alejoamiras 7f41294
ci: get aztec version programatically and dont start pxe
alejoamiras 0df3eb4
ci: clean env aztec version variable
alejoamiras da3e8f0
chore: merge with main
alejoamiras 9f46b51
ci: update node version to aztec's
alejoamiras db7e239
ci: fix consistency of version installing and docker
alejoamiras 33e4682
chore: fix linting
alejoamiras f876958
chore: update .github/workflows/lint.yml
alejoamiras ed85527
chore: update .github/workflows/tests.yml
alejoamiras File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| import { checkAztecVersion } from "./scripts/check-aztec-version.js"; | ||
| import { startSandbox } from "./scripts/start-sandbox.js"; | ||
|
|
||
| /** | ||
| * Jest global setup - runs before all tests | ||
| */ | ||
| export default async function setup() { | ||
| console.log("\nπ§ Setting up Aztec testing environment\n"); | ||
|
|
||
| try { | ||
| // Step 1: Check Aztec CLI version | ||
| console.log("Step 1: Checking Aztec CLI version compatibility"); | ||
| await checkAztecVersion(); | ||
| console.log(""); | ||
|
|
||
| // Step 2: Start sandbox and wait for readiness | ||
| console.log("Step 2: Starting Aztec sandbox"); | ||
| const sandboxManager = await startSandbox(); | ||
| console.log(""); | ||
|
|
||
| // Store sandbox manager globally for teardown | ||
| globalThis.__AZTEC_SANDBOX_MANAGER__ = sandboxManager; | ||
| } catch (error) { | ||
| console.error(`\nβ Setup failed: ${error.message}`); | ||
| process.exit(1); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| /** | ||
| * Jest global teardown - runs after all tests | ||
| */ | ||
| export default async function teardown() { | ||
| console.log("\nLast Step: Cleaning up Aztec testing environment"); | ||
|
|
||
| try { | ||
| // Get the sandbox manager from global storage | ||
| const sandboxManager = globalThis.__AZTEC_SANDBOX_MANAGER__; | ||
|
|
||
| if (sandboxManager) { | ||
| await sandboxManager.stop(); | ||
| console.log("β Sandbox stopped successfully"); | ||
| } else { | ||
| console.log("βΉοΈ No sandbox manager found, skipping cleanup"); | ||
| } | ||
|
|
||
| console.log("β Aztec testing environment cleanup complete\n"); | ||
| } catch (error) { | ||
| console.error("β οΈ Error during cleanup:", error.message); | ||
| // Don't exit with error code during cleanup, just log the issue | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| import { exec } from "child_process"; | ||
| import { promisify } from "util"; | ||
| import { readFileSync } from "fs"; | ||
| import { fileURLToPath } from "url"; | ||
| import { dirname, join } from "path"; | ||
|
|
||
| const execAsync = promisify(exec); | ||
|
|
||
| const __filename = fileURLToPath(import.meta.url); | ||
| const __dirname = dirname(__filename); | ||
|
|
||
| /** | ||
| * Check if the installed Aztec CLI version matches the expected version in package.json | ||
| */ | ||
| async function checkAztecVersion() { | ||
| console.log("π Checking Aztec CLI version"); | ||
|
|
||
| // Read expected version from package.json | ||
| const packageJsonPath = join(__dirname, "..", "package.json"); | ||
| const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf8")); | ||
| const expectedVersion = packageJson.config?.aztecVersion; | ||
|
|
||
| if (!expectedVersion) { | ||
| throw new Error("β No aztecVersion found in package.json config"); | ||
| } | ||
|
|
||
| console.log(`π Expected Aztec version: ${expectedVersion}`); | ||
|
|
||
| let installedVersion; | ||
|
|
||
| try { | ||
| // Check if aztec CLI is installed and get version | ||
| const { stdout } = await execAsync("aztec --version"); | ||
| installedVersion = stdout.trim(); | ||
|
|
||
| console.log("β Aztec CLI version check passed"); | ||
| } catch (error) { | ||
| if (error.code === "ENOENT") { | ||
| throw new Error( | ||
| `β Aztec CLI not found!\n` + | ||
| ` Please install aztec-up and run: VERSION=${expectedVersion} aztec-up`, | ||
| ); | ||
| } else if (error.stdout) { | ||
| // Handle case where command exits with non-zero code (e.g., when sandbox is running) | ||
| // but version is still available in stdout | ||
| installedVersion = error.stdout.trim(); | ||
| } else { | ||
| throw error; | ||
| } | ||
| } | ||
|
|
||
| console.log(`π§ Installed Aztec version: ${installedVersion}`); | ||
|
|
||
| // Compare versions | ||
| if (installedVersion !== expectedVersion) { | ||
| throw new Error( | ||
| `β Version mismatch!\n` + | ||
| ` Expected: ${expectedVersion}\n` + | ||
| ` Installed: ${installedVersion}\n` + | ||
| ` Please run: VERSION=${expectedVersion} aztec-up`, | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| export { checkAztecVersion }; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.