declapract
Version:
A tool to declaratively define best practices, maintainable evolve them, and scalably enforce them.
63 lines • 3.65 kB
JavaScript
;
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', async () => {
const practice = await (0, readPracticeDeclaration_1.readPracticeDeclaration)({
declaredPracticeDirectory: `${dirPath_1.testAssetsDirectoryPath}/example-best-practices-repo/src/practices/dates-and-times`,
});
const plans = await (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', async () => {
const practice = await (0, readPracticeDeclaration_1.readPracticeDeclaration)({
declaredPracticeDirectory: `${dirPath_1.testAssetsDirectoryPath}/example-best-practices-repo/src/practices/prettier`,
});
const plans = await (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', async () => {
const practices = await 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 = await (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