-
-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: create LWC handler to segregate
isProcessable
algorithm
- Loading branch information
Showing
5 changed files
with
113 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
'use strict' | ||
const LwcHandler = require('../../../../src/service/lwcHandler') | ||
const { copyFiles, readDir } = require('../../../../src/utils/fsHelper') | ||
const { | ||
ADDITION, | ||
DELETION, | ||
MODIFICATION, | ||
} = require('../../../../src/utils/gitConstants') | ||
|
||
jest.mock('../../../../src/utils/fsHelper') | ||
|
||
readDir.mockImplementationOnce(() => Promise.resolve([])) | ||
|
||
const objectType = 'lwc' | ||
const element = 'component' | ||
const basePath = `force-app/main/default/${objectType}` | ||
const entityPath = `${basePath}/${element}/${element}.js` | ||
const xmlName = 'LightningComponentBundle' | ||
let work | ||
beforeEach(() => { | ||
jest.clearAllMocks() | ||
work = { | ||
config: { output: '', repo: '', generateDelta: true }, | ||
diffs: { package: new Map(), destructiveChanges: new Map() }, | ||
} | ||
}) | ||
|
||
describe('lwcHandler', () => { | ||
let globalMetadata | ||
beforeAll(async () => { | ||
// eslint-disable-next-line no-undef | ||
globalMetadata = await getGlobalMetadata() | ||
}) | ||
describe('when the line should not be processed', () => { | ||
it.each([`${basePath}/.eslintrc.json`, `${basePath}/jsconfig.json`])( | ||
'does not handle the line', | ||
async entityPath => { | ||
// Arrange | ||
const sut = new LwcHandler( | ||
`${ADDITION} ${entityPath}`, | ||
objectType, | ||
work, | ||
globalMetadata | ||
) | ||
|
||
// Act | ||
await sut.handle() | ||
|
||
// Assert | ||
expect(work.diffs.package.size).toBe(0) | ||
expect(copyFiles).not.toHaveBeenCalled() | ||
} | ||
) | ||
}) | ||
|
||
describe('when the line should be processed', () => { | ||
it.each([ADDITION, MODIFICATION])( | ||
'handles the line for "%s" type change', | ||
async changeType => { | ||
// Arrange | ||
const sut = new LwcHandler( | ||
`${changeType} ${entityPath}`, | ||
objectType, | ||
work, | ||
globalMetadata | ||
) | ||
|
||
// Act | ||
await sut.handle() | ||
|
||
// Assert | ||
expect(work.diffs.package.get(xmlName)).toEqual(new Set([element])) | ||
expect(copyFiles).toHaveBeenCalled() | ||
} | ||
) | ||
|
||
it('handles the line for "D" type change', async () => { | ||
// Arrange | ||
const sut = new LwcHandler( | ||
`${DELETION} ${entityPath}`, | ||
objectType, | ||
work, | ||
globalMetadata | ||
) | ||
|
||
// Act | ||
await sut.handle() | ||
|
||
// Assert | ||
expect(work.diffs.destructiveChanges.get(xmlName)).toEqual( | ||
new Set([element]) | ||
) | ||
expect(copyFiles).not.toHaveBeenCalled() | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
'use strict' | ||
const InResourceHandler = require('./inResourceHandler') | ||
const { parse, sep } = require('path') | ||
|
||
class LwcHandler extends InResourceHandler { | ||
_isProcessable() { | ||
const parentFolder = parse(this.line).dir.split(sep).pop() | ||
|
||
return parentFolder !== this.type | ||
} | ||
} | ||
|
||
module.exports = LwcHandler |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters