Skip to content

Commit

Permalink
update to using existing helper fn for waiting and timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
vicheey committed Nov 19, 2024
1 parent 8ea3827 commit ec1ca94
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 11 deletions.
5 changes: 3 additions & 2 deletions packages/core/src/test/shared/ui/sam/ecrPrompter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import * as SamUtilsModule from '../../../../shared/sam/utils'
import * as ButtonsModule from '../../../../shared/ui/buttons'
import { createEcrPrompter } from '../../../../shared/ui/sam/ecrPrompter'
import { intoCollection } from '../../../../shared/utilities/collectionUtils'
import { sleep } from '../../../../shared/utilities/timeoutUtils'

describe('createEcrPrompter', () => {
let sandbox: sinon.SinonSandbox
Expand Down Expand Up @@ -76,7 +77,7 @@ describe('createEcrPrompter', () => {

// Act
const prompter = createEcrPrompter(ecrClient, mementoRootKey)
await new Promise((f) => setTimeout(f, 50))
await sleep(50)

// Assert
assert.ok(createCommonButtonsStub.calledOnce)
Expand All @@ -103,7 +104,7 @@ describe('createEcrPrompter', () => {

// Act
const prompter = createEcrPrompter(ecrClient, mementoRootKey)
await new Promise((f) => setTimeout(f, 50))
await sleep(50)

// Assert
assert.ok(createCommonButtonsStub.calledOnce)
Expand Down
5 changes: 3 additions & 2 deletions packages/core/src/test/shared/ui/sam/stackPrompter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { DefaultCloudFormationClient } from '../../../../shared/clients/cloudFor
import { samSyncUrl } from '../../../../shared/constants'
import { createStackPrompter } from '../../../../shared/ui/sam/stackPrompter'
import { intoCollection } from '../../../../shared/utilities/collectionUtils'
import { sleep } from '../../../../shared/utilities/timeoutUtils'

describe('createStackPrompter', () => {
let sandbox: sinon.SinonSandbox
Expand Down Expand Up @@ -81,7 +82,7 @@ describe('createStackPrompter', () => {

// Act
const prompter = createStackPrompter(cfnClient, mementoRootKey, samSyncUrl)
await new Promise((f) => setTimeout(f, 50))
await sleep(50)

// Assert
assert.ok(createCommonButtonsStub.calledOnce)
Expand All @@ -108,7 +109,7 @@ describe('createStackPrompter', () => {

// Act
const prompter = createStackPrompter(cfnClient, mementoRootKey, samSyncUrl)
await new Promise((f) => setTimeout(f, 50))
await sleep(50)

// Assert
assert.ok(createCommonButtonsStub.calledOnce)
Expand Down
9 changes: 2 additions & 7 deletions packages/core/src/test/shared/wizards/prompterTester.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import assert from 'assert'
import { TestInputBox, TestQuickPick } from '../vscode/quickInput'
import { getTestWindow, TestWindow } from '../vscode/window'
import { waitUntil } from '../../../shared/utilities/timeoutUtils'

interface PrompterTesterConfig {
testWindow?: TestWindow
Expand Down Expand Up @@ -111,13 +112,7 @@ export class PrompterTester {
}

try {
const timeoutPromise = new Promise<never>((_, reject) => {
setTimeout(() => {
reject(new Error(`Handler for "${input.title}" exceeded ${this.handlerTimout}ms timeout`))
}, this.handlerTimout)
})

await Promise.race([handler(input), timeoutPromise])
await waitUntil(handler(input), { timeout: this.handlerTimout, interval: 50 })
} catch (e) {
// clean up UI on callback function early exit (e.g assertion failure)
await input.dispose()
Expand Down

0 comments on commit ec1ca94

Please sign in to comment.