Skip to content

Add environment name param #355

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ See the [docs](https://octomind.dev/docs) for more details.
url: <publicly accessible url to your deployment>
token: ${{ secrets.AUTOMAGICALLY_TOKEN }}
testTargetId: <your testTargetId that you also get from us>
blocking: <if your pipeline should block until all tests have passed, defaults to false>
environmentName: <environment name that your test cases should run against. optional,
will use the "default" environment otherwise.>
blocking: <if your pipeline should block until all tests have passed, optional, defaults to false>
```

By default the task will run a maximum duration of 2 hours before it will fail with a timeout.
Expand All @@ -28,6 +30,8 @@ By default the task will run a maximum duration of 2 hours before it will fail w

- 2023-07-23: Added requirement for setting `testTargetId` to enable v2 API
- 2024-10-18: Added blocking parameter to allow blocking your pipeline until all tests have passed.
- 2024-10-30: Added environment name parameter to allow running your tests against a specified environment, uses the
default environment if not specified.

## Publishing notes

Expand Down
16 changes: 2 additions & 14 deletions automagicallyexecute/src/executeAutomagically.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,9 @@ export const executeAutomagically = async ({
maximumPollingTimeInMilliseconds?: number
} = {}): Promise<void> => {
const url = getInputRequired('url')
if (!url) {
setResult(TaskResult.Failed, 'URL is required')
return
}

const token = getInputRequired('token')
if (!token) {
setResult(TaskResult.Failed, 'token is required')
return
}

const testTargetId = getInputRequired('testTargetId')
if (!testTargetId) {
setResult(TaskResult.Failed, 'testTargetId is required')
return
}
const environmentName = getInput('environmentName')

const blocking = getBoolInput('blocking')
// https://learn.microsoft.com/en-us/azure/devops/pipelines/build/variables
Expand Down Expand Up @@ -101,6 +88,7 @@ export const executeAutomagically = async ({
body: JSON.stringify({
url,
testTargetId,
environmentName,
context: {
source: 'azureDevOps',
accessToken,
Expand Down
9 changes: 8 additions & 1 deletion automagicallyexecute/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"author": "OctoMind GmbH",
"version": {
"Major": 2,
"Minor": 1,
"Minor": 2,
"Patch": 0
},
"instanceNameFormat": "Execute Automagically",
Expand Down Expand Up @@ -40,6 +40,13 @@
"label": "Blocking",
"required": false,
"helpMarkDown": "If your pipeline should wait until all tests are green, default is false"
},
{
"name": "environmentName",
"type": "string",
"label": "Environment Name",
"required": false,
"helpMarkDown": "(Optional) which environment your tests should be executed against. Will use the 'default' environment if not defined"
}
],
"execution": {
Expand Down
26 changes: 25 additions & 1 deletion automagicallyexecute/tests/executeAutomagically.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,30 @@ describe(executeAutomagically.name, () => {
)
})

it('includes environment name if defined', async () => {
const environmentName = 'staging'
vi.mocked(getInput).mockReturnValue(environmentName)

await executeAutomagically()

expect(fetchJson).toHaveBeenCalledWith(
expect.objectContaining({
method: 'POST'
})
)

const sentBody = JSON.parse(
vi.mocked(fetchJson).mock.calls[0][0].body as string
)

expect(sentBody).toEqual(
expect.objectContaining({
environmentName
})
)
expect(getInput).toHaveBeenCalledWith('environmentName')
})

it("executes and DOESN'T wait if it's not blocking", async () => {
await executeAutomagically()

Expand Down Expand Up @@ -65,7 +89,7 @@ describe(executeAutomagically.name, () => {
method: 'POST'
})
)
expect(fetchJson).toHaveBeenCalledTimes(5)
expect(fetchJson).toHaveBeenCalledTimes(4)
})

it('sets to failed if a request throws', async () => {
Expand Down
3 changes: 2 additions & 1 deletion automagicallyexecute/vite.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {defineConfig} from 'vitest/config'
export default defineConfig({
test: {
globals: true,
environment: 'node'
environment: 'node',
mockReset: true,
}
})
2 changes: 1 addition & 1 deletion vss-extension.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"manifestVersion": 1,
"id": "automagically-execute-task",
"name": "octomind automagically execute",
"version": "2.1.0",
"version": "2.2.0",
"publisher": "octomind",
"targets": [
{
Expand Down