Used to check for browser translation.
用于检测浏览器翻译。
ブラウザの翻訳を検出する
Command Reference

test


The blocklet test command provides a suite of tools for setting up and managing a test environment for a Blocklet. It is primarily used to automate the lifecycle of a Blocklet for end-to-end (e2e) testing, allowing you to initialize, start, reset, and remove a Blocklet programmatically.

Usage#

blocklet test <action> [options]

Test Workflow#

The typical workflow for using the test command in an automated testing script involves initializing a Blocklet, starting it, running tests, and then cleaning up the environment.

Blocklet ServerCLIBlocklet ServerCLIInstalls Blocklet & configures ownerStarts Blocklet and waits for it to be healthyRun e2e tests against the URLResets Blocklet data to initial stateRun another set of testsDeletes Blocklet and all associated datablocklet test initSuccessblocklet test startSuccess, prints accessible URLblocklet test resetSuccessblocklet test removeSuccess

Actions#

The test command includes several actions to manage the test lifecycle:

init#

Initializes a new test Blocklet environment. This command installs the Blocklet on the running Blocklet Server, configures it with a test owner, and issues the necessary DID Passports for testing.

blocklet test init --appName "My Test App" --appSk <app_sk> --ownerSk <owner_sk>

start#

Starts the previously initialized test Blocklet. The command waits until the Blocklet is running and healthy, then prints an accessible URL to the console, which can be used by testing frameworks like Cypress or Playwright.

blocklet test start --appSk <app_sk>

remove#

Completely removes the test Blocklet from the Blocklet Server. This action deletes the Blocklet's code, data, logs, and configurations, ensuring a clean state after tests are complete.

blocklet test remove --appSk <app_sk>

reset#

Resets the data of an existing test Blocklet to its initial state without uninstalling it. This is useful for running multiple independent test suites without the overhead of a full re-installation.

blocklet test reset --appSk <app_sk>

Options#

These options are required to identify the Blocklet and user context for the test operations.

Option

Description

--app-sk

The secret key of the application Blocklet being tested.

--app-name

The name to assign to the test Blocklet during initialization.

--owner-sk

The secret key of the test owner account.

Example Workflow Script#

Here is an example shell script demonstrating a full testing cycle using blocklet test.

# Ensure you have set APP_SK and OWNER_SK as environment variables or pass them directly

# 1. Initialize the test environment for the Blocklet
echo "Initializing test blocklet..."
blocklet test init --appName "My E2E Test App" --appSk "$APP_SK" --ownerSk "$OWNER_SK"

# 2. Start the Blocklet and capture its URL
echo "Starting test blocklet..."
URL=$(blocklet test start --appSk "$APP_SK" | grep 'http' | head -n 1 | sed 's/- //')

if [ -z "$URL" ]; then
echo "Failed to start blocklet or get URL."
exit 1
fi

# 3. Run your end-to-end tests against the Blocklet
echo "Running tests against $URL..."
# For example: npx cypress run --config baseUrl=$URL

# 4. Clean up the environment by removing the Blocklet
echo "Removing test blocklet..."
blocklet test remove --appSk "$APP_SK"

echo "Test cycle complete."


For more commands related to Blocklet management, see the full list of Blocklet commands.