@sprucelabs/spruce-cli
Version:
Command line interface for building Spruce skills.
140 lines • 7.88 kB
JavaScript
"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 LintService_1 = __importDefault(require("../../../services/LintService"));
const AbstractCliTest_1 = __importDefault(require("../../../tests/AbstractCliTest"));
const test_utility_1 = __importDefault(require("../../../tests/utilities/test.utility"));
class UpgradingASkill2Test extends AbstractCliTest_1.default {
static async beforeEach() {
await super.beforeEach();
this.commandFaker.fakeRebuild();
LintService_1.default.disableLinting();
}
static async upgradesPlugins(pluginName, cacheKey, shouldBlockYarn = true) {
await this.FeatureFixture().installCachedFeatures(cacheKey);
this.commandFaker.fakeBuild();
shouldBlockYarn && this.commandFaker.fakeCommand(/yarn/, 0);
// !shouldBlockYarn && LintService.enableLinting()
const pluginPath = this.resolveHashSprucePath(`features/${pluginName}`);
const originalContents = spruce_skill_utils_1.diskUtil.readFile(pluginPath);
spruce_skill_utils_1.diskUtil.writeFile(pluginPath, 'aoeuaoeuao-euaoeu');
const results = await this.Action('node', 'upgrade').execute({});
test_utils_1.assert.isFalsy(results.errors);
test_utility_1.default.assertFileByNameInGeneratedFiles(pluginName, results.files);
const updatedContents = spruce_skill_utils_1.diskUtil.readFile(pluginPath);
test_utils_1.assert.isEqual(updatedContents, originalContents);
test_utils_1.assert.doesInclude(results.summaryLines ?? [], 'successfully');
}
static async canSkipPackageScriptChanges() {
await this.FeatureFixture().installCachedFeatures('skills');
const pkg = this.Service('pkg');
pkg.set({ path: ['scripts', 'build.dev'], value: 'taco' });
const promise = this.Action('node', 'upgrade').execute({});
await this.waitForInput();
const last = this.ui.getLastInvocation();
test_utils_1.assert.isEqual(last.command, 'prompt');
test_utils_1.assert.doesInclude(last.options.options.choices, { value: 'skip' });
test_utils_1.assert.doesInclude(last.options.options.choices, { value: 'skipAll' });
test_utils_1.assert.doesInclude(last.options.options.choices, { value: 'overwrite' });
await this.ui.sendInput('skip');
await promise;
test_utils_1.assert.isEqual(pkg.get(['scripts', 'build.dev']), 'taco');
}
static async asksForEachScriptChange() {
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('skip');
await this.waitForInput();
last = this.ui.getLastInvocation();
test_utils_1.assert.isEqual(last.command, 'prompt');
await this.ui.sendInput('skip');
await promise;
test_utils_1.assert.isEqual(pkg.get(['scripts', 'build.dev']), 'taco');
test_utils_1.assert.isEqual(pkg.get(['scripts', 'watch.build.dev']), 'taco');
}
static async canSkipAllScriptChanges() {
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('skipAll');
await promise;
test_utils_1.assert.isEqual(pkg.get(['scripts', 'build.dev']), 'taco');
test_utils_1.assert.isEqual(pkg.get(['scripts', 'watch.build.dev']), 'taco');
}
static async canOverwriteChangedScript() {
await this.FeatureFixture().installCachedFeatures('skills');
const pkg = this.Service('pkg');
pkg.set({ path: ['scripts', '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');
await promise;
test_utils_1.assert.isNotEqual(pkg.get(['scripts', 'build.dev']), 'taco');
}
static async upgradingSkillWithSandboxUpgradesTheListener() {
await this.FeatureFixture().installCachedFeatures('sandbox');
const results = await this.Action('sandbox', 'setup').execute({});
const match = test_utility_1.default.assertFileByNameInGeneratedFiles(/will-boot/, results.files);
const originalContents = spruce_skill_utils_1.diskUtil.readFile(match);
spruce_skill_utils_1.diskUtil.writeFile(match, 'broken');
this.commandFaker.fakeCommand(/yarn/, 0);
await this.Action('node', 'upgrade').execute({});
const newContents = spruce_skill_utils_1.diskUtil.readFile(match);
test_utils_1.assert.isEqual(originalContents, newContents);
}
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 = UpgradingASkill2Test;
__decorate([
(0, test_utils_1.test)('Upgrades error.plugin (even if skill is broken)', 'error.plugin.ts', 'errors'),
(0, test_utils_1.test)('Upgrades schema.plugin (even if skill is broken)', 'schema.plugin.ts', 'schemas'),
(0, test_utils_1.test)('Upgrades conversation.plugin (even if skill is broken)', 'conversation.plugin.ts', 'conversation', false),
(0, test_utils_1.test)('Upgrades view.plugin (even if skill is broken)', 'view.plugin.ts', 'views', false)
], UpgradingASkill2Test, "upgradesPlugins", null);
__decorate([
(0, test_utils_1.test)()
], UpgradingASkill2Test, "canSkipPackageScriptChanges", null);
__decorate([
(0, test_utils_1.test)()
], UpgradingASkill2Test, "asksForEachScriptChange", null);
__decorate([
(0, test_utils_1.test)()
], UpgradingASkill2Test, "canSkipAllScriptChanges", null);
__decorate([
(0, test_utils_1.test)()
], UpgradingASkill2Test, "canOverwriteChangedScript", null);
__decorate([
(0, test_utils_1.test)()
], UpgradingASkill2Test, "upgradingSkillWithSandboxUpgradesTheListener", null);
//# sourceMappingURL=UpgradingASkill2.test.js.map