UNPKG

@sprucelabs/spruce-cli

Version:

Command line interface for building Spruce skills.

169 lines 7.59 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 FeatureCommandAttacher_1 = __importDefault(require("../../features/FeatureCommandAttacher")); const AbstractCliTest_1 = __importDefault(require("../../tests/AbstractCliTest")); const MockProgramFactory_1 = __importDefault(require("../../tests/MockProgramFactory")); class FeatureCommandAttacherTest extends AbstractCliTest_1.default { static attacher; static program; static async beforeEach() { await super.beforeEach(); this.program = this.MockCommanderProgram(); const actionExecuter = this.ActionExecuter(); this.attacher = new SpyFeatureCommandAttacher({ pkgService: this.Service('pkg'), program: this.program, ui: this.ui, actionExecuter, }); } static canInstantiateAttacher() { test_utils_1.assert.isTruthy(this.attacher); } static hasAttachMethod() { test_utils_1.assert.isFunction(this.attacher.attachFeature); } static async attachFeatureSetsUpCommands() { await this.attachSchemaFeature(); test_utils_1.assert.doesInclude(this.program.commandInvocations, 'create.schema'); test_utils_1.assert.doesInclude(this.program.commandInvocations, 'sync.schemas'); test_utils_1.assert.doesInclude(this.program.commandInvocations, 'sync.fields'); test_utils_1.assert.doesInclude(this.program.descriptionInvocations, { command: 'create.schema', }); test_utils_1.assert.doesInclude(this.program.descriptionInvocations, { command: 'sync.schemas', }); test_utils_1.assert.doesInclude(this.program.descriptionInvocations, { command: 'sync.fields', }); test_utils_1.assert.doesInclude(this.program.actionInvocations, 'create.schema'); test_utils_1.assert.doesInclude(this.program.actionInvocations, 'sync.schemas'); test_utils_1.assert.doesInclude(this.program.actionInvocations, 'sync.fields'); } static async setsUpOptions() { await this.attachSchemaFeature(); test_utils_1.assert.doesInclude(this.program.optionInvocations, { command: 'create.schema', option: '--schemaBuilderDestinationDir <schemaBuilderDestinationDir>', defaultValue: 'src/schemas', }); test_utils_1.assert.doesInclude(this.program.optionInvocations, { command: 'create.schema', option: '--description <description>', }); test_utils_1.assert.doesInclude(this.program.optionInvocations, { command: 'sync.fields', option: '--addonsLookupDir <addonsLookupDir>', }); test_utils_1.assert.doesInclude(this.program.optionInvocations, { command: 'sync.schemas', option: '--shouldFetchRemoteSchemas [true|false]', }); test_utils_1.assert.doesInclude(this.program.optionInvocations, { command: 'sync.schemas', option: '--shouldGenerateCoreSchemaTypes [true|false]', }); } static async ignoresPrivateFields() { await this.attachSchemaFeature(); test_utils_1.assert.doesNotInclude(this.program.optionInvocations, { command: 'create.schema', option: '--shouldEnableVersioning [true|false]', }); } static async testBooleanArg() { const cli = await this.Cli(); const vscodeFeature = cli.getFeature('vscode'); await this.attacher.attachFeature(vscodeFeature); test_utils_1.assert.doesInclude(this.program.optionInvocations, { command: 'setup.vscode', option: '--all [true|false]', }); } static async handlesAliases() { const cli = await this.Cli(); const feature = cli.getFeature('node'); await this.attacher.attachFeature(feature); test_utils_1.assert.doesInclude(this.program.aliasesInvocations, 'update'); } static async testActionWithSameNameAsFeature() { const cli = await this.Cli(); const vscodeFeature = cli.getFeature('test'); await this.attacher.attachFeature(vscodeFeature); const match = this.program.commandInvocations.find((i) => i === 'test'); test_utils_1.assert.isTruthy(match); } static async optionsCanBeOverridden() { await this.FeatureFixture().installCachedFeatures('schemas'); await this.attachSchemaFeature(); await this.program.actionHandler({}); const personPath = this.resolveHashSprucePath('schemas', 'spruce', 'v2020_07_22', 'person.schema.ts'); test_utils_1.assert.isFalse(spruce_skill_utils_1.diskUtil.doesFileExist(personPath)); } static async doesNotCrashWhenRenderingResultsWithoutPackageJson() { this.attacher.clearAndRenderResults({ action: 'test', actionCode: 'test', featureCode: 'test', results: {}, totalTime: 0, }); } static async attachSchemaFeature() { const cli = await this.Cli(); const schemaFeature = cli.getFeature('schema'); await this.attacher.attachFeature(schemaFeature); } static MockCommanderProgram() { return MockProgramFactory_1.default.Program(); } } exports.default = FeatureCommandAttacherTest; __decorate([ (0, test_utils_1.test)() ], FeatureCommandAttacherTest, "canInstantiateAttacher", null); __decorate([ (0, test_utils_1.test)() ], FeatureCommandAttacherTest, "hasAttachMethod", null); __decorate([ (0, test_utils_1.test)() ], FeatureCommandAttacherTest, "attachFeatureSetsUpCommands", null); __decorate([ (0, test_utils_1.test)() ], FeatureCommandAttacherTest, "setsUpOptions", null); __decorate([ test_utils_1.test.skip('enable when private fields can be optionally shown in help.') ], FeatureCommandAttacherTest, "ignoresPrivateFields", null); __decorate([ (0, test_utils_1.test)() ], FeatureCommandAttacherTest, "testBooleanArg", null); __decorate([ (0, test_utils_1.test)() ], FeatureCommandAttacherTest, "handlesAliases", null); __decorate([ (0, test_utils_1.test)() ], FeatureCommandAttacherTest, "testActionWithSameNameAsFeature", null); __decorate([ (0, test_utils_1.test)() ], FeatureCommandAttacherTest, "optionsCanBeOverridden", null); __decorate([ (0, test_utils_1.test)() ], FeatureCommandAttacherTest, "doesNotCrashWhenRenderingResultsWithoutPackageJson", null); class SpyFeatureCommandAttacher extends FeatureCommandAttacher_1.default { clearAndRenderResults(options) { return super.clearAndRenderResults(options); } } //# sourceMappingURL=FeatureCommandAttacher.test.js.map