UNPKG

@sketch-hq/sketch-assistant-utils

Version:

Utility functions and types for Sketch Assistants.

97 lines (96 loc) 4.59 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const sketch_file_1 = require("@sketch-hq/sketch-file"); const path_1 = require("path"); const __1 = require("../"); const process_1 = require("../../../process"); const test_helpers_1 = require("../../../test-helpers"); describe('prunePages', () => { test('should prune pages not present in the file ', () => __awaiter(void 0, void 0, void 0, function* () { const ignore = { pages: ['7CDC2A8F-35F7-4B82-A481-60E59A89381D', 'missing-page-uuid'], assistants: {}, }; const file = yield sketch_file_1.fromFile(path_1.resolve(__dirname, './pages.sketch')); expect(__1.prunePages(ignore, file).pages).not.toContain('missing-page-uuid'); expect(__1.prunePages(ignore, file).pages).toContain('7CDC2A8F-35F7-4B82-A481-60E59A89381D'); })); }); describe('pruneAssistants', () => { test('should prune assistants not present in the package map', () => __awaiter(void 0, void 0, void 0, function* () { const ignore = { pages: [], assistants: { assistant1: { rules: {} }, assistant2: { rules: {} }, }, }; const packageMap = { assistant1: [], }; expect(__1.pruneAssistants(ignore, packageMap).assistants).not.toHaveProperty('assistant2'); })); }); describe('pruneRules', () => { test('should prune ignored rules not present in the assistant', () => __awaiter(void 0, void 0, void 0, function* () { const ignore = { pages: [], assistants: { assistant1: { rules: { foo: { allObjects: true }, bar: { allObjects: true } } }, }, }; const assistant = test_helpers_1.createAssistantDefinition({ name: 'assistant1', rules: [test_helpers_1.createRule({ name: 'foo' })], }); expect(__1.pruneRules(ignore, assistant).assistants.assistant1.rules).not.toHaveProperty('bar'); })); test('rule pruning is scoped to the assistant', () => __awaiter(void 0, void 0, void 0, function* () { const ignore = { pages: [], assistants: { assistant1: { rules: { foo: { allObjects: true } } }, assistant2: { rules: { foo: { allObjects: true } } }, }, }; const assistant = test_helpers_1.createAssistantDefinition({ name: 'assistant1', rules: [test_helpers_1.createRule({ name: 'bar' })], }); expect(__1.pruneRules(ignore, assistant).assistants.assistant1.rules).not.toHaveProperty('foo'); expect(__1.pruneRules(ignore, assistant).assistants.assistant2.rules).toHaveProperty('foo'); })); }); describe('pruneObjects', () => { test('should prune ignored objects not present in the file', () => __awaiter(void 0, void 0, void 0, function* () { const ignore = { pages: [], assistants: { assistant1: { rules: { rule1: { objects: ['58CB1F63-87F1-4C5D-894F-A2BE2E55759C', 'missing-object-uuid'], }, }, }, }, }; const file = yield sketch_file_1.fromFile(path_1.resolve(__dirname, './objects.sketch')); const processedFile = yield process_1.process(file, { cancelled: false }); expect.assertions(2); const pruned = __1.pruneObjects(ignore, processedFile); if ('objects' in pruned.assistants.assistant1.rules.rule1) { expect(pruned.assistants.assistant1.rules.rule1.objects).not.toContain('missing-object-uuid'); expect(pruned.assistants.assistant1.rules.rule1.objects).toContain('58CB1F63-87F1-4C5D-894F-A2BE2E55759C'); } })); });