Skip to content

Commit

Permalink
fix: typescript default exported value (#706)
Browse files Browse the repository at this point in the history
Co-authored-by: Paweł Idczak <[email protected]>
  • Loading branch information
scolladon and pawel-id authored Oct 9, 2023
1 parent 44d7e6a commit 1a4c518
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 7 deletions.
1 change: 1 addition & 0 deletions .github/linters/.cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@
"predicat",
"quotepath",
"recentsha",
"repogitdiff",
"rulesets",
"samlssoconfig",
"samlssoconfigs",
Expand Down
94 changes: 94 additions & 0 deletions __tests__/functional/main.test.ts
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'])
})
})
})
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
"nyc": "^15.1.0",
"prettier": "^3.0.3",
"shx": "^0.3.4",
"sinon": "^16.0.0",
"sinon": "^16.1.0",
"ts-jest": "^29.1.1",
"ts-node": "^10.9.1",
"typescript": "^5.2.2",
Expand Down
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ const sgd = async (config: Config): Promise<Work> => {
return work
}

export default sgd
export = sgd
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9725,7 +9725,7 @@ __metadata:
nyc: ^15.1.0
prettier: ^3.0.3
shx: ^0.3.4
sinon: ^16.0.0
sinon: ^16.1.0
ts-jest: ^29.1.1
ts-node: ^10.9.1
typescript: ^5.2.2
Expand Down Expand Up @@ -9817,17 +9817,17 @@ __metadata:
languageName: node
linkType: hard

"sinon@npm:^16.0.0":
version: 16.0.0
resolution: "sinon@npm:16.0.0"
"sinon@npm:^16.1.0":
version: 16.1.0
resolution: "sinon@npm:16.1.0"
dependencies:
"@sinonjs/commons": ^3.0.0
"@sinonjs/fake-timers": ^10.3.0
"@sinonjs/samsam": ^8.0.0
diff: ^5.1.0
nise: ^5.1.4
supports-color: ^7.2.0
checksum: fbcad39d1610c669bb37ce2d325f2ac666ff5187935d09d1e757e11c50d07b8556b7dfa322eb38ad6ace8a18912224cc502e990779bc3d0954244a1ae8391984
checksum: b3f910e9b3d28f1241b28ac9d384f45c673b64ecfabf7ca2b94c964036118bd4166a2315f2ec2379a85745a7d4840384514aca416bbf189508a9d7fb55b9d5a8
languageName: node
linkType: hard

Expand Down

0 comments on commit 1a4c518

Please sign in to comment.