skipcheck

TM1 Testcontainers · Docs · Writing tests

RequiresTm1Engine

import { RequiresTm1Engine } from "@skipcheck/tm1-testcontainers";

Runs a test class or method against a real TM1 v12 engine, and skips it when there isn't one. For TM1 11, use RequiresTm1.

Tests are skipped, not failed, when Docker isn't available or no Tm1EngineSource is configured, so a build without IBM software stays green. A source that is configured but wrong fails instead.

One engine serves the whole test JVM (Tm1EngineContainer.shared), and each test class gets a database of its own, created when the class first asks for it and dropped when the class is done. So classes don't see each other's objects. Declare a Tm1Database parameter on a test method, constructor or lifecycle method to get it; a Tm1EngineContainer parameter gets the engine.

// A database of this file's own, dropped when the file is done
requiresTm1Engine("lists cubes", async ({ tm1Database: db }) => {
  const response = await fetch(db.getRestUrl() + "Cubes?$select=Name", await db.login().authorize());
  expect(response.status).toBe(200);
});

A database takes about 13 seconds to create and 5 to drop. shareDatabase gives a class the engine's one shared database instead, at no cost: its tests then need uniquely named objects, and to delete them afterwards:

// The engine's one shared database instead: nothing to create, but give what you make a unique name
const requiresSharedDatabase = requiresTm1Engine.extend({ shareDatabase: true });

requiresSharedDatabase("reads the server's name", async ({ tm1Database: db }) => {
  const response = await fetch(db.getRestUrl() + "Configuration/ServerName/$value", await db.login().authorize());
  expect(response.status).toBe(200);
});

"A test class" is the unit each language's test framework shares set-up over: a JUnit class here (with its nested classes), a module in pytest, a class in xUnit, and a file in vitest.

Members

NO_SOURCE_MESSAGE staticWhy tests skip when no source is configured, and what to set.
skipReason staticWhy a TM1 v12 test would be skipped, or undefined to run it (a wrong source runs it, to fail).
databaseName staticThe name of a test file's database.

NO_SOURCE_MESSAGE

static
NO_SOURCE_MESSAGE

Why tests skip when no source is configured, and what to set.

skipReason

static
static skipReason(minVersion = ""): Promise<string | undefined>

Why a TM1 v12 test would be skipped, or undefined to run it (a wrong source runs it, to fail). With a minVersion, such as 12.6, it's also skipped on an older engine; checking that starts the shared engine.

databaseName

static
static databaseName(type: string, suffix: string): string

The name of a test file's database: the file's name, as far as a database's name allows, and suffix, padded to four characters so the name is always long enough for TM1.