-
-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: typescript default exported value (#706)
Co-authored-by: Paweł Idczak <[email protected]>
- Loading branch information
Showing
5 changed files
with
102 additions
and
7 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,94 @@ | ||
;`use strict` | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
const sgd = require('../../src/main') | ||
import { expect, jest, describe, it } from '@jest/globals' | ||
|
||
const mockValidateConfig = jest.fn() | ||
jest.mock('../../src/utils/cliHelper', () => { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
const actualModule: any = jest.requireActual('../../src/utils/cliHelper') | ||
return jest.fn().mockImplementation(function () { | ||
return { | ||
...actualModule, | ||
validateConfig: mockValidateConfig, | ||
} | ||
}) | ||
}) | ||
|
||
const mockGetLines = jest.fn() | ||
jest.mock('../../src/utils/repoGitDiff', () => { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
const actualModule: any = jest.requireActual('../../src/utils/repoGitDiff') | ||
return jest.fn().mockImplementation(function () { | ||
return { | ||
...actualModule, | ||
getLines: mockGetLines, | ||
} | ||
}) | ||
}) | ||
|
||
const mockProcess = jest.fn() | ||
jest.mock('../../src/service/diffLineInterpreter', () => { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
const actualModule: any = jest.requireActual( | ||
'../../src/service/diffLineInterpreter' | ||
) | ||
return jest.fn().mockImplementation(function () { | ||
return { | ||
...actualModule, | ||
process: mockProcess, | ||
} | ||
}) | ||
}) | ||
|
||
describe('external library inclusion', () => { | ||
describe('when configuration is not valid', () => { | ||
beforeEach(() => { | ||
// Arrange | ||
mockValidateConfig.mockImplementationOnce(() => | ||
Promise.reject(new Error('test')) | ||
) | ||
}) | ||
|
||
it('it should throw', async () => { | ||
// Arrange | ||
expect.assertions(1) | ||
|
||
// Act | ||
try { | ||
await sgd({}) | ||
} catch (error) { | ||
// Assert | ||
expect((error as Error).message).toEqual('test') | ||
} | ||
}) | ||
}) | ||
|
||
describe('when there are no changes', () => { | ||
beforeEach(() => { | ||
// Arrange | ||
mockGetLines.mockImplementationOnce(() => Promise.resolve([])) | ||
}) | ||
it('it should not process lines', async () => { | ||
// Act | ||
await sgd({}) | ||
|
||
// Assert | ||
expect(mockProcess).toBeCalledWith([]) | ||
}) | ||
}) | ||
|
||
describe('when there are changes', () => { | ||
beforeEach(() => { | ||
// Arrange | ||
mockGetLines.mockImplementationOnce(() => Promise.resolve(['line'])) | ||
}) | ||
it('it should process those lines', async () => { | ||
// Act | ||
await sgd({}) | ||
|
||
// Assert | ||
expect(mockProcess).toBeCalledWith(['line']) | ||
}) | ||
}) | ||
}) |
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 |
---|---|---|
|
@@ -27,4 +27,4 @@ const sgd = async (config: Config): Promise<Work> => { | |
return work | ||
} | ||
|
||
export default sgd | ||
export = sgd |
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