@sprucelabs/spruce-cli
Version:
Command line interface for building Spruce skills.
77 lines • 4.09 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 ImportService_1 = __importDefault(require("../../services/ImportService"));
const AbstractCliTest_1 = __importDefault(require("../../tests/AbstractCliTest"));
class CachingImportsTest extends AbstractCliTest_1.default {
static importService;
static async beforeAll() {
await super.beforeAll();
ImportService_1.default.setCacheDir(spruce_skill_utils_1.diskUtil.createRandomTempDir());
this.importService = this.Service('import');
ImportService_1.default.enableCaching();
}
static async canTellIfFileChanged() {
const test1Path = this.resolvePath('test1.js');
spruce_skill_utils_1.diskUtil.writeFile(test1Path, 'module.exports = { hello: "world"}');
await this.assertImportedCorrectly(test1Path, { hello: 'world' });
spruce_skill_utils_1.diskUtil.writeFile(test1Path, 'module.exports = { foo: "bar"}');
await this.assertImportedCorrectly(test1Path, { foo: 'bar' });
}
static async assertImportedCorrectly(test1Path, expected) {
const contents = await this.importService.importAll(test1Path);
test_utils_1.assert.isEqualDeep(contents, expected);
}
static async canTellIfRelatedFileChanges() {
const test1Path = this.resolvePath('test1.js');
spruce_skill_utils_1.diskUtil.writeFile(test1Path, 'const value = require("./test2"); module.exports = { hello: value }');
const test2Path = this.resolvePath('test2.js');
spruce_skill_utils_1.diskUtil.writeFile(test2Path, 'module.exports = "world"');
await this.assertImportedCorrectly(test1Path, { hello: 'world' });
spruce_skill_utils_1.diskUtil.writeFile(test2Path, 'module.exports = "bar"');
await this.assertImportedCorrectly(test1Path, { hello: 'bar' });
}
static async canTellIfFilesChangedInASkill() {
await this.FeatureFixture().installFeatures([
{
code: 'skill',
options: {
name: 'file-change-skill',
description: 'It should be good',
},
},
], 'skills');
const test1Path = this.resolvePath('src/test1.ts');
spruce_skill_utils_1.diskUtil.writeFile(test1Path, "import { value } from './test2'\nexport const wrapper = { hello: value }");
const test2Path = this.resolvePath('src/test2.ts');
spruce_skill_utils_1.diskUtil.writeFile(test2Path, 'export const value = "world"');
await this.assertImportedCorrectly(test1Path, {
wrapper: { hello: 'world' },
});
spruce_skill_utils_1.diskUtil.writeFile(test2Path, 'export const value = "bar"');
await this.assertImportedCorrectly(test1Path, {
wrapper: { hello: 'bar' },
});
}
}
exports.default = CachingImportsTest;
__decorate([
(0, test_utils_1.test)()
], CachingImportsTest, "canTellIfFileChanged", null);
__decorate([
(0, test_utils_1.test)()
], CachingImportsTest, "canTellIfRelatedFileChanges", null);
__decorate([
(0, test_utils_1.test)()
], CachingImportsTest, "canTellIfFilesChangedInASkill", null);
//# sourceMappingURL=CachingImports.test.js.map