-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add dynamic test execution data configuration (#374)
* Add tests * Add integration test * Disable debug * Fix test * Fix test
- Loading branch information
Showing
10 changed files
with
247 additions
and
39 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { expect } from "chai"; | ||
import path from "node:path"; | ||
import { getOrCall } from "./functions"; | ||
|
||
describe(path.relative(process.cwd(), __filename), () => { | ||
describe(getOrCall.name, () => { | ||
it("returns unwrapped values", async () => { | ||
expect(await getOrCall("hello")).to.eq("hello"); | ||
}); | ||
|
||
it("resolves sync callbacks", async () => { | ||
expect(await getOrCall(() => 5)).to.eq(5); | ||
}); | ||
|
||
it("resolves async callbacks", async () => { | ||
expect( | ||
await getOrCall(async () => { | ||
return new Promise((resolve) => { | ||
resolve(5); | ||
}); | ||
}) | ||
).to.eq(5); | ||
}); | ||
}); | ||
}); |
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,20 @@ | ||
import { MaybeFunction } from "../types/util"; | ||
|
||
/** | ||
* If the value is a function, evaluates it and returns the result. Otherwise, the value will be | ||
* returned immediately. | ||
* | ||
* @param value - the value | ||
* @returns the value or the callback result | ||
*/ | ||
export async function getOrCall<T>(value: MaybeFunction<T>): Promise<T> { | ||
// See https://github.com/microsoft/TypeScript/issues/37663#issuecomment-1081610403 | ||
if (isFunction(value)) { | ||
return await value(); | ||
} | ||
return value; | ||
} | ||
|
||
function isFunction<T extends (...args: unknown[]) => unknown>(value: unknown): value is T { | ||
return typeof value === "function"; | ||
} |
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,162 @@ | ||
import { expect } from "chai"; | ||
import path from "path"; | ||
import process from "process"; | ||
import { dedent } from "../../src/util/dedent"; | ||
import { LOCAL_SERVER } from "../server-config"; | ||
import { runCypress, setupCypressProject } from "../sh"; | ||
import { getIntegrationClient } from "./clients"; | ||
import { getCreatedTestExecutionIssueKey } from "./util"; | ||
|
||
// ============================================================================================== // | ||
// https://github.com/Qytera-Gmbh/cypress-xray-plugin/issues/359 | ||
// ============================================================================================== // | ||
|
||
describe.only(path.relative(process.cwd(), __filename), () => { | ||
for (const test of [ | ||
{ | ||
expectedLabels: [], | ||
expectedSummary: "Integration test 359 (hardcoded)", | ||
manualTest: "CYP-1139", | ||
projectKey: "CYP", | ||
service: "cloud", | ||
testExecutionIssueData: dedent(` | ||
{ | ||
fields: { | ||
summary: "Integration test 359 (hardcoded)", | ||
labels: LABELS | ||
} | ||
} | ||
`), | ||
title: "test execution issue data is hardcoded (cloud)", | ||
xrayPassedStatus: "PASSED", | ||
}, | ||
{ | ||
expectedLabels: ["x", "y"], | ||
expectedSummary: "Integration test 359 (wrapped)", | ||
manualTest: "CYP-1139", | ||
projectKey: "CYP", | ||
service: "cloud", | ||
testExecutionIssueData: dedent(` | ||
() => { | ||
return { | ||
fields: { | ||
summary: "Integration test 359 (wrapped)", | ||
labels: LABELS | ||
} | ||
}; | ||
} | ||
`), | ||
title: "test execution issue data is wrapped (cloud)", | ||
xrayPassedStatus: "PASSED", | ||
}, | ||
{ | ||
expectedLabels: [], | ||
expectedSummary: "Integration test 359 (hardcoded)", | ||
manualTest: "CYPLUG-461", | ||
projectKey: "CYPLUG", | ||
service: "server", | ||
testExecutionIssueData: dedent(` | ||
{ | ||
fields: { | ||
summary: "Integration test 359 (hardcoded)", | ||
labels: LABELS | ||
} | ||
} | ||
`), | ||
title: "test execution issue data is hardcoded (server)", | ||
xrayPassedStatus: "PASS", | ||
}, | ||
{ | ||
expectedLabels: ["x", "y"], | ||
expectedSummary: "Integration test 359 (wrapped)", | ||
manualTest: "CYPLUG-461", | ||
projectKey: "CYPLUG", | ||
service: "server", | ||
testExecutionIssueData: dedent(` | ||
() => { | ||
return { | ||
fields: { | ||
summary: "Integration test 359 (wrapped)", | ||
labels: LABELS | ||
} | ||
}; | ||
} | ||
`), | ||
title: "test execution issue data is wrapped (server)", | ||
xrayPassedStatus: "PASS", | ||
}, | ||
] as const) { | ||
it(test.title, async () => { | ||
const project = setupCypressProject({ | ||
configFileContent: dedent(` | ||
const { defineConfig } = require("cypress"); | ||
const fix = require("cypress-on-fix"); | ||
const { configureXrayPlugin } = require("cypress-xray-plugin"); | ||
const LABELS = []; | ||
module.exports = defineConfig({ | ||
video: false, | ||
chromeWebSecurity: false, | ||
e2e: { | ||
specPattern: "**/*.cy.js", | ||
async setupNodeEvents(on, config) { | ||
const fixedOn = fix(on); | ||
await configureXrayPlugin(fixedOn, config, { | ||
jira: { | ||
projectKey: "CYP", | ||
testExecutionIssue: ${test.testExecutionIssueData} | ||
}, | ||
xray: { | ||
uploadResults: true, | ||
testEnvironments: ["DEV"], | ||
status: { | ||
passed: "${test.xrayPassedStatus}" | ||
} | ||
}, | ||
plugin: { | ||
debug: false, | ||
}, | ||
}); | ||
fixedOn("task", { | ||
"update-labels": (values) => LABELS.push(...values) | ||
}); | ||
return config; | ||
}, | ||
}, | ||
}); | ||
`), | ||
testFiles: [ | ||
{ | ||
content: dedent(` | ||
describe("${test.manualTest} template spec", () => { | ||
it("passes", () => { | ||
cy.visit("${LOCAL_SERVER.url}"); | ||
cy.task("update-labels", ${JSON.stringify(test.expectedLabels)}) | ||
}); | ||
}); | ||
`), | ||
fileName: "spec.cy.js", | ||
}, | ||
], | ||
}); | ||
|
||
const output = runCypress(project.projectDirectory, { | ||
includeDefaultEnv: test.service, | ||
}); | ||
|
||
const testExecutionIssueKey = getCreatedTestExecutionIssueKey( | ||
test.projectKey, | ||
output, | ||
"cypress" | ||
); | ||
|
||
const searchResult = await getIntegrationClient("jira", test.service).search({ | ||
fields: ["labels", "summary"], | ||
jql: `issue in (${testExecutionIssueKey})`, | ||
}); | ||
expect(searchResult[0].fields?.labels).to.deep.eq(test.expectedLabels); | ||
expect(searchResult[0].fields?.summary).to.deep.eq(test.expectedSummary); | ||
}); | ||
} | ||
}); |
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