Skip to main content

Overview

Use the standalone CLI with --json to build, publish, install, and uninstall your app from test code. Install it globally with npm install -g twenty. Combined with Vitest and the typed API clients, you can write integration tests that verify your app works end-to-end against a real Twenty server.

Using npm packages

You can install and use any npm package in your app. Both logic functions and front components are bundled with esbuild, which inlines their dependencies into the output — no node_modules are needed at runtime.

Installing a package

Then import it in your code:
src/logic-functions/fetch-data.ts
The same works for front components:
src/front-components/chart.tsx

How bundling works

The build step uses esbuild to produce a single self-contained file per logic function and per front component. Imported packages are inlined into the bundle, except for the ones listed below. Logic functions run in a Node.js environment. Node built-in modules (fs, path, crypto, http, etc.) are available and do not need to be installed. Front components run in a Web Worker. Node built-in modules are not available — only npm packages that work in a browser environment. Note that the sandbox implements a partial DOM, so a package can build cleanly and still fail at runtime; see Current limitations. Both environments have twenty-client-sdk/core and twenty-client-sdk/metadata available as pre-provided modules — these are not bundled but resolved at runtime by the server. Front components can also share dependencies through a shared dependencies bundle. Packages listed in the frontComponentSharedDependencies field of the app’s package.json are built once into a separate file and loaded from it at runtime instead of being inlined into each component, so a component that imports only shared packages carries almost no dependency code of its own.

Setup

The scaffolded app already includes Vitest. If you set it up manually, install the dependencies:
Create a vitest.config.ts at the root of your app:
vitest.config.ts
The generated template includes src/__tests__/run-twenty.ts, a subprocess helper that invokes the global CLI and parses its JSON result. Set TWENTY_CLI to an absolute executable path to use a local CLI build. It inherits TWENTY_API_URL and TWENTY_API_KEY; no home-directory config file is needed. Use this helper for setup and teardown:
src/__tests__/global-setup.ts
Run integration tests against a disposable workspace: setup installs the app and teardown uninstalls it. For registry-install coverage, run app publish --private followed by app install instead of app apply --create.

Writing an integration test

Use twenty-client-sdk to inspect data and metadata after the CLI setup completes:
For a manifest, read data.manifest from twenty app build --json. For deployed function tests, use the metadata client’s executeOneLogicFunction mutation with a user token. Resolve the function within the installed application’s ID before invoking it.

Running tests

Make sure your local Twenty server is running, then:
Or in watch mode during development:

Type checking

You can also run type checking on your app without running tests:
This checks your app’s tsconfig.json with its installed TypeScript compiler, without emitting files, and reports any type errors. Scaffolded apps also ship a yarn typecheck script that covers test files too (tsconfig.spec.json).

CI with GitHub Actions

The scaffolder generates a ready-to-use workflow at .github/workflows/ci.yml. On every push to main and every pull request, it spawns an ephemeral Twenty server in the runner (via the twentyhq/twenty/.github/actions/spawn-twenty-app-dev-test action), then runs yarn lint, yarn typecheck, yarn test:unit, and yarn test with TWENTY_API_URL / TWENTY_API_KEY pointing at that server. No secrets are required, and you can pin the server version via the TWENTY_VERSION env at the top of the workflow. See Publishing → Automated CI/CD for a full walkthrough of the three scaffolded workflows (ci.yml, the cd.yml deploy pipeline, and publish.yml for npm publishing).