Skip to content

DX | 01-04-2025 | Release #309

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 18 commits into from
Apr 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
1e0166b
fix: validate parameters in sync method and ensure query parameters a…
harshithad0703 Mar 11, 2025
5659488
Merge pull request #303 from contentstack/fix/dx-2269-sre-issue
harshithad0703 Mar 11, 2025
135aec1
Merge pull request #304 from contentstack/staging
cs-raj Mar 12, 2025
c7393b0
feat: add Jest configuration for testing environment and reporting
harshithad0703 Mar 20, 2025
6dddf32
refactor: improve test summary reporting in sanity-report.js
harshithad0703 Mar 20, 2025
6fa302f
refactor: update tests to use jest and improve readability
harshithad0703 Mar 20, 2025
1d77bfc
fix: update live preview test to use correct CDN host
harshithad0703 Mar 20, 2025
600c115
feat: update testing scripts and enhance Slack reporting for test res…
harshithad0703 Mar 20, 2025
9a4b699
refactor: remove unnecessary invocation of sendSlackMessage in sanity…
harshithad0703 Mar 20, 2025
9870ff0
refactor: remove try catch blocks in test cases
harshithad0703 Mar 20, 2025
abff767
fix: update Slack channel in sendSlackMessage function
harshithad0703 Mar 24, 2025
b116bd6
update dependencies
harshithad0703 Mar 26, 2025
e673176
Merge pull request #307 from contentstack/fix/dx-2317-slack-fail-msg
harshithad0703 Mar 26, 2025
5aef8f0
Merge pull request #308 from contentstack/development
harshithad0703 Mar 26, 2025
b7e3bc9
fix: update Slack channel to SLACK_CHANNEL2 in sendFailureDetails fun…
harshithad0703 Mar 27, 2025
92eab6d
Merge pull request #310 from contentstack/fix/slack-thread-msg
harshithad0703 Mar 27, 2025
066d687
Merge pull request #311 from contentstack/development
harshithad0703 Mar 27, 2025
cb95614
Merge pull request #316 from contentstack/master
harshithad0703 Apr 1, 2025
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
21 changes: 21 additions & 0 deletions jest.js.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module.exports = {
testEnvironment: "node",
testMatch: ["**/test/**/*.js"],
testPathIgnorePatterns: [
"/node_modules/",
"/test/index.js",
"/test/config.js",
"/test/sync_config.js",
"/test/.*/utils.js",
"/test/sync/",
],
reporters: ["default", ["jest-html-reporters",
{
"filename": "tap-html.html",
"expand": true,
"inlineSource": true,
"includeFailureMsg": true, // Includes error messages in JSON
"includeConsoleLog": true
}
]],
};
58 changes: 27 additions & 31 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"_id": "[email protected]",
"scripts": {
"test": "npm run test:e2e && npm run test:typescript",
"test:e2e": "tape test/index.js | tap-html --out ./tap-html.html",
"test:e2e": "jest --config jest.js.config.js",
"test:typescript": "jest --config jest.config.js --testPathPattern=test/typescript",
"automate": "node test.js",
"build:node": "webpack --config webpack/webpack.node.js",
Expand Down Expand Up @@ -100,10 +100,10 @@
"webpack-node-externals": "^3.0.0"
},
"dependencies": {
"@contentstack/utils": "^1.3.15",
"@fetch-mock/jest": "^0.2.10",
"@contentstack/utils": "^1.3.18",
"@fetch-mock/jest": "^0.2.12",
"es6-promise": "^4.2.8",
"fetch-mock": "^12.2.0",
"fetch-mock": "^12.4.0",
"localStorage": "1.0.4",
"qs": "^6.14.0"
}
Expand Down
129 changes: 76 additions & 53 deletions sanity-report-dev11.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
const fs = require("fs");
const { App } = require("@slack/bolt");
const { JSDOM } = require("jsdom");
const dotenv = require("dotenv");
const path = require("path");

dotenv.config();

Expand All @@ -9,40 +11,38 @@ const user2 = process.env.USER2;
const user3 = process.env.USER3;
const user4 = process.env.USER4;

const tapHtmlContent = fs.readFileSync("./tap-html.html", "utf8");
const dom = new JSDOM(tapHtmlContent);
const $ = require("jquery")(dom.window);

const totalCount = $(".nav a:nth-child(2)")
.text()
.trim()
.replace("Total Count", "");
const totalPass = $(".nav a:nth-child(3)")
.text()
.trim()
.replace("Total Pass", "");
const totalFail = $(".nav a:nth-child(4)")
.text()
.trim()
.replace("Total Fail", "");

const totalTime = $(".nav a:nth-child(1)")
.text()
.trim()
.replace("Total Time", "");

const milliseconds = parseInt(totalTime.replace(/\D/g, ''), 10);
const totalSeconds = Math.floor(milliseconds / 1000);
const durationInMinutes = Math.floor(totalSeconds / 60);
const durationInSeconds = totalSeconds % 60;

const passedTests = parseInt(totalPass, 10);
const totalTests = parseInt(totalCount, 10);
const data = fs.readFileSync(path.join(__dirname, "tap-html.html"), "utf8");
const dom = new JSDOM(data);
const textarea = dom.window.document.querySelector(
"#jest-html-reports-result-data"
);
const testResults = JSON.parse(textarea.textContent.trim());

const startTime = testResults.startTime;
const endTime = Math.max(
...testResults.testResults.map((t) => t.perfStats.end)
);
const totalSeconds = (endTime - startTime) / 1000;
const minutes = Math.floor(totalSeconds / 60);
const seconds = (totalSeconds % 60).toFixed(2);
const duration = `${minutes}m ${seconds}s`;

const summary = {
totalSuites: testResults.numTotalTestSuites,
passedSuites: testResults.numPassedTestSuites,
failedSuites: testResults.numFailedTestSuites,
totalTests: testResults.numTotalTests,
passedTests: testResults.numPassedTests,
failedTests: testResults.numFailedTests,
skippedTests: testResults.numPendingTests + testResults.numTodoTests,
pendingTests: testResults.numPendingTests,
duration: duration,
};

const resultMessage =
passedTests === totalTests
? `:white_check_mark: Success (${passedTests} / ${totalTests} Passed)`
: `:x: Failure (${passedTests} / ${totalTests} Passed)`;
summary.passedTests === summary.totalTests
? `:white_check_mark: Success (${summary.passedTests} / ${summary.totalTests} Passed)`
: `:x: Failure (${summary.passedTests} / ${summary.totalTests} Passed)`;

const pipelineName = process.env.GO_PIPELINE_NAME;
const pipelineCounter = process.env.GO_PIPELINE_COUNTER;
Expand All @@ -51,42 +51,65 @@ const goCdServer = process.env.GOCD_SERVER;
const reportUrl = `http://${goCdServer}/go/files/${pipelineName}/${pipelineCounter}/sanity/1/sanity/test-results/tap-html.html`;

let tagUsers = ``;
if (totalFail > 0) {
if (summary.failedTests > 0) {
tagUsers = `<@${user1}> <@${user2}> <@${user3}> <@${user4}>`;
}

const slackMessage = {
text: `Dev11, SDK-CDA Sanity
*Result:* ${resultMessage}. ${durationInMinutes}m ${durationInSeconds}s
*Failed Tests:* ${totalFail}
*Result:* ${resultMessage}. ${summary.duration}s
*Failed Tests:* ${summary.failedTests + summary.skippedTests}
<${reportUrl}|View Report>
${tagUsers}`,
};

const slackWebhookUrl = process.env.SLACK_WEBHOOK_URL;

const sendSlackMessage = async (message) => {
const payload = {
text: message,
};
const app = new App({
token: process.env.SLACK_BOT_TOKEN,
signingSecret: process.env.SLACK_SIGNING_SECRET,
});

const sendSlackMessage = async () => {
try {
const response = await fetch(slackWebhookUrl, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(payload),
const result = await app.client.chat.postMessage({
token: process.env.SLACK_BOT_TOKEN,
channel: process.env.SLACK_CHANNEL2,
text: slackMessage.text, // Ensure this is the full object
});

if (!response.ok) {
throw new Error(`Error sending message to Slack: ${response.statusText}`);
if (summary.failedTests > 0) {
await sendFailureDetails(result.ts); // Pass the correct thread timestamp
}

console.log("Message sent to Slack successfully");
} catch (error) {
console.error("Error:", error);
console.error("Error sending Slack message:", error);
}
};

const sendFailureDetails = async (threadTs) => {
const failedTestSuites = testResults.testResults.filter(
(suite) => suite.numFailingTests > 0
);
if (failedTestSuites.length > 0) {
let failureDetails = "*Failed Test Modules:*\n";
for (const suite of failedTestSuites) {
let modulePath = suite.testFilePath;
let formattedModuleName = path
.relative(__dirname, modulePath)
.replace(/^test\//, "")
.replace(/\.js$/, "")
.replace(/\//g, " ");
failureDetails += ` - ${formattedModuleName}: ${suite.numFailingTests} failed\n`;
}
try {
await app.client.chat.postMessage({
token: process.env.SLACK_BOT_TOKEN,
channel: process.env.SLACK_CHANNEL2,
text: failureDetails,
thread_ts: threadTs,
});
} catch (error) {
console.error("Error sending failure details:", error);
}
}
};

sendSlackMessage(slackMessage.text);
sendSlackMessage(slackMessage.text);
Loading
Loading