-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #251 from inversify/test/add-e2e-bind-rule
Add e2e bind rule
- Loading branch information
Showing
17 changed files
with
214 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 4 additions & 1 deletion
5
packages/container/tools/e2e-tests/src/binding/models/BindingParameter.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
import { ConstantValueBindingParameter } from './ConstantValueBindingParameter'; | ||
import { DynamicValueBindingParameter } from './DynamicValueBindingParameter'; | ||
|
||
export type BindingParameter = ConstantValueBindingParameter; | ||
export type BindingParameter = | ||
| ConstantValueBindingParameter | ||
| DynamicValueBindingParameter; |
1 change: 1 addition & 0 deletions
1
packages/container/tools/e2e-tests/src/binding/models/BindingParameterKind.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export enum BindingParameterKind { | ||
constantValue, | ||
dynamicValue, | ||
} |
5 changes: 5 additions & 0 deletions
5
packages/container/tools/e2e-tests/src/binding/models/DynamicValueBindingParameter.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { BaseBindingParameter } from './BaseBindingParameter'; | ||
import { BindingParameterKind } from './BindingParameterKind'; | ||
|
||
export type DynamicValueBindingParameter = | ||
BaseBindingParameter<BindingParameterKind.dynamicValue>; |
10 changes: 10 additions & 0 deletions
10
packages/container/tools/e2e-tests/src/binding/parameters/bindingScope.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { defineParameterType } from '@cucumber/cucumber'; | ||
import { BindingScope, bindingScopeValues } from '@inversifyjs/core'; | ||
|
||
defineParameterType({ | ||
name: 'bindingScope', | ||
regexp: new RegExp(`"(${Object.values(bindingScopeValues).join('|')})"`), | ||
transformer: function (bindingScope: string): BindingScope { | ||
return bindingScope as BindingScope; | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
packages/container/tools/e2e-tests/src/common/parameters/stringList.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { defineParameterType } from '@cucumber/cucumber'; | ||
|
||
defineParameterType({ | ||
name: 'stringList', | ||
regexp: /("\w+"(?:(?:, "\w+")* and "\w+")?)/, | ||
transformer: function (stringList: string): string[] { | ||
return stringList | ||
.split(/ and |, /) | ||
.map((item: string): string => item.replaceAll('"', '')); | ||
}, | ||
}); |
9 changes: 9 additions & 0 deletions
9
packages/container/tools/e2e-tests/src/container/actions/setContainerGetRequest.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { InversifyWorld } from '../../common/models/InversifyWorld'; | ||
|
||
export function setContainerGetRequest( | ||
this: InversifyWorld, | ||
alias: string, | ||
result: unknown, | ||
): void { | ||
this.containerRequests.get.set(alias, result); | ||
} |
14 changes: 14 additions & 0 deletions
14
...ages/container/tools/e2e-tests/src/container/calculations/getContainerGetRequestOrFail.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { InversifyWorld } from '../../common/models/InversifyWorld'; | ||
|
||
export function getContainerGetRequestOrFail( | ||
this: InversifyWorld, | ||
alias: string, | ||
): unknown { | ||
if (!this.containerRequests.get.has(alias)) { | ||
throw new Error( | ||
`Expected "${alias}" aliased container get request not found`, | ||
); | ||
} | ||
|
||
return this.containerRequests.get.get(alias); | ||
} |
54 changes: 54 additions & 0 deletions
54
packages/container/tools/e2e-tests/src/container/step-definitions/thenDefinitions.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import assert from 'node:assert/strict'; | ||
|
||
import { Then } from '@cucumber/cucumber'; | ||
|
||
import { InversifyWorld } from '../../common/models/InversifyWorld'; | ||
import { getContainerGetRequestOrFail } from '../calculations/getContainerGetRequestOrFail'; | ||
|
||
function getValues(this: InversifyWorld, valueAliases: string[]): unknown[] { | ||
return valueAliases.map((valueAlias: string): unknown => | ||
getContainerGetRequestOrFail.bind(this)(valueAlias), | ||
); | ||
} | ||
|
||
function thenValuesAreDistinct( | ||
this: InversifyWorld, | ||
valueAliases: string[], | ||
): void { | ||
assert.ok( | ||
getValues | ||
.bind(this)(valueAliases) | ||
.every( | ||
(value: unknown, index: number, array: unknown[]): boolean => | ||
array.at(index - 1) !== value, | ||
), | ||
); | ||
} | ||
|
||
function thenValuesAreEqual( | ||
this: InversifyWorld, | ||
valueAliases: string[], | ||
): void { | ||
assert.ok( | ||
getValues | ||
.bind(this)(valueAliases) | ||
.every( | ||
(value: unknown, index: number, array: unknown[]): boolean => | ||
array.at(index - 1) === value, | ||
), | ||
); | ||
} | ||
|
||
Then<InversifyWorld>( | ||
'{stringList} values are distinct', | ||
function (valueAliases: string[]): void { | ||
thenValuesAreDistinct.bind(this)(valueAliases); | ||
}, | ||
); | ||
|
||
Then<InversifyWorld>( | ||
'{stringList} values are equal', | ||
function (valueAliases: string[]): void { | ||
thenValuesAreEqual.bind(this)(valueAliases); | ||
}, | ||
); |
32 changes: 32 additions & 0 deletions
32
packages/container/tools/e2e-tests/src/container/step-definitions/whenDefinitions.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { When } from '@cucumber/cucumber'; | ||
|
||
import { defaultAlias } from '../../common/models/defaultAlias'; | ||
import { InversifyWorld } from '../../common/models/InversifyWorld'; | ||
import { setContainerGetRequest } from '../actions/setContainerGetRequest'; | ||
import { getContainerOrFail } from '../calculations/getContainerOrFail'; | ||
|
||
function whenContainerGetsValueForService( | ||
this: InversifyWorld, | ||
serviceId: string, | ||
containerAlias?: string, | ||
valueAlias?: string, | ||
): void { | ||
const parsedContainerAlias: string = containerAlias ?? defaultAlias; | ||
const parsedValueAlias: string = valueAlias ?? defaultAlias; | ||
|
||
setContainerGetRequest.bind(this)( | ||
parsedValueAlias, | ||
getContainerOrFail.bind(this)(parsedContainerAlias).get(serviceId), | ||
); | ||
} | ||
|
||
When<InversifyWorld>( | ||
'container gets a {string} value for service {string}', | ||
function (valueAlias: string, serviceId: string): void { | ||
whenContainerGetsValueForService.bind(this)( | ||
serviceId, | ||
undefined, | ||
valueAlias, | ||
); | ||
}, | ||
); |
This file was deleted.
Oops, something went wrong.