Skip to content

Commit 2efa3ec

Browse files
fix another broken test
- Removed unnecessary fake clock. I guess this existed for historical reasons but is not needed anymore - Refactored one of the methods so that it could be stubbed Signed-off-by: nkomonen-amazon <[email protected]>
1 parent 6bcf269 commit 2efa3ec

File tree

2 files changed

+8
-11
lines changed

2 files changed

+8
-11
lines changed

packages/core/src/auth/sso/ssoAccessTokenProvider.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,15 @@ export abstract class SsoAccessTokenProvider {
101101
* Sometimes we get many calls at once and this
102102
* can trigger redundant disk reads, or token refreshes.
103103
* We debounce to avoid this.
104+
*
105+
* NOTE: The property {@link getTokenDebounced()} does not work with being stubbed for tests, so
106+
* this redundant function was created to work around that.
104107
*/
105-
public getToken = debounce(this._getToken.bind(this), 100)
106-
public async _getToken(): Promise<SsoToken | undefined> {
108+
public async getToken(): Promise<SsoToken | undefined> {
109+
return this.getTokenDebounced()
110+
}
111+
private getTokenDebounced = debounce(this._getToken.bind(this), 100)
112+
private async _getToken(): Promise<SsoToken | undefined> {
107113
const data = await this.cache.token.load(this.tokenCacheKey)
108114
SsoAccessTokenProvider.logIfChanged(
109115
indent(

packages/core/src/test/credentials/provider/sharedCredentialsProvider.test.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,11 @@
44
*/
55

66
import assert from 'assert'
7-
import * as FakeTimers from '@sinonjs/fake-timers'
87
import * as sinon from 'sinon'
98
import { SharedCredentialsProvider } from '../../../auth/providers/sharedCredentialsProvider'
109
import { stripUndefined } from '../../../shared/utilities/collectionUtils'
1110
import * as process from '@aws-sdk/credential-provider-process'
1211
import { ParsedIniData } from '@smithy/shared-ini-file-loader'
13-
import { installFakeClock } from '../../testUtil'
1412
import { SsoClient } from '../../../auth/sso/clients'
1513
import { stub } from '../../utilities/stubber'
1614
import { SsoAccessTokenProvider } from '../../../auth/sso/ssoAccessTokenProvider'
@@ -19,20 +17,13 @@ import { createTestSections } from '../testUtil'
1917
const missingPropertiesFragment = 'missing properties'
2018

2119
describe('SharedCredentialsProvider', async function () {
22-
let clock: FakeTimers.InstalledClock
2320
let sandbox: sinon.SinonSandbox
2421

2522
before(function () {
2623
sandbox = sinon.createSandbox()
27-
clock = installFakeClock()
28-
})
29-
30-
after(function () {
31-
clock.uninstall()
3224
})
3325

3426
afterEach(function () {
35-
clock.reset()
3627
sandbox.restore()
3728
})
3829

0 commit comments

Comments
 (0)