Skip to content
Lucent
SEARCH LUCENT

Search guides, APIs, and examples.

GitHub

Very early and experimental. The language, the generated native code and every package API change without notice. Do not use Lucent in production.

Test a module

Run shared modules in Jest or Vitest as TypeScript, compare native and JavaScript with lucent bench, and check SDK calls on devices.

vitest.config.ts
import { createRequire } from "node:module";
import { defineConfig } from "vitest/config";
const require = createRequire(import.meta.url);
export default defineConfig({
resolve: { alias: { "lucent:core": require.resolve("@lucent-lang/lucent/core") } },
});
trip.test.ts
import { expect, it } from "vitest";
import { Trip } from "./src/trip.lucent";
it("rejects a fix that arrives late", () => {
const trip = new Trip();
trip.add({ latitude: 48.85, longitude: 2.29, time: 1000 });
expect(() => trip.add({ latitude: 48.86, longitude: 2.3, time: 0 })).toThrow(
expect.objectContaining({ code: "E_OUT_OF_ORDER" }),
);
});

A module is TypeScript, so your test runner can run it as is. @lucent-lang/lucent/core is the JavaScript version of lucent:core, for delay, error and the rest. Modules with platform code can't run this way: their SDK calls need the app.

terminal
npx lucent bench

lucent bench runs each case of your *.bench.ts files as the compiled module and as JavaScript, and fails when the results differ. It needs a desktop Hermes, at ~/hermes or in HERMES_DIR.

terminal
npx lucent build --platforms host --out .lucent/host

A host build compiles for your computer. Platform code there throws this code runs only on iOS and Android, so the shared code around it can run in tests.

SDK calls run only in the app. Build it for the simulator and the emulator, and check each platform's branch there.