Skip to content

Commit 710a118

Browse files
committed
test fixup
1 parent f1a6898 commit 710a118

File tree

4 files changed

+16
-6
lines changed

4 files changed

+16
-6
lines changed

packages/core/src/test/lambda/vue/remoteInvoke/invokeLambda.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { FakeExtensionContext } from '../../../fakeExtensionContext'
2121
import * as samCliRemoteTestEvent from '../../../../shared/sam/cli/samCliRemoteTestEvent'
2222
import { TestEventsOperation, SamCliRemoteTestEventsParameters } from '../../../../shared/sam/cli/samCliRemoteTestEvent'
2323
import { assertLogsContain } from '../../../globalSetup.test'
24+
import { createResponse } from '../../../testUtil'
2425

2526
describe('RemoteInvokeWebview', () => {
2627
let outputChannel: vscode.OutputChannel
@@ -394,7 +395,7 @@ describe('RemoteInvokeWebview', () => {
394395
createQuickPickStub.returns({})
395396
promptUserStub.resolves([{ label: 'testEvent', filename: 'testEvent.json' }])
396397
verifySinglePickerOutputStub.returns({ label: 'testEvent', filename: 'testEvent.json' })
397-
httpFetcherStub.resolves(mockSampleContent)
398+
httpFetcherStub.resolves(createResponse(mockSampleContent))
398399

399400
const result = await remoteInvokeWebview.getSamplePayload()
400401

packages/core/src/test/lambda/vue/samInvokeBackend.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import { SamDebugConfigProvider } from '../../../shared/sam/debugger/awsSamDebug
2828
import sinon from 'sinon'
2929
import * as nls from 'vscode-nls'
3030
import { assertLogsContain } from '../../../test/globalSetup.test'
31+
import { createResponse } from '../../testUtil'
3132

3233
const localize = nls.loadMessageBundle()
3334

@@ -166,7 +167,7 @@ describe('SamInvokeWebview', () => {
166167
createQuickPickStub.returns({})
167168
promptUserStub.resolves([{ label: 'testEvent', filename: 'testEvent.json' }])
168169
verifySinglePickerOutputStub.returns({ label: 'testEvent', filename: 'testEvent.json' })
169-
httpFetcherStub.resolves(mockSampleContent)
170+
httpFetcherStub.resolves(createResponse(mockSampleContent))
170171

171172
const result = await samInvokeWebview.getSamplePayload()
172173

packages/core/src/test/shared/resourceFetcher/httpResourceFetcher.test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import assert from 'assert'
77
import { HttpResourceFetcher, getPropertyFromJsonUrl } from '../../../shared/resourcefetcher/httpResourceFetcher'
88
import { stub } from '../../utilities/stubber'
9+
import { createResponse } from '../../testUtil'
910

1011
describe('getPropertyFromJsonUrl', function () {
1112
const dummyUrl = 'url'
@@ -19,18 +20,18 @@ describe('getPropertyFromJsonUrl', function () {
1920

2021
it('undefined if resource is not JSON', async function () {
2122
const mockFetcher = stub(HttpResourceFetcher)
22-
mockFetcher.get.resolves('foo' as any) // horrible hack: this works without the declaration but the language server latches onto this using a FetcherResult return type
23+
mockFetcher.get.resolves(createResponse('foo'))
2324
assert.strictEqual(await getPropertyFromJsonUrl(dummyUrl, dummyProperty, mockFetcher), undefined)
2425
})
2526

2627
it('undefined if property is not present', async function () {
2728
const mockFetcher = stub(HttpResourceFetcher)
28-
mockFetcher.get.resolves('{"foo": "bar"}' as any)
29+
mockFetcher.get.resolves(createResponse('{"foo": "bar"}'))
2930
assert.strictEqual(await getPropertyFromJsonUrl(dummyUrl, dummyProperty, mockFetcher), undefined)
3031
})
3132
it('returns value if property is present', async function () {
3233
const mockFetcher = stub(HttpResourceFetcher)
33-
mockFetcher.get.resolves('{"property": "111"}' as any)
34+
mockFetcher.get.resolves(createResponse('{"property": "111"}'))
3435
mockFetcher.getNewETagContent.resolves({ content: 'foo', eTag: '' })
3536
const value = await getPropertyFromJsonUrl(dummyUrl, dummyProperty, mockFetcher)
3637
assert.strictEqual(value, '111')

packages/core/src/test/testUtil.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { DeclaredCommand } from '../shared/vscode/commands2'
1818
import { mkdirSync, existsSync } from 'fs' // eslint-disable-line no-restricted-imports
1919
import { randomBytes } from 'crypto'
2020
import request from '../shared/request'
21-
import { stub } from 'sinon'
21+
import { createStubInstance, stub } from 'sinon'
2222

2323
const testTempDirs: string[] = []
2424

@@ -634,3 +634,10 @@ export function getFetchStubWithResponse(response: Partial<Response>) {
634634
export function copyEnv(): NodeJS.ProcessEnv {
635635
return { ...process.env }
636636
}
637+
638+
// Returns a stubbed response object
639+
export function createResponse(text: string): Response {
640+
const responseStub = createStubInstance(Response)
641+
responseStub.text.resolves(text)
642+
return responseStub
643+
}

0 commit comments

Comments
 (0)