@sprucelabs/spruce-cli
Version:
Command line interface for building Spruce skills.
150 lines • 6.49 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 test_utils_1 = require("@sprucelabs/test-utils");
const test_utils_2 = require("@sprucelabs/test-utils");
const constants_1 = require("../../features/cache/constants");
const CommandService_1 = __importDefault(require("../../services/CommandService"));
const AbstractCliTest_1 = __importDefault(require("../../tests/AbstractCliTest"));
class EnablingAndDisablingCacheTest extends AbstractCliTest_1.default {
static async cacheFeatureIsAlwaysOn() {
const isInstalled = await this.featureInstaller.isInstalled('cache');
test_utils_1.assert.isTrue(isInstalled);
}
static hasEnableFeature() {
test_utils_1.assert.isFunction(this.Action('cache', 'enable').execute);
}
static async returnsErrorWhenEnablingIfDockerIsNotInstalled() {
CommandService_1.default.fakeCommand(/which docker/gis, {
code: 1,
});
const results = await this.Action('cache', 'enable').execute({});
test_utils_1.assert.isTruthy(results.errors);
test_utils_2.errorAssert.assertError(results.errors[0], 'MISSING_DEPENDENCIES', {
dependencies: [
{
name: 'Docker',
},
],
});
}
static async returnsErrorWhenDockerNotEnabled() {
CommandService_1.default.fakeCommand(/npm config/gis, {
code: 1,
stderr: 'which',
});
const results = await this.Action('cache', 'enable').execute({});
test_utils_1.assert.isTruthy(results.errors);
test_utils_2.errorAssert.assertError(results.errors[0], 'DOCKER_NOT_STARTED');
}
static async canEnableCache() {
CommandService_1.default.fakeCommand(/which docker/gis, {
code: 0,
});
CommandService_1.default.fakeCommand(constants_1.ENABLE_NPM_CACHE_COMMAND, {
code: 0,
});
CommandService_1.default.fakeCommand(constants_1.DISABLE_NPM_CACHE_COMMAND, {
code: 0,
});
const results = await this.Action('cache', 'enable').execute({});
test_utils_1.assert.isFalsy(results.errors);
}
static hasDisableFeature() {
test_utils_1.assert.isFunction(this.Action('cache', 'disable').execute);
}
static async returnsErrorWhenDisablingIfDockerIsNotInstalled() {
CommandService_1.default.fakeCommand(/which docker/gis, {
code: 1,
});
const results = await this.Action('cache', 'disable').execute({});
test_utils_1.assert.isTruthy(results.errors);
test_utils_2.errorAssert.assertError(results.errors[0], 'MISSING_DEPENDENCIES', {
dependencies: [
{
name: 'Docker',
},
],
});
}
static async returnsErrorWhenDisablingIfDockerIsNotStarted() {
CommandService_1.default.fakeCommand(/which docker/gis, {
code: 0,
});
CommandService_1.default.fakeCommand(/npm config/gis, {
code: 1,
});
const results = await this.Action('cache', 'disable').execute({});
test_utils_1.assert.isTruthy(results.errors);
test_utils_2.errorAssert.assertError(results.errors[0], 'MISSING_DEPENDENCIES', {
dependencies: [
{
name: 'Docker',
},
],
});
}
static async returnsErrorIfCacheIsNotInstalled() {
CommandService_1.default.fakeCommand(/npm config/gis, {
code: 1,
stderr: 'tsanoehusnatohu snatoh No such container staoheu saotnhu ',
});
const results = await this.Action('cache', 'disable').execute({});
test_utils_1.assert.isTruthy(results.errors);
test_utils_2.errorAssert.assertError(results.errors[0], 'CACHE_NOT_ENABLED');
}
static async canEnableCacheMultipleTimes() {
CommandService_1.default.fakeCommand(/which docker/gis, {
code: 0,
});
CommandService_1.default.fakeCommand(constants_1.DISABLE_NPM_CACHE_COMMAND, {
code: 0,
});
CommandService_1.default.fakeCommand(constants_1.ENABLE_NPM_CACHE_COMMAND, {
code: 0,
});
await this.Action('cache', 'enable').execute({});
const results = await this.Action('cache', 'enable').execute({});
test_utils_1.assert.isFalsy(results.errors);
}
}
exports.default = EnablingAndDisablingCacheTest;
__decorate([
(0, test_utils_1.test)()
], EnablingAndDisablingCacheTest, "cacheFeatureIsAlwaysOn", null);
__decorate([
(0, test_utils_1.test)()
], EnablingAndDisablingCacheTest, "hasEnableFeature", null);
__decorate([
(0, test_utils_1.test)()
], EnablingAndDisablingCacheTest, "returnsErrorWhenEnablingIfDockerIsNotInstalled", null);
__decorate([
(0, test_utils_1.test)()
], EnablingAndDisablingCacheTest, "returnsErrorWhenDockerNotEnabled", null);
__decorate([
(0, test_utils_1.test)()
], EnablingAndDisablingCacheTest, "canEnableCache", null);
__decorate([
(0, test_utils_1.test)()
], EnablingAndDisablingCacheTest, "hasDisableFeature", null);
__decorate([
(0, test_utils_1.test)()
], EnablingAndDisablingCacheTest, "returnsErrorWhenDisablingIfDockerIsNotInstalled", null);
__decorate([
(0, test_utils_1.test)()
], EnablingAndDisablingCacheTest, "returnsErrorWhenDisablingIfDockerIsNotStarted", null);
__decorate([
(0, test_utils_1.test)()
], EnablingAndDisablingCacheTest, "returnsErrorIfCacheIsNotInstalled", null);
__decorate([
(0, test_utils_1.test)()
], EnablingAndDisablingCacheTest, "canEnableCacheMultipleTimes", null);
//# sourceMappingURL=EnablingAndDisablingCache.test.js.map