UNPKG

@sprucelabs/spruce-cli

Version:

Command line interface for building Spruce skills.

74 lines 3.12 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const spruce_skill_utils_1 = require("@sprucelabs/spruce-skill-utils"); const test_utils_1 = require("@sprucelabs/test-utils"); const AbstractCliTest_1 = __importDefault(require("./AbstractCliTest")); class AbstractSchemaTest extends AbstractCliTest_1.default { static get schemaTypesFile() { return this.resolveHashSprucePath('schemas', 'schemas.types.ts'); } static get coreSchemaTypesFile() { return this.resolveHashSprucePath('schemas', 'core.schemas.types.ts'); } static async syncSchemas(cacheKey, syncOptions = {}) { const cli = await this.installSchemaFeature(cacheKey); await this.Action('schema', 'sync').execute(syncOptions); return cli; } static generateExpectedHealthSchemas(schemas) { const expected = schemas.map((schema) => ({ // @ts-ignore id: schema.id, // @ts-ignore name: schema.name, version: schema.version ?? spruce_skill_utils_1.CORE_SCHEMA_VERSION.constValue, namespace: schema.namespace, // @ts-ignore description: schema.description, })); const expectedJSon = JSON.stringify(expected); const cleanedExpected = JSON.parse(expectedJSon); return this.sortSchemas(cleanedExpected); } static sortSchemas(schemas) { return schemas.sort((a, b) => (a.id > b.id ? -1 : 1)); } static async installSchemaFeature(cacheKey, bootOptions) { const fixture = this.FeatureFixture(); const cli = await fixture.installFeatures([ { code: 'skill', options: { name: 'testing', description: 'this is a great test!', }, }, { code: 'schema', }, ], cacheKey, { ...(bootOptions || {}), graphicsInterface: this.ui }); return cli; } static async assertHealthySkillNamed(name, expectedHealth = { skill: { status: 'passed' } }, expectedInstalledSkills = ['skill']) { const cli = await this.Cli(); await this.linkLocalPackages(); const health = await cli.checkHealth(); // @ts-ignore if (health.schema?.schemas) { //@ts-ignore health.schema.schemas = this.sortSchemas(health.schema.schemas); } test_utils_1.assert.isEqualDeep(health, expectedHealth); const packageContents = spruce_skill_utils_1.diskUtil.readFile(this.resolvePath('package.json')); test_utils_1.assert.doesInclude(packageContents, name); for (const code of expectedInstalledSkills) { const isInstalled = await this.featureInstaller.isInstalled(code); test_utils_1.assert.isTrue(isInstalled); } } } exports.default = AbstractSchemaTest; //# sourceMappingURL=AbstractSchemaTest.js.map