UNPKG

@sprucelabs/spruce-cli

Version:

Command line interface for building Spruce skills.

107 lines 5.37 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 fs_1 = __importDefault(require("fs")); const spruce_skill_utils_1 = require("@sprucelabs/spruce-skill-utils"); const test_utils_1 = require("@sprucelabs/test-utils"); const CommandService_1 = __importDefault(require("../../../services/CommandService")); const AbstractCliTest_1 = __importDefault(require("../../../tests/AbstractCliTest")); class UpgradingASkill4Test extends AbstractCliTest_1.default { static async beforeEach() { await super.beforeEach(); CommandService_1.default.fakeCommand(new RegExp(/rebuild/gis), { code: 0, }); } static async restoresMissingPackagesAndPlugins() { await this.FeatureFixture().installCachedFeatures('views'); const features = this.Service('pkg', process.cwd()).get('testSkillCache.everything'); const pkg = this.Service('pkg'); const checks = []; for (const feat of features) { const { code } = feat; const nodeModule = `@sprucelabs/spruce-${code}-plugin`; const path = this.resolveHashSprucePath('features', `${code}.plugin.ts`); const plugin = spruce_skill_utils_1.diskUtil.doesFileExist(path) ? path : undefined; checks.push({ nodeModule: pkg.get(['dependencies', nodeModule]) ? nodeModule : undefined, plugin, }); } for (const check of checks) { if (check.nodeModule) { pkg.unset(['dependencies', check.nodeModule]); } if (check.plugin) { spruce_skill_utils_1.diskUtil.deleteFile(check.plugin); } } CommandService_1.default.fakeCommand(/yarn clean/, { code: 0 }); CommandService_1.default.fakeCommand(/yarn build.dev/, { code: 0 }); await this.Action('node', 'upgrade').execute({}); for (const check of checks) { if (check.nodeModule) { test_utils_1.assert.isTruthy(pkg.get(['dependencies', check.nodeModule]), `${check.nodeModule} was not added back as a dependencies.`); } if (check.plugin) { test_utils_1.assert.isTrue(spruce_skill_utils_1.diskUtil.doesFileExist(check.plugin), `${check.plugin} was not rewritten.`); } } } static async doesNotAskIfNewScriptsAreAddedToSkillFeature() { const cli = await this.FeatureFixture().installCachedFeatures('skills'); const pkg = this.Service('pkg'); const skillFeature = cli.getFeature('skill'); //@ts-ignore skillFeature.scripts['taco'] = 'bravo'; await this.Action('node', 'upgrade').execute({}); test_utils_1.assert.isEqual(pkg.get(['scripts', 'taco']), 'bravo'); this.assertSandboxListenerNotWritten(); } static async canOverwriteMultipleChangedScript() { await this.FeatureFixture().installCachedFeatures('skills'); const pkg = this.Service('pkg'); pkg.set({ path: ['scripts', 'build.dev'], value: 'taco' }); pkg.set({ path: ['scripts', 'watch.build.dev'], value: 'taco' }); const promise = this.Action('node', 'upgrade').execute({}); await this.waitForInput(); let last = this.ui.getLastInvocation(); test_utils_1.assert.isEqual(last.command, 'prompt'); await this.ui.sendInput('overwrite'); last = this.ui.getLastInvocation(); test_utils_1.assert.isEqual(last.command, 'prompt'); await this.ui.sendInput('overwrite'); await promise; test_utils_1.assert.isNotEqual(pkg.get(['scripts', 'build.dev']), 'taco'); test_utils_1.assert.isNotEqual(pkg.get(['scripts', 'watch.build.dev']), 'taco'); } static assertSandboxListenerNotWritten() { const listeners = this.resolvePath('src', 'listeners'); if (!spruce_skill_utils_1.diskUtil.doesDirExist(listeners)) { return; } const matches = fs_1.default.readdirSync(listeners); test_utils_1.assert.isLength(matches, 0, 'A sandbox listeners was written and it should not have been.'); } } exports.default = UpgradingASkill4Test; __decorate([ (0, test_utils_1.test)() ], UpgradingASkill4Test, "restoresMissingPackagesAndPlugins", null); __decorate([ (0, test_utils_1.test)() ], UpgradingASkill4Test, "doesNotAskIfNewScriptsAreAddedToSkillFeature", null); __decorate([ (0, test_utils_1.test)() ], UpgradingASkill4Test, "canOverwriteMultipleChangedScript", null); //# sourceMappingURL=UpgradingASkill4.test.js.map