UNPKG

@sprucelabs/spruce-cli

Version:

Command line interface for building Spruce skills.

49 lines 2.4 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 AbstractSkillTest_1 = __importDefault(require("../../../../tests/AbstractSkillTest")); const test_utility_1 = __importDefault(require("../../../../tests/utilities/test.utility")); class AbstractInstanceTest extends AbstractSkillTest_1.default { static skillCacheKey = 'tests'; static action; static async beforeEach() { await super.beforeEach(); this.action = this.Action('test', 'create'); } static async createTest(name, willPromptForSubDir = false) { const promise = this.action.execute({ type: 'behavioral', nameReadable: name, nameCamel: spruce_skill_utils_1.namesUtil.toCamel(name), namePascal: spruce_skill_utils_1.namesUtil.toPascal(name), }); await this.ui.waitForInput(); await this.ui.sendInput(''); if (willPromptForSubDir) { await this.ui.waitForInput(); await this.ui.sendInput(''); } const results = await promise; test_utils_1.assert.isFalsy(results.errors, 'Error creating test'); return results; } static async createTestAndAssertContentsEqual(name, expected, willPromptForSubDir = false) { const testFile = await this.createTestAndGetCreatedFilePath(name, willPromptForSubDir); const contents = spruce_skill_utils_1.diskUtil.readFile(testFile); test_utils_1.assert.isEqual(this.normalizeWhitespace(contents), this.normalizeWhitespace(expected), 'Instance test does not match expected'); } static async createTestAndGetCreatedFilePath(name, willPromptForSubDir = false) { const results = await this.createTest(name, willPromptForSubDir); const testFile = test_utility_1.default.assertFileByNameInGeneratedFiles(`${spruce_skill_utils_1.namesUtil.toPascal(name)}.test.ts`, results.files); return testFile; } static normalizeWhitespace(contents) { return contents.replace(/\s/g, ''); } } exports.default = AbstractInstanceTest; //# sourceMappingURL=AbstractInstanceTest.js.map