@sprucelabs/spruce-cli
Version:
Command line interface for building Spruce skills.
100 lines (99 loc) • 4.96 kB
JavaScript
;
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 test_utils_2 = require("@sprucelabs/test-utils");
const LintService_1 = __importDefault(require("../../services/LintService"));
const AbstractSkillTest_1 = __importDefault(require("../../tests/AbstractSkillTest"));
const test_utility_1 = __importDefault(require("../../tests/utilities/test.utility"));
class SettingLogTransportsInASkillTest extends AbstractSkillTest_1.default {
static skillCacheKey = 'skills';
static async hasCreateTransportCommand() {
const action = this.Action('log', 'createTransport');
test_utils_1.assert.isFunction(action.execute);
}
static async needsNameOfTransport() {
const results = await this.createTransport();
test_utils_1.assert.isFalsy(results.errors);
}
static async createsTransportFile(nameReadable) {
const results = await this.createTransport(nameReadable);
const nameCamel = spruce_skill_utils_1.namesUtil.toCamel(nameReadable);
const match = test_utility_1.default.assertFileByNameInGeneratedFiles(`${nameCamel}Transport.plugin.ts`, results.files);
test_utils_1.assert.doesInclude(match, this.resolvePath('src/logTransports', `${nameCamel}Transport.plugin.ts`));
test_utils_1.assert.isTrue(spruce_skill_utils_1.diskUtil.doesFileExist(match));
}
static async cantCreateTransportThatAlreadyExists() {
const results = await this.createTransport('Slack');
test_utils_1.assert.isTruthy(results.errors);
test_utils_2.errorAssert.assertError(results.errors[0], 'TRANSPORT_ALREADY_EXISTS', {
name: 'Slack',
});
}
static async logsWriteToTransports() {
LintService_1.default.enableLinting();
const transportContents = `
import { diskUtil, Level, LogTransport } from '@sprucelabs/spruce-skill-utils'
export default function (): {
levels: Level[]
transport: LogTransport
} | null {
return {
levels: ['ERROR', 'INFO', 'WARN'],
transport: (...messageParts: string[]) => {
const message = messageParts.join(' ')
diskUtil.writeFile(
diskUtil.resolvePath(__dirname, '..', '..', 'log.txt'),
message
)
},
}
}
`;
await this.createTransportWithContents(transportContents, 'File');
await this.Service('build').build();
const boot = await this.Action('skill', 'boot').execute({});
await boot.meta?.kill();
test_utils_1.assert.isTrue(spruce_skill_utils_1.diskUtil.doesFileExist(spruce_skill_utils_1.diskUtil.resolvePath(this.cwd, 'log.txt')));
}
static async createTransportWithContents(transportContents, nameReadable) {
const results = await this.createTransport(nameReadable);
const match = test_utility_1.default.assertFileByNameInGeneratedFiles(`${spruce_skill_utils_1.namesUtil.toCamel(nameReadable)}Transport.plugin.ts`, results.files);
spruce_skill_utils_1.diskUtil.writeFile(match, transportContents);
}
static async createTransport(nameReadable = 'Slack') {
const action = this.Action('log', 'createTransport');
const results = await action.execute({
nameReadable,
nameCamel: spruce_skill_utils_1.namesUtil.toCamel(nameReadable),
});
return results;
}
}
exports.default = SettingLogTransportsInASkillTest;
__decorate([
(0, test_utils_1.test)()
], SettingLogTransportsInASkillTest, "hasCreateTransportCommand", null);
__decorate([
(0, test_utils_1.test)()
], SettingLogTransportsInASkillTest, "needsNameOfTransport", null);
__decorate([
(0, test_utils_1.test)('can create transport 1', 'Sms'),
(0, test_utils_1.test)('can create transport 2', 'Email')
], SettingLogTransportsInASkillTest, "createsTransportFile", null);
__decorate([
(0, test_utils_1.test)()
], SettingLogTransportsInASkillTest, "cantCreateTransportThatAlreadyExists", null);
__decorate([
(0, test_utils_1.test)()
], SettingLogTransportsInASkillTest, "logsWriteToTransports", null);
//# sourceMappingURL=SettingLogTransportsInASkill.test.js.map