From 8dfc18b05f2cc8d34e943b15af15804fdab8ce65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Colladon?= Date: Fri, 8 Sep 2023 14:06:28 +0200 Subject: [PATCH] fix: integration job feedback --- .eslintrc.js | 1 + .github/linters/.cspell.json | 2 + __tests__/functional/delta.nut.ts | 2 +- __tests__/perf/{bench.js => bench.mjs} | 6 +- .../post-processor/includeProcessor.test.ts | 1 - __tests__/unit/lib/service/lwcHandler.test.ts | 4 +- __tests__/unit/lib/utils/fxpHelper.test.ts | 2 +- __tests__/unit/lib/utils/metadataDiff.test.ts | 1 + __tests__/unit/lib/utils/repoGitDiff.test.ts | 96 +++++++++---------- __tests__/unit/lib/utils/repoSetup.test.ts | 4 +- package.json | 2 +- src/utils/repoGitDiff.ts | 41 ++++---- tsconfig.json | 2 +- 13 files changed, 87 insertions(+), 77 deletions(-) rename __tests__/perf/{bench.js => bench.mjs} (77%) diff --git a/.eslintrc.js b/.eslintrc.js index 30fbd5c0..174ae300 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -33,6 +33,7 @@ module.exports = { }, plugins: ['prettier', '@typescript-eslint'], rules: { + '@typescript-eslint/no-non-null-assertion': 'off', '@typescript-eslint/brace-style': 'off', '@typescript-eslint/comma-dangle': 'off', '@typescript-eslint/comma-spacing': 'off', diff --git a/.github/linters/.cspell.json b/.github/linters/.cspell.json index 23e58040..9387c4a5 100644 --- a/.github/linters/.cspell.json +++ b/.github/linters/.cspell.json @@ -74,6 +74,7 @@ "ignorewarnings", "iife", "indx", + "Infile", "lcov", "linebreak", "lintstagedrc", @@ -92,6 +93,7 @@ "mutingpermissionsets", "myexperiencebundle", "nonblock", + "notblank", "notexist", "notificationtypes", "notiftype", diff --git a/__tests__/functional/delta.nut.ts b/__tests__/functional/delta.nut.ts index 927d0efd..3fe779fa 100644 --- a/__tests__/functional/delta.nut.ts +++ b/__tests__/functional/delta.nut.ts @@ -74,7 +74,7 @@ const getFileLineNumber = async (path: string) => { output: process.stdout, terminal: false, }) - // eslint-disable-next-line no-unused-vars + // eslint-disable-next-line no-unused-vars, @typescript-eslint/no-unused-vars for await (const _ of rl) { ++linesCount } diff --git a/__tests__/perf/bench.js b/__tests__/perf/bench.mjs similarity index 77% rename from __tests__/perf/bench.js rename to __tests__/perf/bench.mjs index 202a3c85..2d57f1bf 100644 --- a/__tests__/perf/bench.js +++ b/__tests__/perf/bench.mjs @@ -1,7 +1,7 @@ 'use strict' -const { execCmd } = require('@salesforce/cli-plugins-testkit') -const Benchmark = require('benchmark') -const suite = new Benchmark.Suite() +import { execCmd } from '@salesforce/cli-plugins-testkit' +import benchmark from 'benchmark' +const suite = new benchmark.Suite() suite .add('e2e-test', () => { diff --git a/__tests__/unit/lib/post-processor/includeProcessor.test.ts b/__tests__/unit/lib/post-processor/includeProcessor.test.ts index 03f5ff11..ef800a2a 100644 --- a/__tests__/unit/lib/post-processor/includeProcessor.test.ts +++ b/__tests__/unit/lib/post-processor/includeProcessor.test.ts @@ -146,4 +146,3 @@ describe('IncludeProcessor', () => { }) }) }) -it('test', () => {}) diff --git a/__tests__/unit/lib/service/lwcHandler.test.ts b/__tests__/unit/lib/service/lwcHandler.test.ts index a664ae0b..003374f7 100644 --- a/__tests__/unit/lib/service/lwcHandler.test.ts +++ b/__tests__/unit/lib/service/lwcHandler.test.ts @@ -5,11 +5,11 @@ import LwcHandler from '../../../../src/service/lwcHandler' import { copyFiles } from '../../../../src/utils/fsHelper' import { Work } from '../../../../src/types/work' import { MetadataRepository } from '../../../../src/types/metadata' -const { +import { ADDITION, DELETION, MODIFICATION, -} = require('../../../../src/utils/gitConstants') +} from '../../../../src/utils/gitConstants' jest.mock('../../../../src/utils/fsHelper') diff --git a/__tests__/unit/lib/utils/fxpHelper.test.ts b/__tests__/unit/lib/utils/fxpHelper.test.ts index 74c09718..9c695e9c 100644 --- a/__tests__/unit/lib/utils/fxpHelper.test.ts +++ b/__tests__/unit/lib/utils/fxpHelper.test.ts @@ -92,7 +92,7 @@ describe('fxpHelper', () => { describe('when called with non xml content', () => { beforeEach(() => { // Arrange - mockedReadPathFromGit.mockResolvedValueOnce('{"attribut": "value"}') + mockedReadPathFromGit.mockResolvedValueOnce('{"attribute": "value"}') }) it('returns empty object', async () => { // Act diff --git a/__tests__/unit/lib/utils/metadataDiff.test.ts b/__tests__/unit/lib/utils/metadataDiff.test.ts index 1e9478c8..2dcdf2d8 100644 --- a/__tests__/unit/lib/utils/metadataDiff.test.ts +++ b/__tests__/unit/lib/utils/metadataDiff.test.ts @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ 'use strict' import { expect, jest, describe, it } from '@jest/globals' import { getGlobalMetadata, getWork } from '../../../__utils__/globalTestHelper' diff --git a/__tests__/unit/lib/utils/repoGitDiff.test.ts b/__tests__/unit/lib/utils/repoGitDiff.test.ts index 472373ac..745fb609 100644 --- a/__tests__/unit/lib/utils/repoGitDiff.test.ts +++ b/__tests__/unit/lib/utils/repoGitDiff.test.ts @@ -28,7 +28,7 @@ jest.mock('../../../../src/utils/childProcessUtils', () => { }) const mockedGetSpawContent = jest.mocked(getSpawnContent) -const mockedGetSpawContentByLine = jest.mocked(getSpawnContentByLine) +const mockedGetSpawnContentByLine = jest.mocked(getSpawnContentByLine) const FORCEIGNORE_MOCK_PATH = '__mocks__/.forceignore' @@ -61,7 +61,7 @@ describe(`test if repoGitDiff`, () => { }) it('can parse git correctly', async () => { const output: string[] = [] - mockedGetSpawContentByLine.mockResolvedValue([]) + mockedGetSpawnContentByLine.mockResolvedValue([]) config.ignore = FORCEIGNORE_MOCK_PATH config.ignoreWhitespace = true const repoGitDiff = new RepoGitDiff(config, globalMetadata) @@ -71,7 +71,7 @@ describe(`test if repoGitDiff`, () => { it('can parse git permissively', async () => { const output: string[] = [] - mockedGetSpawContentByLine.mockResolvedValue([]) + mockedGetSpawnContentByLine.mockResolvedValue([]) config.ignore = FORCEIGNORE_MOCK_PATH const repoGitDiff = new RepoGitDiff(config, globalMetadata) const work = await repoGitDiff.getLines() @@ -82,11 +82,11 @@ describe(`test if repoGitDiff`, () => { const output: string[] = [ 'force-app/main/default/objects/Account/fields/awesome.field-meta.xml', ] - mockedGetSpawContentByLine.mockResolvedValueOnce([]) - mockedGetSpawContentByLine.mockResolvedValueOnce( + mockedGetSpawnContentByLine.mockResolvedValueOnce([]) + mockedGetSpawnContentByLine.mockResolvedValueOnce( output.map(x => `1${TAB}1${TAB}${x}`) ) - mockedGetSpawContentByLine.mockResolvedValueOnce([]) + mockedGetSpawnContentByLine.mockResolvedValueOnce([]) config.ignore = FORCEIGNORE_MOCK_PATH const repoGitDiff = new RepoGitDiff(config, globalMetadata) const work = await repoGitDiff.getLines() @@ -97,11 +97,11 @@ describe(`test if repoGitDiff`, () => { const output: string[] = [ 'force-app/main/default/objects/Account/fields/awesome.field-meta.xml', ] - mockedGetSpawContentByLine.mockResolvedValueOnce([]) - mockedGetSpawContentByLine.mockResolvedValueOnce( + mockedGetSpawnContentByLine.mockResolvedValueOnce([]) + mockedGetSpawnContentByLine.mockResolvedValueOnce( output.map(x => `1${TAB}1${TAB}${x}`) ) - mockedGetSpawContentByLine.mockResolvedValueOnce([]) + mockedGetSpawnContentByLine.mockResolvedValueOnce([]) const repoGitDiff = new RepoGitDiff(config, globalMetadata) const work = await repoGitDiff.getLines() expect(work).toStrictEqual(output.map(x => `${DELETION}${TAB}${x}`)) @@ -111,11 +111,11 @@ describe(`test if repoGitDiff`, () => { const output: string[] = [ 'force-app/main/default/objects/Account/fields/awesome.field-meta.xml', ] - mockedGetSpawContentByLine.mockResolvedValueOnce( + mockedGetSpawnContentByLine.mockResolvedValueOnce( output.map(x => `1${TAB}1${TAB}${x}`) ) - mockedGetSpawContentByLine.mockResolvedValueOnce([]) - mockedGetSpawContentByLine.mockResolvedValueOnce([]) + mockedGetSpawnContentByLine.mockResolvedValueOnce([]) + mockedGetSpawnContentByLine.mockResolvedValueOnce([]) const repoGitDiff = new RepoGitDiff(config, globalMetadata) const work = await repoGitDiff.getLines() expect(work).toStrictEqual(output.map(x => `${ADDITION}${TAB}${x}`)) @@ -125,11 +125,11 @@ describe(`test if repoGitDiff`, () => { const output: string[] = [ 'force-app/main/default/objects/Account/fields/awesome.field-meta.xml', ] - mockedGetSpawContentByLine.mockResolvedValueOnce( + mockedGetSpawnContentByLine.mockResolvedValueOnce( output.map(x => `1${TAB}1${TAB}${x}`) ) - mockedGetSpawContentByLine.mockResolvedValueOnce([]) - mockedGetSpawContentByLine.mockResolvedValueOnce([]) + mockedGetSpawnContentByLine.mockResolvedValueOnce([]) + mockedGetSpawnContentByLine.mockResolvedValueOnce([]) const repoGitDiff = new RepoGitDiff(config, globalMetadata) const work = await repoGitDiff.getLines() expect(work).toStrictEqual(output.map(x => `${ADDITION}${TAB}${x}`)) @@ -139,9 +139,9 @@ describe(`test if repoGitDiff`, () => { const output: string[] = [ 'force-app/main/default/objects/Account/fields/awesome.field-meta.xml', ] - mockedGetSpawContentByLine.mockResolvedValueOnce([]) - mockedGetSpawContentByLine.mockResolvedValueOnce([]) - mockedGetSpawContentByLine.mockResolvedValueOnce( + mockedGetSpawnContentByLine.mockResolvedValueOnce([]) + mockedGetSpawnContentByLine.mockResolvedValueOnce([]) + mockedGetSpawnContentByLine.mockResolvedValueOnce( output.map(x => `1${TAB}1${TAB}${x}`) ) const repoGitDiff = new RepoGitDiff(config, globalMetadata) @@ -153,9 +153,9 @@ describe(`test if repoGitDiff`, () => { const output: string[] = [ 'force-app/main/default/objects/Account/fields/awesome.field-meta.xml', ] - mockedGetSpawContentByLine.mockResolvedValueOnce([]) - mockedGetSpawContentByLine.mockResolvedValueOnce([]) - mockedGetSpawContentByLine.mockResolvedValueOnce( + mockedGetSpawnContentByLine.mockResolvedValueOnce([]) + mockedGetSpawnContentByLine.mockResolvedValueOnce([]) + mockedGetSpawnContentByLine.mockResolvedValueOnce( output.map(x => `1${TAB}1${TAB}${x}`) ) const repoGitDiff = new RepoGitDiff(config, globalMetadata) @@ -165,11 +165,11 @@ describe(`test if repoGitDiff`, () => { it('can filter ignored files', async () => { const output = 'force-app/main/default/pages/test.page-meta.xml' - mockedGetSpawContentByLine.mockResolvedValueOnce([ + mockedGetSpawnContentByLine.mockResolvedValueOnce([ `1${TAB}1${TAB}${output}`, ]) - mockedGetSpawContentByLine.mockResolvedValueOnce([]) - mockedGetSpawContentByLine.mockResolvedValueOnce([]) + mockedGetSpawnContentByLine.mockResolvedValueOnce([]) + mockedGetSpawnContentByLine.mockResolvedValueOnce([]) config.ignore = FORCEIGNORE_MOCK_PATH const repoGitDiff = new RepoGitDiff(config, globalMetadata) const work = await repoGitDiff.getLines() @@ -180,11 +180,11 @@ describe(`test if repoGitDiff`, () => { it('can filter ignored destructive files', async () => { const output = 'force-app/main/default/pages/test.page-meta.xml' - mockedGetSpawContentByLine.mockResolvedValueOnce([]) + mockedGetSpawnContentByLine.mockResolvedValueOnce([]) mockedGetSpawContent.mockResolvedValueOnce( Buffer.from(`1${TAB}1${TAB}${output}`) ) - mockedGetSpawContentByLine.mockResolvedValueOnce([]) + mockedGetSpawnContentByLine.mockResolvedValueOnce([]) config.ignoreDestructive = FORCEIGNORE_MOCK_PATH const repoGitDiff = new RepoGitDiff(config, globalMetadata) const work = await repoGitDiff.getLines() @@ -195,7 +195,7 @@ describe(`test if repoGitDiff`, () => { it('can filter ignored and ignored destructive files', async () => { const output = 'force-app/main/default/lwc/jsconfig.json' - mockedGetSpawContentByLine.mockResolvedValueOnce([]) + mockedGetSpawnContentByLine.mockResolvedValueOnce([]) mockedGetSpawContent.mockResolvedValueOnce( Buffer.from(`1${TAB}1${TAB}${output}`) ) @@ -213,11 +213,11 @@ describe(`test if repoGitDiff`, () => { it('can filter deletion if only ignored is specified files', async () => { const output = 'force-app/main/default/pages/test.page-meta.xml' - mockedGetSpawContentByLine.mockResolvedValueOnce([]) - mockedGetSpawContentByLine.mockResolvedValueOnce([ + mockedGetSpawnContentByLine.mockResolvedValueOnce([]) + mockedGetSpawnContentByLine.mockResolvedValueOnce([ `1${TAB}1${TAB}${output}`, ]) - mockedGetSpawContentByLine.mockResolvedValueOnce([]) + mockedGetSpawnContentByLine.mockResolvedValueOnce([]) config.ignore = FORCEIGNORE_MOCK_PATH const repoGitDiff = new RepoGitDiff(config, globalMetadata) const work = await repoGitDiff.getLines() @@ -228,11 +228,11 @@ describe(`test if repoGitDiff`, () => { it('cannot filter non deletion if only ignored destructive is specified files', async () => { const output = 'force-app/main/default/pages/test.page-meta.xml' - mockedGetSpawContentByLine.mockResolvedValueOnce([ + mockedGetSpawnContentByLine.mockResolvedValueOnce([ `1${TAB}1${TAB}${output}`, ]) - mockedGetSpawContentByLine.mockResolvedValueOnce([]) - mockedGetSpawContentByLine.mockResolvedValueOnce([]) + mockedGetSpawnContentByLine.mockResolvedValueOnce([]) + mockedGetSpawnContentByLine.mockResolvedValueOnce([]) config.ignoreDestructive = FORCEIGNORE_MOCK_PATH const repoGitDiff = new RepoGitDiff(config, globalMetadata) @@ -243,11 +243,11 @@ describe(`test if repoGitDiff`, () => { it('can filter sub folders', async () => { const output = 'force-app/main/default/pages/test.page-meta.xml' - mockedGetSpawContentByLine.mockResolvedValueOnce([ + mockedGetSpawnContentByLine.mockResolvedValueOnce([ `1${TAB}1${TAB}${output}`, ]) - mockedGetSpawContentByLine.mockResolvedValueOnce([]) - mockedGetSpawContentByLine.mockResolvedValueOnce([]) + mockedGetSpawnContentByLine.mockResolvedValueOnce([]) + mockedGetSpawnContentByLine.mockResolvedValueOnce([]) config.ignore = FORCEIGNORE_MOCK_PATH const repoGitDiff = new RepoGitDiff(config, globalMetadata) const work = await repoGitDiff.getLines() @@ -262,13 +262,13 @@ describe(`test if repoGitDiff`, () => { 'force-app/account/domain/classes/Account.cls', ] - mockedGetSpawContentByLine.mockResolvedValueOnce([ + mockedGetSpawnContentByLine.mockResolvedValueOnce([ `1${TAB}1${TAB}${output[1]}`, ]) - mockedGetSpawContentByLine.mockResolvedValueOnce([ + mockedGetSpawnContentByLine.mockResolvedValueOnce([ `1${TAB}1${TAB}${output[0]}`, ]) - mockedGetSpawContentByLine.mockResolvedValueOnce([]) + mockedGetSpawnContentByLine.mockResolvedValueOnce([]) const repoGitDiff = new RepoGitDiff(config, globalMetadata) const work = await repoGitDiff.getLines() const expected: string[] = [`${ADDITION}${TAB}${output[1]}`] @@ -280,13 +280,13 @@ describe(`test if repoGitDiff`, () => { 'force-app/main/default/objects/Account/fields/TEST__c.field-meta.xml', 'force-app/main/default/objects/Account/fields/Test__c.field-meta.xml', ] - mockedGetSpawContentByLine.mockResolvedValueOnce([ + mockedGetSpawnContentByLine.mockResolvedValueOnce([ `1${TAB}1${TAB}${output[1]}`, ]) - mockedGetSpawContentByLine.mockResolvedValueOnce([ + mockedGetSpawnContentByLine.mockResolvedValueOnce([ `1${TAB}1${TAB}${output[0]}`, ]) - mockedGetSpawContentByLine.mockResolvedValueOnce([]) + mockedGetSpawnContentByLine.mockResolvedValueOnce([]) const repoGitDiff = new RepoGitDiff(config, globalMetadata) const work = await repoGitDiff.getLines() const expected: string[] = [`${ADDITION}${TAB}${output[1]}`] @@ -298,13 +298,13 @@ describe(`test if repoGitDiff`, () => { 'force-app/main/default/classes/Account.cls', 'force-app/main/default/classes/RenamedAccount.cls', ] - mockedGetSpawContentByLine.mockResolvedValueOnce([ + mockedGetSpawnContentByLine.mockResolvedValueOnce([ `1${TAB}1${TAB}${output[1]}`, ]) - mockedGetSpawContentByLine.mockResolvedValueOnce([ + mockedGetSpawnContentByLine.mockResolvedValueOnce([ `1${TAB}1${TAB}${output[0]}`, ]) - mockedGetSpawContentByLine.mockResolvedValueOnce([]) + mockedGetSpawnContentByLine.mockResolvedValueOnce([]) const repoGitDiff = new RepoGitDiff(config, globalMetadata) const work = await repoGitDiff.getLines() const expected: string[] = [ @@ -319,13 +319,13 @@ describe(`test if repoGitDiff`, () => { 'force-app/main/default/objects/Account/fields/CustomField__c.field-meta.xml', 'force-app/main/default/objects/Opportunity/fields/CustomField__c.field-meta.xml', ] - mockedGetSpawContentByLine.mockResolvedValueOnce([ + mockedGetSpawnContentByLine.mockResolvedValueOnce([ `1${TAB}1${TAB}${output[1]}`, ]) - mockedGetSpawContentByLine.mockResolvedValueOnce([ + mockedGetSpawnContentByLine.mockResolvedValueOnce([ `1${TAB}1${TAB}${output[0]}`, ]) - mockedGetSpawContentByLine.mockResolvedValueOnce([]) + mockedGetSpawnContentByLine.mockResolvedValueOnce([]) const repoGitDiff = new RepoGitDiff(config, globalMetadata) const work = await repoGitDiff.getLines() const expected: string[] = [ diff --git a/__tests__/unit/lib/utils/repoSetup.test.ts b/__tests__/unit/lib/utils/repoSetup.test.ts index ce00fb9f..4252c571 100644 --- a/__tests__/unit/lib/utils/repoSetup.test.ts +++ b/__tests__/unit/lib/utils/repoSetup.test.ts @@ -9,7 +9,7 @@ import { Config } from '../../../../src/types/config' jest.mock('../../../../src/utils/childProcessUtils') const mockedGetSpawContent = jest.mocked(getSpawnContent) -const mockedGetSpawContentByLine = jest.mocked(getSpawnContentByLine) +const mockedGetSpawnContentByLine = jest.mocked(getSpawnContentByLine) describe(`test if repoSetup`, () => { const config: Config = { @@ -93,7 +93,7 @@ describe(`test if repoSetup`, () => { // Arrange const expected = ['file/path/name.ext', 'other/file/path/name.ext'] config.repo = './' - mockedGetSpawContentByLine.mockResolvedValue(expected) + mockedGetSpawnContentByLine.mockResolvedValue(expected) // Act const repoSetup = new RepoSetup(config) diff --git a/package.json b/package.json index 6a4a70fe..dada35d4 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "test:build:local": "yarn clean ; shx rm -rf .yarn/cache node_modules ; yarn && yarn pack && yarn test", "test:mutation": "stryker run", "test:nut": "nyc mocha **/*.nut.ts", - "test:perf": "node __tests__/perf/bench.js | tee perf-result.txt", + "test:perf": "node __tests__/perf/bench.mjs | tee perf-result.txt", "test:unit": "jest", "test:unit:clear:cache": "jest --clearCache", "test:unit:coverage": "jest --coverage", diff --git a/src/utils/repoGitDiff.ts b/src/utils/repoGitDiff.ts index 864f4a09..73ff616c 100644 --- a/src/utils/repoGitDiff.ts +++ b/src/utils/repoGitDiff.ts @@ -91,17 +91,19 @@ export default class RepoGitDiff { } protected async _treatResult(lines: string[]): Promise { - const linesPerDiffType: Map = lines.reduce( - (acc: Map, line: string) => { - const idx: string = line.charAt(0) - if (!acc.has(idx)) { - acc.set(idx, []) - } - acc.get(idx)!.push(line) - return acc - }, - new Map() - ) + const renamedElements = this._getRenamedElements(lines) + + const ignoreHelper = await buildIgnoreHelper(this.config) + + return lines + .filter(Boolean) + .filter((line: string) => this._filterInternal(line, renamedElements)) + .filter((line: string) => ignoreHelper.keep(line)) + } + + protected _getRenamedElements(lines: string[]) { + const linesPerDiffType: Map = + this._spreadLinePerDiffType(lines) const AfileNames: string[] = linesPerDiffType .get(ADDITION) @@ -114,12 +116,17 @@ export default class RepoGitDiff { ) }) ?? [] - const ignoreHelper = await buildIgnoreHelper(this.config) - - return lines - .filter(Boolean) - .filter((line: string) => this._filterInternal(line, deletedRenamed)) - .filter((line: string) => ignoreHelper.keep(line)) + return deletedRenamed + } + protected _spreadLinePerDiffType(lines: string[]) { + return lines.reduce((acc: Map, line: string) => { + const idx: string = line.charAt(0) + if (!acc.has(idx)) { + acc.set(idx, []) + } + acc.get(idx)!.push(line) + return acc + }, new Map()) } protected _filterInternal(line: string, deletedRenamed: string[]): boolean { diff --git a/tsconfig.json b/tsconfig.json index 88598784..05837c86 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -12,7 +12,7 @@ "alwaysStrict": true, "noImplicitOverride": true, "noImplicitReturns": true, - "skipLibCheck": true, + "skipLibCheck": true }, "include": [ "./src/**/*",