Skip to content

Commit

Permalink
Adding verbose logging option to node script (#1186)
Browse files Browse the repository at this point in the history
  • Loading branch information
craigatk committed Dec 2, 2023
1 parent 4b60ec6 commit 03d359b
Show file tree
Hide file tree
Showing 23 changed files with 206 additions and 156 deletions.
6 changes: 3 additions & 3 deletions publishers/node-script/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "projektor-publish",
"version": "3.12.0",
"version": "3.12.1",
"homepage": "https://projektor.dev/docs/node-script/",
"repository": {
"type": "git",
Expand All @@ -24,11 +24,11 @@
"node-gzip": "1.1.2"
},
"devDependencies": {
"axios-mock-adapter": "1.21.5",
"axios-mock-adapter": "1.22.0",
"env-cmd": "10.1.0",
"jest": "29.7.0",
"jest-junit": "16.0.0",
"prettier": "3.0.3",
"prettier": "3.1.0",
"projektor-publish": "3.12.0",
"wait-for-expect": "3.0.2"
},
Expand Down
6 changes: 3 additions & 3 deletions publishers/node-script/src/__tests__/index-coverage.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,21 @@ describe("node script index - coverage reports", () => {
{ coverage, serverUrl, compressionEnabled: false },
{},
null,
"projektor.none.json"
"projektor.none.json",
);

expect(mockAxios.history.post.length).toBe(1);

const resultsPostRequest = mockAxios.history.post.find((postRequest) =>
postRequest.url.includes("groupedResults")
postRequest.url.includes("groupedResults"),
);

const resultsPostData = resultsPostRequest.data;

const resultsPostBody = JSON.parse(resultsPostData);
expect(resultsPostBody.coverageFiles.length).toBe(1);
expect(resultsPostBody.coverageFiles[0].reportContents).toContain(
"<coverage"
"<coverage",
);
});
});
6 changes: 3 additions & 3 deletions publishers/node-script/src/__tests__/index-exit.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe("node script index exit with failure", () => {
"src/__tests__/resultsWithFailure/*.xml",
],
null,
"projektor.none.json"
"projektor.none.json",
);

expect(process.exitCode).toBe(1);
Expand All @@ -56,7 +56,7 @@ describe("node script index exit with failure", () => {
"src/__tests__/resultsDir1/*.xml",
],
null,
"projektor.none.json"
"projektor.none.json",
);

expect(process.exitCode).not.toBe(1);
Expand All @@ -75,7 +75,7 @@ describe("node script index exit with failure", () => {
{ resultsFileGlobs, failOnPublishError: true, serverUrl },
{},
null,
"projektor.none.json"
"projektor.none.json",
);

expect(process.exitCode).toBe(1);
Expand Down
12 changes: 6 additions & 6 deletions publishers/node-script/src/__tests__/index-git.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe("node script index - Git source control values", () => {
},
{ VELA_BUILD_REF: "refs/heads/my-branch" },
null,
"src/__tests__/does_not_exist.json"
"src/__tests__/does_not_exist.json",
);
expect(mockAxios.history.post.length).toBe(1);

Expand All @@ -54,7 +54,7 @@ describe("node script index - Git source control values", () => {
},
{ VELA_PULL_REQUEST_SOURCE: "my-branch" },
null,
"src/__tests__/does_not_exist.json"
"src/__tests__/does_not_exist.json",
);
expect(mockAxios.history.post.length).toBe(1);

Expand Down Expand Up @@ -84,7 +84,7 @@ describe("node script index - Git source control values", () => {
DRONE_PULL_REQUEST: "42",
},
null,
"src/__tests__/does_not_exist.json"
"src/__tests__/does_not_exist.json",
);
expect(mockAxios.history.post.length).toBe(1);

Expand Down Expand Up @@ -112,7 +112,7 @@ describe("node script index - Git source control values", () => {
},
{ VELA_BUILD_PULL_REQUEST: "42" },
null,
"src/__tests__/does_not_exist.json"
"src/__tests__/does_not_exist.json",
);
expect(mockAxios.history.post.length).toBe(1);

Expand All @@ -138,7 +138,7 @@ describe("node script index - Git source control values", () => {
},
{ VELA_BUILD_PULL_REQUEST: "42", VELA_BUILD_NUMBER: "22" },
null,
"src/__tests__/does_not_exist.json"
"src/__tests__/does_not_exist.json",
);
expect(mockAxios.history.post.length).toBe(1);

Expand All @@ -163,7 +163,7 @@ describe("node script index - Git source control values", () => {
},
{ VELA_BUILD_PULL_REQUEST: "42", VELA_BUILD_NUMBER: "22" },
null,
"src/__tests__/does_not_exist.json"
"src/__tests__/does_not_exist.json",
);
expect(mockAxios.history.post.length).toBe(1);

Expand Down
12 changes: 6 additions & 6 deletions publishers/node-script/src/__tests__/index-performance.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,26 @@ describe("node script index - performance results", () => {
{ performance, serverUrl, compressionEnabled },
{},
null,
"projektor.none.json"
"projektor.none.json",
);

expect(mockAxios.history.post.length).toBe(1);

const resultsPostRequest = mockAxios.history.post.find((postRequest) =>
postRequest.url.includes("groupedResults")
postRequest.url.includes("groupedResults"),
);

const parsedRequestBody = JSON.parse(resultsPostRequest.data.toString());
expect(parsedRequestBody.groupedTestSuites.length).toBe(0);

expect(parsedRequestBody.performanceResults.length).toBe(2);
const file1 = parsedRequestBody.performanceResults.find(
(file) => file.name === "perf-test-1.json"
(file) => file.name === "perf-test-1.json",
);
expect(file1.resultsBlob).toBe('{"name":"perf-test-1"}');

const file2 = parsedRequestBody.performanceResults.find(
(file) => file.name === "perf-test-2.json"
(file) => file.name === "perf-test-2.json",
);
expect(file2.resultsBlob).toBe('{"name":"perf-test-2"}');
});
Expand All @@ -62,13 +62,13 @@ describe("node script index - performance results", () => {
{ performance, serverUrl, compressionEnabled },
{},
null,
"projektor.none.json"
"projektor.none.json",
);

expect(mockAxios.history.post.length).toBe(0);

expect(consoleLog).toHaveBeenCalledWith(
"No performance results files found in locations does_not_exist/*.json"
"No performance results files found in locations does_not_exist/*.json",
);
});
});
6 changes: 3 additions & 3 deletions publishers/node-script/src/__tests__/index-quality.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe("node script index - code quality reports", () => {
{ resultsFileGlobs, codeQuality, serverUrl },
{},
null,
"projektor.none.json"
"projektor.none.json",
);

expect(mockAxios.history.post.length).toBe(1);
Expand Down Expand Up @@ -66,7 +66,7 @@ describe("node script index - code quality reports", () => {
{ resultsFileGlobs, codeQuality, serverUrl },
{},
null,
"projektor.none.json"
"projektor.none.json",
);

expect(mockAxios.history.post.length).toBe(1);
Expand Down Expand Up @@ -106,7 +106,7 @@ describe("node script index - code quality reports", () => {
{ resultsFileGlobs, codeQuality, serverUrl },
{},
null,
"projektor.none.json"
"projektor.none.json",
);

expect(mockAxios.history.post.length).toBe(1);
Expand Down
16 changes: 8 additions & 8 deletions publishers/node-script/src/__tests__/index-slack.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe("index Slack message file", () => {
{ resultsFileGlobs, serverUrl, projectName, writeSlackMessageFile },
{},
null,
"projektor.none.json"
"projektor.none.json",
);

expect(fs.existsSync(slackMessageFileName)).toBeTruthy();
Expand All @@ -44,7 +44,7 @@ describe("index Slack message file", () => {
.toString();
const parsedMessage = JSON.parse(messageFileContents);
expect(parsedMessage.attachments[0].pretext).toBe(
`Tests passed in project ${projectName}`
`Tests passed in project ${projectName}`,
);
});

Expand All @@ -69,7 +69,7 @@ describe("index Slack message file", () => {
},
{},
null,
"projektor.none.json"
"projektor.none.json",
);

expect(fs.existsSync(slackMessageFileName)).toBeTruthy();
Expand All @@ -79,7 +79,7 @@ describe("index Slack message file", () => {
.toString();
const parsedMessage = JSON.parse(messageFileContents);
expect(parsedMessage.attachments[0].pretext).toBe(
`Tests passed in project ${slackProjectName}`
`Tests passed in project ${slackProjectName}`,
);
});

Expand All @@ -102,7 +102,7 @@ describe("index Slack message file", () => {
},
{},
null,
"projektor.none.json"
"projektor.none.json",
);

expect(fs.existsSync(slackMessageFileName)).toBeTruthy();
Expand All @@ -112,7 +112,7 @@ describe("index Slack message file", () => {
.toString();
const parsedMessage = JSON.parse(messageFileContents);
expect(parsedMessage.attachments[0].pretext).toBe(
`Tests passed in project ${slackProjectName}`
`Tests passed in project ${slackProjectName}`,
);
});

Expand All @@ -135,7 +135,7 @@ describe("index Slack message file", () => {
},
{},
null,
"projektor.none.json"
"projektor.none.json",
);

expect(fs.existsSync(slackMessageFileName)).toBeTruthy();
Expand All @@ -147,7 +147,7 @@ describe("index Slack message file", () => {
const message = parsedMessage.attachments[0];
expect(message.pretext).toBe("No test results found");
expect(message.text).toBe(
`No test results found to publish in project ${slackProjectName}`
`No test results found to publish in project ${slackProjectName}`,
);
});
});
Loading

0 comments on commit 03d359b

Please sign in to comment.