Skip to content

Commit

Permalink
fix: make lockfile practice only for js and ts
Browse files Browse the repository at this point in the history
  • Loading branch information
Jakub Vacek committed Jan 27, 2021
1 parent d11eb01 commit 660cd0b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { LockfileIsPresentPractice } from './LockfileIsPresentPractice';
import { PracticeEvaluationResult } from '../../model';
import { JsLockfileIsPresentPractice } from './JsLockfileIsPresentPractice';
import { PracticeEvaluationResult, ProgrammingLanguage } from '../../model';
import { TestContainerContext, createTestContainer } from '../../inversify.config';
import shelljs from 'shelljs';
import { sync as commandExists } from 'command-exists';
Expand All @@ -16,11 +16,11 @@ jest.mock('command-exists', () => ({

describe('LockfileIsPresentPractice', () => {
let containerCtx: TestContainerContext;
let practice: LockfileIsPresentPractice;
let practice: JsLockfileIsPresentPractice;

beforeAll(() => {
containerCtx = createTestContainer();
containerCtx.container.bind('LockfileIsPresentPractice').to(LockfileIsPresentPractice);
containerCtx.container.bind('LockfileIsPresentPractice').to(JsLockfileIsPresentPractice);
practice = containerCtx.container.get('LockfileIsPresentPractice');
});

Expand Down Expand Up @@ -60,11 +60,24 @@ describe('LockfileIsPresentPractice', () => {
expect(evaluated).toEqual(PracticeEvaluationResult.unknown);
});

it('Is always applicable', async () => {
const result = await practice.isApplicable();
it('Is applicable to JS', async () => {
containerCtx.practiceContext.projectComponent.language = ProgrammingLanguage.JavaScript;
const result = await practice.isApplicable(containerCtx.practiceContext);
expect(result).toEqual(true);
});

it('Is applicable to TS', async () => {
containerCtx.practiceContext.projectComponent.language = ProgrammingLanguage.TypeScript;
const result = await practice.isApplicable(containerCtx.practiceContext);
expect(result).toEqual(true);
});

it('Is not applicable to other languages', async () => {
containerCtx.practiceContext.projectComponent.language = ProgrammingLanguage.Python;
const result = await practice.isApplicable(containerCtx.practiceContext);
expect(result).toEqual(false);
});

describe('fixer', () => {
let npmInstallRun: boolean;
let yarnInstallRun: boolean;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { IPractice } from '../IPractice';
import { PracticeEvaluationResult, PracticeImpact } from '../../model';
import { PracticeEvaluationResult, PracticeImpact, ProgrammingLanguage } from '../../model';
import { DxPractice } from '../DxPracticeDecorator';
import { PracticeContext } from '../../contexts/practice/PracticeContext';
import { PackageManagerUtils, PackageManagerType } from '../utils/PackageManagerUtils';
Expand All @@ -13,9 +13,11 @@ import shell from 'shelljs';
reportOnlyOnce: true,
url: 'https://dxkb.io/p/lockfile',
})
export class LockfileIsPresentPractice implements IPractice {
async isApplicable(): Promise<boolean> {
return true;
export class JsLockfileIsPresentPractice implements IPractice {
async isApplicable(ctx: PracticeContext): Promise<boolean> {
return (
ctx.projectComponent.language === ProgrammingLanguage.JavaScript || ctx.projectComponent.language === ProgrammingLanguage.TypeScript
);
}

async evaluate(ctx: PracticeContext): Promise<PracticeEvaluationResult> {
Expand Down
4 changes: 2 additions & 2 deletions src/practices/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { TypeScriptUsedPractice } from './JavaScript/TypeScriptUsedPractice';
import { PrettierUsedPractice } from './JavaScript/PrettierUsedPractice';
import { ESLintUsedPractice } from './JavaScript/ESLintUsedPractice';
import { LockfileIsPresentPractice } from './PackageManagement/LockfileIsPresentPractice';
import { JsLockfileIsPresentPractice } from './JavaScript/JsLockfileIsPresentPractice';
import { JsFrontendTestingFrameworkUsedPractice } from './JavaScript/JsFrontendTestingFrameworkUsedPractice';
import { JsLoggerUsedPractice } from './JavaScript/JsLoggerUsedPractice';
import { LicenseIsPresentPractice } from './LanguageIndependent/LicenseIsPresentPractice';
Expand Down Expand Up @@ -49,7 +49,7 @@ export const practices = [
PrettierUsedPractice,
ESLintUsedPractice,
ESLintWithoutErrorsPractice,
LockfileIsPresentPractice,
JsLockfileIsPresentPractice,
JsFrontendTestingFrameworkUsedPractice,
JsBackendTestingFrameworkUsedPractice,
JsLoggerUsedPractice,
Expand Down

0 comments on commit 660cd0b

Please sign in to comment.