UNPKG

@sprucelabs/spruce-cli

Version:

Command line interface for building Spruce skills.

119 lines • 6.26 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 LintService_1 = __importDefault(require("../../../services/LintService")); const AbstractTestTest_1 = __importDefault(require("../../../tests/AbstractTestTest")); const test_utility_1 = __importDefault(require("../../../tests/utilities/test.utility")); const uiAssert_utility_1 = __importDefault(require("../../../tests/utilities/uiAssert.utility")); class CreatingBehavioralTestsTest extends AbstractTestTest_1.default { static async hasCreateAction() { test_utils_1.assert.isFunction(this.Action('test', 'create').execute); } static async requiresInstallIfFeatureNotInstalled() { await this.installTests('testsInNodeModule'); const testFeature = this.featureInstaller.getFeature('test'); const candidates = await testFeature.buildParentClassCandidates(); test_utils_1.assert.doesInclude(candidates, { label: 'AbstractStoreTest (requires install)', name: 'AbstractStoreTest', }); } static async canCreateBehavioralTest(testName) { LintService_1.default.enableLinting(); const match = await this.createTestAndGetFile(testName); test_utils_1.assert.doesInclude(match, 'behavioral'); await this.Service('build').build(); await test_utils_1.assert.doesThrowAsync(() => this.Service('command').execute('yarn test'), /false.*?does not equal.*?true/gis); } static async promptsToSelectFolderIfInsideTestDir(testType) { await this.installTests(); this.createTestSubDir(testType, 'dummy1'); const { promise } = await this.installAndStartTestActionAndWaitForInput(testType); uiAssert_utility_1.default.assertRendersDirectorySelect(this.ui, this.resolvePath('src', '__tests__', testType)); await this.ui.sendInput(''); await this.waitAndSelectSubClass(); await promise; } static async selectingAnOptionRendersToSubDir(dirName) { await this.installTests(); const dir = this.createTestSubDir('behavioral', dirName); const { promise } = await this.installAndStartTestActionAndWaitForInput('behavioral'); await this.ui.sendInput({ path: dir }); await this.waitAndSelectSubClass(); const results = await promise; const expectedPath = this.resolvePath('src', '__tests__', 'behavioral', dirName, 'CanBookAppointment.test.ts'); test_utils_1.assert.isEqual(expectedPath, results.files?.[0]?.path); } static async allTestsComeFakedToStart() { const testFile = await this.createTestAndGetFile(); const contents = spruce_skill_utils_1.diskUtil.readFile(testFile); test_utils_1.assert.doesInclude(contents, 'fake.login()'); } static createTestSubDir(...testDirs) { const newDir = this.resolveTestDir(...testDirs); spruce_skill_utils_1.diskUtil.createDir(newDir); return newDir; } static resolveTestDir(...testDirs) { return this.resolvePath('src', '__tests__', ...testDirs); } static async createTest(testName = 'AbstractSpruceFixtureTest') { const { promise } = await this.installAndStartTestActionAndWaitForInput(); this.selectOptionBasedOnLabel(testName); const response = await promise; return response; } static async installAndStartTestActionAndWaitForInput(testType = 'behavioral') { await this.installTests(); const promise = this.Action('test', 'create').execute({ type: testType, nameReadable: 'Can book appointment', nameCamel: 'canBookAppointment', namePascal: 'CanBookAppointment', }); await this.waitForInput(); return { promise }; } static async waitAndSelectSubClass(selectedSubClass) { await this.waitForInput(); await this.ui.sendInput(selectedSubClass ?? ''); } static async createTestAndGetFile(testName) { const response = await this.createTest(testName); const match = test_utility_1.default.assertFileByNameInGeneratedFiles('CanBookAppointment.test.ts', response.files); return match; } } exports.default = CreatingBehavioralTestsTest; __decorate([ (0, test_utils_1.test)() ], CreatingBehavioralTestsTest, "hasCreateAction", null); __decorate([ (0, test_utils_1.test)() ], CreatingBehavioralTestsTest, "requiresInstallIfFeatureNotInstalled", null); __decorate([ (0, test_utils_1.test)('can create behavioral test with AbstractSpruceFixtureTest', 'AbstractSpruceFixtureTest'), (0, test_utils_1.test)('can create behavioral test with AbstractStoreTest', 'AbstractStoreTest (requires install)') ], CreatingBehavioralTestsTest, "canCreateBehavioralTest", null); __decorate([ (0, test_utils_1.test)('finds folders inside behavioral', 'behavioral'), (0, test_utils_1.test)('finds folders inside implementation', 'implementation') ], CreatingBehavioralTestsTest, "promptsToSelectFolderIfInsideTestDir", null); __decorate([ (0, test_utils_1.test)('can select sub dir 1', 'test'), (0, test_utils_1.test)('can select sub dir 2', 'test-2') ], CreatingBehavioralTestsTest, "selectingAnOptionRendersToSubDir", null); __decorate([ (0, test_utils_1.test)() ], CreatingBehavioralTestsTest, "allTestsComeFakedToStart", null); //# sourceMappingURL=CreatingATest.test.js.map