Skip to content

Commit 410bcaf

Browse files
Refactor: test CollectionUtils -> general collectionUtils. (#3535)
* (rebase): remove ec2 changes from this branch * remove TODO comment Co-authored-by: JadenSimon <[email protected]> * delete final remnants of ec2 * delete old file --------- Co-authored-by: JadenSimon <[email protected]>
1 parent 3670094 commit 410bcaf

File tree

18 files changed

+37
-44
lines changed

18 files changed

+37
-44
lines changed

src/shared/utilities/collectionUtils.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,3 +488,24 @@ export async function* joinAll<T>(iterable: AsyncIterable<AsyncIterable<T>>): As
488488
}
489489
} while (!iterables.completed)
490490
}
491+
492+
export async function* asyncGenerator<T>(items: T[]): AsyncIterableIterator<T> {
493+
yield* items
494+
}
495+
496+
export function intoCollection<T>(arr: T[]): AsyncCollection<T> {
497+
return toCollection(async function* () {
498+
yield* arr
499+
})
500+
}
501+
502+
export function createCollectionFromPages<T>(...pages: T[]): AsyncCollection<T> {
503+
return toCollection(async function* () {
504+
for (let i = 0; i < pages.length - 1; i++) {
505+
yield pages[i]
506+
}
507+
508+
return pages[pages.length - 1]
509+
})
510+
}
511+

src/test/apigateway/explorer/apiGatewayNodes.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
assertNodeListOnlyHasErrorNode,
99
assertNodeListOnlyHasPlaceholderNode,
1010
} from '../../utilities/explorerNodeAssertions'
11-
import { asyncGenerator } from '../../utilities/collectionUtils'
11+
import { asyncGenerator } from '../../../shared/utilities/collectionUtils'
1212
import { ApiGatewayNode } from '../../../apigateway/explorer/apiGatewayNodes'
1313
import { RestApiNode } from '../../../apigateway/explorer/apiNodes'
1414
import { DefaultApiGatewayClient } from '../../../shared/clients/apiGatewayClient'

src/test/apprunner/explorer/apprunnerServiceNode.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { AppRunnerNode } from '../../../apprunner/explorer/apprunnerNode'
1111
import { AppRunnerServiceNode } from '../../../apprunner/explorer/apprunnerServiceNode'
1212
import { DefaultAppRunnerClient } from '../../../shared/clients/apprunnerClient'
1313
import { DefaultCloudWatchLogsClient } from '../../../shared/clients/cloudWatchLogsClient'
14-
import { asyncGenerator } from '../../utilities/collectionUtils'
14+
import { asyncGenerator } from '../../../shared/utilities/collectionUtils'
1515
import { AWSTreeNodeBase } from '../../../shared/treeview/nodes/awsTreeNodeBase'
1616
import { stub } from '../../utilities/stubber'
1717
import { getLabel } from '../../../shared/treeview/utils'

src/test/cloudWatchLogs/explorer/cloudWatchLogsNode.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import * as assert from 'assert'
77
import { contextValueCloudwatchLog, LogGroupNode } from '../../../cloudWatchLogs/explorer/logGroupNode'
88
import { CloudWatchLogsNode } from '../../../cloudWatchLogs/explorer/cloudWatchLogsNode'
9-
import { asyncGenerator } from '../../utilities/collectionUtils'
9+
import { asyncGenerator } from '../../../shared/utilities/collectionUtils'
1010
import {
1111
assertNodeListOnlyHasErrorNode,
1212
assertNodeListOnlyHasPlaceholderNode,

src/test/codecatalyst/wizards/selectResource.test.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,10 @@
66
import { instance, when } from 'ts-mockito'
77
import { createOrgPrompter, createProjectPrompter } from '../../../codecatalyst/wizards/selectResource'
88
import { CodeCatalystOrg, CodeCatalystClient, CodeCatalystProject } from '../../../shared/clients/codecatalystClient'
9-
import { AsyncCollection, toCollection } from '../../../shared/utilities/asyncCollection'
9+
import { intoCollection } from '../../../shared/utilities/collectionUtils'
1010
import { createQuickPickPrompterTester } from '../../shared/ui/testUtils'
1111
import { mock } from '../../utilities/mockito'
1212

13-
// TODO: move to test utils
14-
function intoCollection<T>(arr: T[]): AsyncCollection<T> {
15-
return toCollection(async function* () {
16-
yield* arr
17-
})
18-
}
19-
2013
describe('Prompts', function () {
2114
let orgs: CodeCatalystOrg[]
2215
let projects: CodeCatalystProject[]

src/test/dynamicResources/explorer/moreResourcesNode.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { ResourcesNode } from '../../../dynamicResources/explorer/nodes/resource
99
import { ResourceTypeNode } from '../../../dynamicResources/explorer/nodes/resourceTypeNode'
1010
import { CloudFormationClient } from '../../../shared/clients/cloudFormationClient'
1111
import { assertNodeListOnlyHasPlaceholderNode } from '../../utilities/explorerNodeAssertions'
12-
import { asyncGenerator } from '../../utilities/collectionUtils'
12+
import { asyncGenerator } from '../../../shared/utilities/collectionUtils'
1313
import { mock, instance, when } from 'ts-mockito'
1414
import { CloudFormation } from 'aws-sdk'
1515
import { CloudControlClient } from '../../../shared/clients/cloudControlClient'

src/test/ecs/model.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import { Cluster, Container, Service } from '../../ecs/model'
77
import { DefaultEcsClient } from '../../shared/clients/ecsClient'
88
import { assertChildren, assertTreeItem } from '../shared/treeview/testUtil'
9-
import { createCollectionFromPages } from '../utilities/collectionUtils'
9+
import { createCollectionFromPages } from '../../shared/utilities/collectionUtils'
1010
import { stub } from '../utilities/stubber'
1111

1212
const clusterData = {

src/test/eventSchemas/commands/searchSchemas.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { Schemas } from 'aws-sdk'
99
import * as sinon from 'sinon'
1010
import { SchemasNode } from '../../../eventSchemas/explorer/schemasNode'
1111
import { getTabSizeSetting } from '../../../shared/utilities/editorUtilities'
12-
import { asyncGenerator } from '../../utilities/collectionUtils'
12+
import { asyncGenerator } from '../../../shared/utilities/collectionUtils'
1313

1414
import { MockOutputChannel } from '../../mockOutputChannel'
1515
import {

src/test/eventSchemas/explorer/registryItemNode.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
assertNodeListOnlyHasErrorNode,
1818
assertNodeListOnlyHasPlaceholderNode,
1919
} from '../../utilities/explorerNodeAssertions'
20-
import { asyncGenerator } from '../../utilities/collectionUtils'
20+
import { asyncGenerator } from '../../../shared/utilities/collectionUtils'
2121
import { getIcon } from '../../../shared/icons'
2222
import { stub } from '../../utilities/stubber'
2323

src/test/eventSchemas/providers/schemasDataProvider.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
SchemasDataProvider,
1111
} from '../../../eventSchemas/providers/schemasDataProvider'
1212
import { DefaultSchemaClient } from '../../../shared/clients/schemaClient'
13-
import { asyncGenerator } from '../../utilities/collectionUtils'
13+
import { asyncGenerator } from '../../../shared/utilities/collectionUtils'
1414
import { stub } from '../../utilities/stubber'
1515

1616
describe('schemasDataProvider', function () {

0 commit comments

Comments
 (0)