From d61fe6a68dbf95ddcc18e40af4b2ef187634c58c Mon Sep 17 00:00:00 2001 From: Prokop Simek Date: Tue, 11 Feb 2020 10:56:14 +0100 Subject: [PATCH] chore: lint all and remove unnecessary imports --- jest.config.js | 2 +- src/detectors/ScanningStrategyDetector.spec.ts | 5 ----- src/inspectors/CollaborationInspector.spec.ts | 2 -- src/inspectors/IssueTrackingInspector.spec.ts | 5 ----- src/lib/assertNever.spec.ts | 3 --- .../CorrectCommitMessagesPractice.spec.ts | 5 ----- src/practices/LanguageIndependent/DoesPullRequests.spec.ts | 5 ----- .../LanguageIndependent/ThinPullRequestsPractice.spec.ts | 6 ------ .../LanguageIndependent/TimeToSolveIssuesPractice.spec.ts | 5 ----- .../TimeToSolvePullRequestsPractice.spec.ts | 5 ----- src/practices/index.ts | 1 - src/services/bitbucket/BitbucketService.spec.ts | 4 +--- src/services/git/Git.spec.ts | 4 ---- src/services/git/GitHubService.spec.ts | 2 -- src/services/git/VCSServicesUtils.ts | 1 - src/test/helpers/bitbucketNock.ts | 2 -- src/test/jest.setupFileAfterEnv.ts | 5 +++++ 17 files changed, 7 insertions(+), 55 deletions(-) create mode 100644 src/test/jest.setupFileAfterEnv.ts diff --git a/jest.config.js b/jest.config.js index d9bd0b0b5..fecc4d8e7 100644 --- a/jest.config.js +++ b/jest.config.js @@ -114,7 +114,7 @@ module.exports = { setupFiles: ['./src/jest.setup.ts'], // A list of paths to modules that run some code to configure or set up the testing framework before each test - // setupFilesAfterEnv: [], + setupFilesAfterEnv: ['./src/test/jest.setupFileAfterEnv.ts'], // A list of paths to snapshot serializer modules Jest should use for snapshot testing // snapshotSerializers: [], diff --git a/src/detectors/ScanningStrategyDetector.spec.ts b/src/detectors/ScanningStrategyDetector.spec.ts index f15198071..d2cdb58b6 100644 --- a/src/detectors/ScanningStrategyDetector.spec.ts +++ b/src/detectors/ScanningStrategyDetector.spec.ts @@ -1,4 +1,3 @@ -import nock from 'nock'; import git from 'simple-git/promise'; import { createTestContainer } from '../inversify.config'; import { GitHubNock } from '../test/helpers/gitHubNock'; @@ -8,10 +7,6 @@ jest.mock('simple-git/promise'); describe('ScanningStrategyDetector', () => { const mockedGit = git; - beforeEach(() => { - nock.cleanAll(); - }); - describe('#detect', () => { it('local path without remote', async () => { mockedGit.mockImplementation(() => { diff --git a/src/inspectors/CollaborationInspector.spec.ts b/src/inspectors/CollaborationInspector.spec.ts index 9b54afb33..fc23358d4 100644 --- a/src/inspectors/CollaborationInspector.spec.ts +++ b/src/inspectors/CollaborationInspector.spec.ts @@ -1,5 +1,4 @@ import { CollaborationInspector } from './CollaborationInspector'; -import nock from 'nock'; import { TestContainerContext } from '../inversify.config'; import { createTestContainer } from '../inversify.config'; import { GitHubNock } from '../test/helpers/gitHubNock'; @@ -29,7 +28,6 @@ describe('Collaboration Inspector', () => { beforeEach(async () => { inspector = containerCtx.practiceContext.collaborationInspector; - nock.cleanAll(); }); it('returns paginated pull requests', async () => { diff --git a/src/inspectors/IssueTrackingInspector.spec.ts b/src/inspectors/IssueTrackingInspector.spec.ts index a7294b0d7..92d597505 100644 --- a/src/inspectors/IssueTrackingInspector.spec.ts +++ b/src/inspectors/IssueTrackingInspector.spec.ts @@ -1,5 +1,4 @@ import { IssueTrackingInspector } from './IssueTrackingInspector'; -import nock from 'nock'; import { TestContainerContext, createTestContainer } from '../inversify.config'; import { GitHubNock } from '../test/helpers/gitHubNock'; import { @@ -20,10 +19,6 @@ describe('Issue Tracking Inspector', () => { inspector = containerCtx.practiceContext.issueTrackingInspector; }); - beforeEach(() => { - nock.cleanAll(); - }); - it('returns paginated issues', async () => { new GitHubNock('1', 'octocat', 1, 'Hello-World').getIssues().reply(200, getIssuesResponse); const response = await inspector.listIssues('octocat', 'Hello-World'); diff --git a/src/lib/assertNever.spec.ts b/src/lib/assertNever.spec.ts index d7f2f5581..a34e57523 100644 --- a/src/lib/assertNever.spec.ts +++ b/src/lib/assertNever.spec.ts @@ -1,7 +1,4 @@ import { assertNever } from './assertNever'; -import { ProgrammingLanguage, PracticeImpact } from '../model'; -import { PracticeDetail } from '../practices/IPractice'; -import { ReportDetailType, ReporterData } from '../reporters/ReporterData'; describe('AssertNever', () => { it('Throws error if it is called', () => { diff --git a/src/practices/LanguageIndependent/CorrectCommitMessagesPractice.spec.ts b/src/practices/LanguageIndependent/CorrectCommitMessagesPractice.spec.ts index c52752e0d..c3de258c0 100644 --- a/src/practices/LanguageIndependent/CorrectCommitMessagesPractice.spec.ts +++ b/src/practices/LanguageIndependent/CorrectCommitMessagesPractice.spec.ts @@ -1,4 +1,3 @@ -import nock from 'nock'; import { CollaborationInspector } from '../../inspectors/CollaborationInspector'; import { createTestContainer, TestContainerContext } from '../../inversify.config'; import { PracticeEvaluationResult } from '../../model'; @@ -14,10 +13,6 @@ describe('CorrectCommitMessagesPractice', () => { const MockedCollaborationInspector = >(CollaborationInspector); let mockCollaborationInspector: CollaborationInspector; - beforeEach(async () => { - nock.cleanAll(); - }); - beforeAll(() => { containerCtx = createTestContainer(); containerCtx.container.bind('CorrectCommitMessagesPractice').to(CorrectCommitMessagesPractice); diff --git a/src/practices/LanguageIndependent/DoesPullRequests.spec.ts b/src/practices/LanguageIndependent/DoesPullRequests.spec.ts index 26905ef82..ec5bd569a 100644 --- a/src/practices/LanguageIndependent/DoesPullRequests.spec.ts +++ b/src/practices/LanguageIndependent/DoesPullRequests.spec.ts @@ -1,7 +1,6 @@ import { createTestContainer, TestContainerContext } from '../../inversify.config'; import { PracticeEvaluationResult } from '../../model'; import { DoesPullRequestsPractice } from './DoesPullRequests'; -import nock from 'nock'; import { GitHubNock } from '../../test/helpers/gitHubNock'; import { getRepoCommitsResponse } from '../../services/git/__MOCKS__/gitHubServiceMockFolder/getRepoCommitsResponse.mock'; import { PullRequestState } from '../../inspectors/ICollaborationInspector'; @@ -10,10 +9,6 @@ describe('DoesPullRequests', () => { let practice: DoesPullRequestsPractice; let containerCtx: TestContainerContext; - beforeEach(async () => { - nock.cleanAll(); - }); - beforeAll(() => { containerCtx = createTestContainer(); containerCtx.container.bind('DoesPullRequests').to(DoesPullRequestsPractice); diff --git a/src/practices/LanguageIndependent/ThinPullRequestsPractice.spec.ts b/src/practices/LanguageIndependent/ThinPullRequestsPractice.spec.ts index 481375ecf..d71dbaf9a 100644 --- a/src/practices/LanguageIndependent/ThinPullRequestsPractice.spec.ts +++ b/src/practices/LanguageIndependent/ThinPullRequestsPractice.spec.ts @@ -1,4 +1,3 @@ -import nock from 'nock'; import { CollaborationInspector } from '../../inspectors'; import { createTestContainer, TestContainerContext } from '../../inversify.config'; import { PracticeEvaluationResult } from '../../model'; @@ -8,7 +7,6 @@ import { ThinPullRequestsPractice } from './ThinPullRequestsPractice'; import { getPullRequestsResponse } from '../../services/git/__MOCKS__/bitbucketServiceMockFolder/getPullRequestsResponse'; import moment from 'moment'; import { getPullRequestResponse } from '../../services/git/__MOCKS__/bitbucketServiceMockFolder'; -import _ from 'lodash'; describe('ThinPullRequestsPractice', () => { let practice: ThinPullRequestsPractice; @@ -16,10 +14,6 @@ describe('ThinPullRequestsPractice', () => { const MockedCollaborationInspector = >(CollaborationInspector); let mockCollaborationInspector: CollaborationInspector; - beforeEach(async () => { - nock.cleanAll(); - }); - beforeAll(() => { containerCtx = createTestContainer(); containerCtx.container.bind('ThinPullRequestsPractice').to(ThinPullRequestsPractice); diff --git a/src/practices/LanguageIndependent/TimeToSolveIssuesPractice.spec.ts b/src/practices/LanguageIndependent/TimeToSolveIssuesPractice.spec.ts index 9897d265d..dc1e8402d 100644 --- a/src/practices/LanguageIndependent/TimeToSolveIssuesPractice.spec.ts +++ b/src/practices/LanguageIndependent/TimeToSolveIssuesPractice.spec.ts @@ -1,5 +1,4 @@ import moment from 'moment'; -import nock from 'nock'; import { IssueTrackingInspector } from '../../inspectors'; import { createTestContainer, TestContainerContext } from '../../inversify.config'; import { PracticeEvaluationResult } from '../../model'; @@ -16,10 +15,6 @@ describe('TimeToSolveIssuesPractice', () => { const MockedIssueTrackingInspector = >(IssueTrackingInspector); let mockIssueTrackingInspector: IssueTrackingInspector; - beforeEach(async () => { - nock.cleanAll(); - }); - beforeAll(() => { containerCtx = createTestContainer(); containerCtx.container.bind('TimeToSolveIssuesPractice').to(TimeToSolveIssuesPractice); diff --git a/src/practices/LanguageIndependent/TimeToSolvePullRequestsPractice.spec.ts b/src/practices/LanguageIndependent/TimeToSolvePullRequestsPractice.spec.ts index 9d8660461..4c86f389e 100644 --- a/src/practices/LanguageIndependent/TimeToSolvePullRequestsPractice.spec.ts +++ b/src/practices/LanguageIndependent/TimeToSolvePullRequestsPractice.spec.ts @@ -1,5 +1,4 @@ import moment from 'moment'; -import nock from 'nock'; import { CollaborationInspector } from '../../inspectors'; import { createTestContainer, TestContainerContext } from '../../inversify.config'; import { PracticeEvaluationResult } from '../../model'; @@ -16,10 +15,6 @@ describe('TimeToSolvePullRequestsPractice', () => { const MockedCollaborationInspector = >(CollaborationInspector); let mockCollaborationInspector: CollaborationInspector; - beforeEach(async () => { - nock.cleanAll(); - }); - beforeAll(() => { containerCtx = createTestContainer(); containerCtx.container.bind('TimeToSolvePractice').to(TimeToSolvePullRequestsPractice); diff --git a/src/practices/index.ts b/src/practices/index.ts index 88aa0c974..a20842f7b 100644 --- a/src/practices/index.ts +++ b/src/practices/index.ts @@ -29,7 +29,6 @@ import { TimeToSolvePullRequestsPractice } from './LanguageIndependent/TimeToSol import { TimeToSolveIssuesPractice } from './LanguageIndependent/TimeToSolveIssuesPractice'; import { ThinPullRequestsPractice } from './LanguageIndependent/ThinPullRequestsPractice'; import { SecurityVulnerabilitiesPractice } from './JavaScript/SecurityVulnerabilitiesPractice'; -import { FirstTestPractice, SecondTestPractice, InvalidTestPractice } from '../scanner'; import { JavaPackageManagementUsedPractice } from './Java/JavaPackageManagementUsedPractice'; import { JavaLoggerUsedPractice } from './Java/JavaLoggerUsedPractice'; import { JavaTestingFrameworkUsedPractice } from './Java/JavaTestingFrameworkUsedPractice'; diff --git a/src/services/bitbucket/BitbucketService.spec.ts b/src/services/bitbucket/BitbucketService.spec.ts index 5fa6c1929..14fefaa3d 100644 --- a/src/services/bitbucket/BitbucketService.spec.ts +++ b/src/services/bitbucket/BitbucketService.spec.ts @@ -1,4 +1,3 @@ -import nock from 'nock'; import { PullRequestState, IssueState } from '../../inspectors'; import { getIssueResponse, @@ -24,7 +23,7 @@ describe('Bitbucket Service', () => { beforeEach(async () => { service = new BitbucketService(argumentsProviderFactory({ uri: '.' })); - nock.cleanAll(); + bitbucketNock = new BitbucketNock('pypy', 'pypy'); }); @@ -131,7 +130,6 @@ describe('Bitbucket Service', () => { it('returns open issues in own interface', async () => { const mockIssue = bitbucketIssueResponseFactory({ state: BitbucketIssueState.new }); - bitbucketNock.getOwnerId(); bitbucketNock.listIssuesResponse([mockIssue], { filter: { state: BitbucketIssueState.new } }); const response = await service.listIssues('pypy', 'pypy', { filter: { state: IssueState.open } }); diff --git a/src/services/git/Git.spec.ts b/src/services/git/Git.spec.ts index 34ec29629..166c2da53 100644 --- a/src/services/git/Git.spec.ts +++ b/src/services/git/Git.spec.ts @@ -1,6 +1,5 @@ import { Git } from './Git'; import { GitHubNock } from '../../test/helpers/gitHubNock'; -import nock from 'nock'; import { GitHubService } from './GitHubService'; import { argumentsProviderFactory } from '../../test/factories/ArgumentsProviderFactory'; @@ -15,7 +14,6 @@ describe('Git', () => { beforeEach(() => { service.purgeCache(); - nock.cleanAll(); }); describe('#exists', () => { @@ -240,8 +238,6 @@ describe('Git', () => { it('stops on false', async () => { gitHubNock.getDirectory('mockFolder', ['mockFile.ts'], ['mockSubFolder']); gitHubNock.getFile('mockFolder/mockFile.ts'); - gitHubNock.getDirectory('mockFolder/mockSubFolder', ['mockSubFolderFile.txt'], []); - gitHubNock.getFile('mockFolder/mockSubFolder/mockSubFolderFile.txt'); const files: string[] = []; diff --git a/src/services/git/GitHubService.spec.ts b/src/services/git/GitHubService.spec.ts index 31e8328fd..9d2dc3560 100644 --- a/src/services/git/GitHubService.spec.ts +++ b/src/services/git/GitHubService.spec.ts @@ -1,5 +1,4 @@ /* eslint-disable @typescript-eslint/camelcase */ -import nock from 'nock'; import { GitHubService } from './GitHubService'; import { GitHubNock } from '../../test/helpers/gitHubNock'; import { @@ -34,7 +33,6 @@ describe('GitHub Service', () => { beforeEach(async () => { service = new GitHubService(argumentsProviderFactory({ uri: '.' })); - nock.cleanAll(); }); describe('#getPullRequests', () => { diff --git a/src/services/git/VCSServicesUtils.ts b/src/services/git/VCSServicesUtils.ts index f754361e5..a37545528 100644 --- a/src/services/git/VCSServicesUtils.ts +++ b/src/services/git/VCSServicesUtils.ts @@ -1,5 +1,4 @@ import { PullRequestState } from '../../inspectors/ICollaborationInspector'; -import { VCSServiceType } from './IVCSService'; import { GitHubIssueState } from './IGitHubService'; import { IssueState } from '../../inspectors'; import { BitbucketIssueState, BitbucketPullRequestState } from '../bitbucket/IBitbucketService'; diff --git a/src/test/helpers/bitbucketNock.ts b/src/test/helpers/bitbucketNock.ts index 5e834cafd..c47cc0af8 100644 --- a/src/test/helpers/bitbucketNock.ts +++ b/src/test/helpers/bitbucketNock.ts @@ -7,8 +7,6 @@ import { bitbucketListPRsResponseFactory } from '../factories/responses/bitbucke import { bitbucketListPullCommitsResponseFactory } from '../factories/responses/bitbucket/listPullCommitsResponseFactory'; import { bitbucketListCommitResponseFactory } from '../factories/responses/bitbucket/listRepoCommitsResponseFactory'; import { BitbucketPullRequestState, BitbucketIssueState } from '../../services/bitbucket/IBitbucketService'; -import _ from 'lodash'; -import qs from 'qs'; import { VCSServicesUtils } from '../../services/git/VCSServicesUtils'; export class BitbucketNock { diff --git a/src/test/jest.setupFileAfterEnv.ts b/src/test/jest.setupFileAfterEnv.ts new file mode 100644 index 000000000..8ce27770d --- /dev/null +++ b/src/test/jest.setupFileAfterEnv.ts @@ -0,0 +1,5 @@ +import nock from 'nock'; + +beforeEach(() => { + nock.cleanAll(); +});