🎉 Add addTokensLib method to the library

This commit is contained in:
Andrey Antukh
2025-10-24 14:21:56 +02:00
parent ec5e814a72
commit ef271db879
8 changed files with 219 additions and 20 deletions

View File

@@ -1,8 +1,15 @@
import assert from "node:assert/strict";
import test from "node:test";
import * as fs from "node:fs";
import path from "node:path";
import { fileURLToPath } from "node:url";
import * as penpot from "#self";
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
test("create empty context", () => {
const context = penpot.createBuildContext();
assert.ok(context);
@@ -118,3 +125,48 @@ test("create context with color", () => {
assert.equal(color.opacity, params.opacity);
assert.equal(color.name, params.name);
});
test("create context with tokens lib as json", () => {
const context = penpot.createBuildContext();
const fileId = context.addFile({name: "file 1"});
const pageId = context.addPage({name: "page 1"});
const tokensFilePath = path.join(__dirname, "_tokens-1.json");
const tokens = fs.readFileSync(tokensFilePath, "utf8");
context.addTokensLib(tokens);
const internalState = context.getInternalState();
const file = internalState.files[fileId];
assert.ok(file, "file should exist");
assert.ok(file.data);
assert.ok(file.data.tokensLib)
});
test("create context with tokens lib as obj", () => {
const context = penpot.createBuildContext();
const fileId = context.addFile({name: "file 1"});
const pageId = context.addPage({name: "page 1"});
const tokensFilePath = path.join(__dirname, "_tokens-1.json");
const tokens = fs.readFileSync(tokensFilePath, "utf8");
context.addTokensLib(JSON.parse(tokens))
const internalState = context.getInternalState();
const file = internalState.files[fileId];
assert.ok(file, "file should exist");
assert.ok(file.data);
assert.ok(file.data.tokensLib)
});