UNPKG

declapract

Version:

A tool to declaratively define best practices, maintainable evolve them, and scalably enforce them.

101 lines 5.92 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const shelljs_1 = __importDefault(require("shelljs")); const dirPath_1 = require("../__test_assets__/dirPath"); const readUsePracticesConfig_1 = require("./readUsePracticesConfig"); describe('readUsePracticesConfig', () => { it('should read usage config specifying locally declared practices, by directory', () => __awaiter(void 0, void 0, void 0, function* () { const config = yield (0, readUsePracticesConfig_1.readUsePracticesConfig)({ configPath: `${dirPath_1.testAssetsDirectoryPath}/example-service-1-repo/declapract.use.yml`, }); expect(config.scope.usecase).toEqual('lambda-service'); expect(config.variables).toHaveProperty('organizationName'); expect(config.declared.practices.length); expect(config).toMatchSnapshot({ rootDir: expect.any(String), declared: expect.objectContaining({ rootDir: expect.any(String) }), }); })); it('should read usage config specifying locally declared practices, by custom config path', () => __awaiter(void 0, void 0, void 0, function* () { const config = yield (0, readUsePracticesConfig_1.readUsePracticesConfig)({ configPath: `${dirPath_1.testAssetsDirectoryPath}/example-service-2-repo/declapract.use.yml`, }); expect(config.scope.usecase).toEqual('lambda-service'); expect(config.variables).toHaveProperty('organizationName'); expect(config.declared.practices.length); expect(config).toMatchSnapshot({ rootDir: expect.any(String), declared: expect.objectContaining({ rootDir: expect.any(String) }), }); })); it('should read usage config with explicit practices scope', () => __awaiter(void 0, void 0, void 0, function* () { const config = yield (0, readUsePracticesConfig_1.readUsePracticesConfig)({ configPath: `${dirPath_1.testAssetsDirectoryPath}/example-project-passes-uses-practices-directly/declapract.use.yml`, }); expect(config.scope.usecase).toEqual('lambda-service'); expect(config.scope.practices).toEqual([ 'cicd-common', 'conventional-commits', 'husky', ]); expect(config.variables).toHaveProperty('organizationName'); expect(config.declared.practices.length); expect(config).toMatchSnapshot({ rootDir: expect.any(String), declared: expect.objectContaining({ rootDir: expect.any(String) }), }); })); it('should read usage config with exclusively practices scope', () => __awaiter(void 0, void 0, void 0, function* () { const config = yield (0, readUsePracticesConfig_1.readUsePracticesConfig)({ configPath: `${dirPath_1.testAssetsDirectoryPath}/example-project-passes-uses-practices-exclusively/declapract.use.yml`, }); expect(config.scope.usecase).toEqual(null); expect(config.scope.practices).toEqual([ 'cicd-common', 'conventional-commits', 'husky', ]); expect(config.variables).toHaveProperty('organizationName'); expect(config.declared.practices.length); expect(config).toMatchSnapshot({ rootDir: expect.any(String), declared: expect.objectContaining({ rootDir: expect.any(String) }), }); })); // TODO: make this test work again, after we create a simple declapract package for testing (live ones get too many type errors w/ this project's settings + being nested in src/) it.skip('should read usage config specifying npm module with declarations', () => __awaiter(void 0, void 0, void 0, function* () { var _a; // npm install the declarations module yield shelljs_1.default.cd(`${dirPath_1.testAssetsDirectoryPath}/example-service-3-repo`); const result = yield shelljs_1.default.exec('npm install'); if (result.code !== 0) throw new Error((_a = result.stderr) !== null && _a !== void 0 ? _a : result.stdout); // now read the config const config = yield (0, readUsePracticesConfig_1.readUsePracticesConfig)({ configPath: `${dirPath_1.testAssetsDirectoryPath}/example-service-3-repo/declapract.use.yml`, }); expect(config.declared.practices.length).toBeGreaterThan(3); // should be atleast 3 defined there expect(config.scope.usecase).toEqual('lambda-service'); expect(config.variables).toHaveProperty('organizationName'); expect(config.declared.practices.length); expect(config).toMatchSnapshot({ rootDir: expect.any(String), declared: expect.objectContaining({ rootDir: expect.stringContaining('example-service-3-repo/node_modules/best-practices-typescript'), // should reference the `.declapract` dir of the example project (since that's where we clone git repos into) }), }); })); }); //# sourceMappingURL=readUsePracticesConfig.integration.test.js.map