declapract
Version:
A tool to declaratively define best practices, maintainable evolve them, and scalably enforce them.
72 lines • 4.46 kB
JavaScript
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());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const domain_1 = require("../../../domain");
const dirPath_1 = require("../../__test_assets__/dirPath");
const readPracticeDeclaration_1 = require("../../declaration/readPracticeDeclarations/readPracticeDeclaration/readPracticeDeclaration");
const getPlansForProject_1 = require("./getPlansForProject");
describe('getPlansForProject', () => {
it('should define that a file failing a check that is not automatically fixable needs FIX_MANUAL action', () => __awaiter(void 0, void 0, void 0, function* () {
const practice = yield (0, readPracticeDeclaration_1.readPracticeDeclaration)({
declaredPracticeDirectory: `${dirPath_1.testAssetsDirectoryPath}/example-best-practices-repo/src/practices/dates-and-times`,
});
const plans = yield (0, getPlansForProject_1.getPlansForProject)({
projectRootDirectory: `${dirPath_1.testAssetsDirectoryPath}/example-project-fails-prettier`,
practices: [practice],
projectVariables: {},
});
// console.log(JSON.stringify(plans, null, 2));
expect(plans.find((plan) => plan.path === 'package.json')).toMatchObject({
action: domain_1.RequiredAction.FIX_MANUAL,
});
expect(plans.find((plan) => plan.path === '.prettierignore')).toEqual(undefined); // not evaluated since not in the practices
}));
it('should define that a file failing a check that _is_ automatically fixable needs FIX_AUTOMATIC action', () => __awaiter(void 0, void 0, void 0, function* () {
const practice = yield (0, readPracticeDeclaration_1.readPracticeDeclaration)({
declaredPracticeDirectory: `${dirPath_1.testAssetsDirectoryPath}/example-best-practices-repo/src/practices/prettier`,
});
const plans = yield (0, getPlansForProject_1.getPlansForProject)({
projectRootDirectory: `${dirPath_1.testAssetsDirectoryPath}/example-project-fails-prettier`,
practices: [practice],
projectVariables: {},
});
// console.log(JSON.stringify(plans, null, 2));
expect(plans.find((plan) => plan.path === '.prettierignore')).toMatchObject({
action: domain_1.RequiredAction.FIX_AUTOMATIC,
});
expect(plans.find((plan) => plan.path === 'package.json')).toMatchObject({
action: domain_1.RequiredAction.NO_CHANGE,
});
}));
it('should combine evaluations per file across multiple practices', () => __awaiter(void 0, void 0, void 0, function* () {
const practices = yield Promise.all([
(0, readPracticeDeclaration_1.readPracticeDeclaration)({
declaredPracticeDirectory: `${dirPath_1.testAssetsDirectoryPath}/example-best-practices-repo/src/practices/dates-and-times`,
}),
(0, readPracticeDeclaration_1.readPracticeDeclaration)({
declaredPracticeDirectory: `${dirPath_1.testAssetsDirectoryPath}/example-best-practices-repo/src/practices/prettier`,
}),
]);
const plans = yield (0, getPlansForProject_1.getPlansForProject)({
projectRootDirectory: `${dirPath_1.testAssetsDirectoryPath}/example-project-fails-prettier`,
practices,
projectVariables: {},
});
// console.log(JSON.stringify(plans, null, 2));
expect(plans.find((plan) => plan.path === '.prettierignore')).toMatchObject({
action: domain_1.RequiredAction.FIX_AUTOMATIC,
});
expect(plans.find((plan) => plan.path === 'package.json')).toMatchObject({
action: domain_1.RequiredAction.FIX_MANUAL,
});
}));
});
//# sourceMappingURL=getPlansForProject.integration.test.js.map
;