Skip to content

Commit 902c4e8

Browse files
authored
fix: tests call openExternal() without stubbing #3813
Problem: rejected promise not handled within 1 second: Error: No return value has been set. Use `getOpenExternalStub().resolves` to set one. stack trace: Error: No return value has been set. Use `getOpenExternalStub().resolves` to set one. at Context.<anonymous> (/Users/runner/work/aws-toolkit-vscode/aws-toolkit-vscode/src/test/globalSetup.test.ts:74:13) at Generator.next (<anonymous>) at /Users/runner/work/aws-toolkit-vscode/aws-toolkit-vscode/dist/src/test/globalSetup.test.js:35:71 Solution: - Fail in `afterEach` (this is much more useful than a silent message in the test log). ``` 1) "after each" hook: afterEach for "shows an option to go to documentation when no connections are available": Error: Test called openExternal(....) without first configuring getOpenExternalStub().resolves(). ``` - Fix the tests.
1 parent 8893f0d commit 902c4e8

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

src/test/apprunner/wizards/codeRepositoryWizard.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ describe('createConnectionPrompter', function () {
117117
})
118118

119119
it('shows an option to go to documentation when no connections are available', async function () {
120+
getOpenExternalStub().resolves(true)
120121
const tester = makeTester([])
121122
tester.assertItems(['No connections found'])
122123
tester.acceptItem('No connections found')

src/test/globalSetup.test.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,7 @@ export const mochaHooks = {
7070
// to be minimally intrusive and as close to the real thing as possible.
7171
globalSandbox.replace(vscode, 'window', getTestWindow())
7272
openExternalStub = globalSandbox.stub(vscode.env, 'openExternal')
73-
openExternalStub.rejects(
74-
new Error('No return value has been set. Use `getOpenExternalStub().resolves` to set one.')
75-
)
73+
openExternalStub.returns(undefined as any) // Detected in afterEach() below.
7674

7775
// Wraps the test function to bubble up errors that occurred in events from `TestWindow`
7876
if (this.currentTest?.fn) {
@@ -88,6 +86,14 @@ export const mochaHooks = {
8886
await testUtil.closeAllEditors()
8987
},
9088
afterEach(this: Mocha.Context) {
89+
if (openExternalStub.called && openExternalStub.returned(sinon.match.typeOf('undefined'))) {
90+
throw new Error(
91+
`Test called openExternal(${
92+
getOpenExternalStub().args[0]
93+
}) without first configuring getOpenExternalStub().resolves().`
94+
)
95+
}
96+
9197
// Prevent other tests from using the same TestLogger instance
9298
teardownTestLogger(this.currentTest?.fullTitle() as string)
9399
testLogger = undefined

src/test/shared/ui/prompters/roles.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ describe('createRolePrompter', function () {
7575
})
7676

7777
it('can open documentation', async function () {
78+
getOpenExternalStub().resolves(true)
7879
tester.pressButton('View Toolkit Documentation')
7980
tester.addCallback(() => assert.ok(getOpenExternalStub().calledWith(helpUri)))
8081
tester.hide()

0 commit comments

Comments
 (0)