-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(feature) Publishing CI flag from Node script (#181)
- Loading branch information
Showing
9 changed files
with
152 additions
and
17 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
78 changes: 78 additions & 0 deletions
78
.../node-script/publish-functional-test/src/__tests__/without-token/publish-metadata.spec.js
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,78 @@ | ||
const { exec } = require("child_process"); | ||
const waitForExpect = require("wait-for-expect"); | ||
const { | ||
fetchTestRunSummary, | ||
fetchResultsMetadata, | ||
} = require("../util/projektor_client"); | ||
const { extractTestRunId } = require("../util/parse_output"); | ||
const { verifyOutput } = require("../verify/cli_output_verify"); | ||
|
||
describe("publish results metadata functional spec", () => { | ||
const serverPort = "8082"; | ||
|
||
it("should publish CI=true when running in CI", async (done) => { | ||
exec( | ||
`env-cmd -f .ci-env yarn projektor-publish --serverUrl=http://localhost:${serverPort} results/*.xml`, | ||
async (error, stdout, stderr) => { | ||
verifyOutput(error, stdout, stderr, serverPort); | ||
expect(error).toBeNull(); | ||
|
||
const testRunId = extractTestRunId(stdout); | ||
console.log("Test ID", testRunId); | ||
|
||
await waitForExpect(async () => { | ||
const testRunSummaryResponse = await fetchTestRunSummary( | ||
testRunId, | ||
serverPort | ||
); | ||
expect(testRunSummaryResponse.status).toEqual(200); | ||
}); | ||
|
||
const metadataResponse = await fetchResultsMetadata( | ||
testRunId, | ||
serverPort | ||
); | ||
expect(metadataResponse.status).toEqual(200); | ||
|
||
console.log("Results metadata response", metadataResponse.data); | ||
|
||
expect(metadataResponse.data.ci).toEqual(true); | ||
|
||
done(); | ||
} | ||
); | ||
}); | ||
|
||
it("should publish CI=false when running in CI", async (done) => { | ||
exec( | ||
`env-cmd -f .no-ci-env yarn projektor-publish --serverUrl=http://localhost:${serverPort} results/*.xml`, | ||
async (error, stdout, stderr) => { | ||
verifyOutput(error, stdout, stderr, serverPort); | ||
expect(error).toBeNull(); | ||
|
||
const testRunId = extractTestRunId(stdout); | ||
console.log("Test ID", testRunId); | ||
|
||
await waitForExpect(async () => { | ||
const testRunSummaryResponse = await fetchTestRunSummary( | ||
testRunId, | ||
serverPort | ||
); | ||
expect(testRunSummaryResponse.status).toEqual(200); | ||
}); | ||
|
||
const metadataResponse = await fetchResultsMetadata( | ||
testRunId, | ||
serverPort | ||
); | ||
expect(metadataResponse.status).toEqual(200); | ||
|
||
console.log("Results metadata response", metadataResponse.data); | ||
|
||
expect(metadataResponse.data.ci).toEqual(false); | ||
|
||
done(); | ||
} | ||
); | ||
}); | ||
}); |
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
48 changes: 48 additions & 0 deletions
48
publishers/node-script/src/__tests__/publish-metdata.spec.js
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,48 @@ | ||
const axios = require("axios"); | ||
const MockAdapter = require("axios-mock-adapter"); | ||
const { collectAndSendResults } = require("../publish"); | ||
|
||
describe("Node script publishing with results metadata", () => { | ||
let mockAxios; | ||
|
||
beforeEach(() => { | ||
mockAxios = new MockAdapter(axios); | ||
}); | ||
|
||
afterEach(() => { | ||
mockAxios.restore(); | ||
}); | ||
|
||
it("should publish results along with metadata", async () => { | ||
const fileGlob = "src/__tests__/resultsDir1/*.xml"; | ||
const serverUrl = "http://localhost:8080"; | ||
mockAxios | ||
.onPost("http://localhost:8080/groupedResults") | ||
.reply(200, { id: "ABC123", uri: "/tests/ABC123" }); | ||
|
||
const isCI = true; | ||
|
||
await collectAndSendResults( | ||
serverUrl, | ||
null, | ||
[fileGlob], | ||
null, | ||
null, | ||
"projektor/projektor", | ||
"main", | ||
"my-proj", | ||
isCI | ||
); | ||
|
||
expect(mockAxios.history.post.length).toBe(1); | ||
|
||
const resultsPostRequest = mockAxios.history.post.find((postRequest) => | ||
postRequest.url.includes("groupedResults") | ||
); | ||
|
||
const parsedRequestBody = JSON.parse(resultsPostRequest.data); | ||
expect(parsedRequestBody.groupedTestSuites.length).toBe(1); | ||
|
||
expect(parsedRequestBody.metadata.ci).toBe(true); | ||
}); | ||
}); |
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