UNPKG

@sprucelabs/spruce-cli

Version:

Command line interface for building Spruce skills.

146 lines • 7.04 kB
"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; 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("../../../tests/AbstractCliTest")); class SettingUpASkill extends AbstractCliTest_1.default { static async failsWithBadParams() { const cli = await this.Cli(); await test_utils_1.assert.doesThrowAsync(async () => { await cli.installFeatures({ features: [ { // @ts-ignore code: 'skill', options: { // @ts-ignore name2: 'test', description: 'This is such a good skill!', }, }, ], }); }, 'name'); } static async failsHealthCheckWithNothingInstalled() { const cli = await this.Cli(); const health = await cli.checkHealth(); test_utils_1.assert.isEqual(health.skill.status, 'failed'); test_utils_1.assert.doesInclude(health, { 'skill.errors[].options.code': 'SKILL_NOT_INSTALLED', }); } static async getsAFailedHealthCheckWhenIndexFileIsMoved() { const cli = await this.installSkill(); spruce_skill_utils_1.diskUtil.moveFile(this.resolvePath('src', 'index.ts'), this.resolvePath('src', 'index2.ts')); const health = await cli.checkHealth(); test_utils_1.assert.isEqual(health.skill.status, 'failed'); test_utils_1.assert.doesInclude(health, { 'skill.errors[].options.code': 'BOOT_ERROR', }); } static async installSkill() { const fixture = this.FeatureFixture(); const cli = await fixture.installCachedFeatures('skills'); return cli; } static async getsAGoodHealthCheckAndNothingElse() { const cli = await this.installSkill(); const hashSpruceDir = this.resolveHashSprucePath(); test_utils_1.assert.isTrue(spruce_skill_utils_1.diskUtil.doesDirExist(hashSpruceDir)); const health = await cli.checkHealth(); if (health.skill?.errors && health.skill.errors.length > 0) { test_utils_1.assert.fail(health.skill.errors?.[0].message); } test_utils_1.assert.isEqualDeep(health, { skill: { status: 'passed' } }); } static async reportsProperInstallResults() { const cli = await this.Cli(); const results = await cli.installFeatures({ features: [ { code: 'skill', options: { name: 'Transfer file check skill', description: 'For tracking files copied count', }, }, ], }); test_utils_1.assert.isTruthy(results.files); test_utils_1.assert.isAbove(results.files.length, 0); const generateFiles = results.files.filter((file) => file.action === 'generated'); test_utils_1.assert.isEqual(generateFiles.length, results.files.length); test_utils_1.assert.isTruthy(results.packagesInstalled); test_utils_1.assert.isAbove(results.packagesInstalled.length, 0); const hiddenFiles = results.files.filter((file) => file.name[0] === '.'); test_utils_1.assert.isAbove(hiddenFiles.length, 0); this.assertDevDependenciesExist(); this.assertSkillNameIsSaved(); } static async canAcceptOptionalDestination() { const cli = await this.Cli(); const results = await cli.installFeatures({ features: [ { code: 'skill', options: { name: 'Transfer file check skill', description: 'For tracking files copied count', destination: 'taco', }, }, ], }); test_utils_1.assert.isTrue(spruce_skill_utils_1.diskUtil.doesDirExist(this.resolvePath('taco'))); test_utils_1.assert.isFalse(spruce_skill_utils_1.diskUtil.doesDirExist(this.resolvePath('.env'))); test_utils_1.assert.isTrue(spruce_skill_utils_1.diskUtil.doesDirExist(this.resolvePath('taco', '.env'))); test_utils_1.assert.isFalse(spruce_skill_utils_1.diskUtil.doesFileExist(this.resolvePath('package.json'))); test_utils_1.assert.isFalse(spruce_skill_utils_1.diskUtil.doesFileExist(this.resolvePath('src'))); test_utils_1.assert.isFalse(spruce_skill_utils_1.diskUtil.doesFileExist(this.resolvePath('node_modules'))); test_utils_1.assert.isFalse(spruce_skill_utils_1.diskUtil.doesFileExist(this.resolvePath(spruce_skill_utils_1.HASH_SPRUCE_DIR))); test_utils_1.assert.isTrue(spruce_skill_utils_1.diskUtil.doesFileExist(this.resolvePath('taco', 'package.json'))); const first = results.files?.[0]; test_utils_1.assert.isTruthy(first); test_utils_1.assert.doesInclude(first.path, 'taco'); } static assertSkillNameIsSaved() { const env = this.Service('env'); test_utils_1.assert.isTruthy(env.get('SKILL_NAME')); test_utils_1.assert.isEqual(env.get('SKILL_NAME'), 'Transfer file check skill'); } static assertDevDependenciesExist() { const pkg = this.Service('pkg'); const devDependencies = pkg.get('devDependencies'); test_utils_1.assert.isTruthy(devDependencies); } } exports.default = SettingUpASkill; __decorate([ (0, test_utils_1.test)() ], SettingUpASkill, "failsWithBadParams", null); __decorate([ (0, test_utils_1.test)() ], SettingUpASkill, "failsHealthCheckWithNothingInstalled", null); __decorate([ (0, test_utils_1.test)() ], SettingUpASkill, "getsAFailedHealthCheckWhenIndexFileIsMoved", null); __decorate([ (0, test_utils_1.test)() ], SettingUpASkill, "getsAGoodHealthCheckAndNothingElse", null); __decorate([ (0, test_utils_1.test)() ], SettingUpASkill, "reportsProperInstallResults", null); __decorate([ (0, test_utils_1.test)() ], SettingUpASkill, "canAcceptOptionalDestination", null); //# sourceMappingURL=SettingUpASkill.test.js.map