-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from penpot/test-fix
Test fix
- Loading branch information
Showing
305 changed files
with
1,592 additions
and
218 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
const axios = require('axios'); | ||
const { readResultsFromFile } = require('./saveTestResults'); | ||
// const fs = require('fs') | ||
// const FormData = require('form-data'); | ||
|
||
|
||
const baseUrl = 'https://chat.kaleidos.net/api/v4'; | ||
const channel_id = `${process.env.CHANNEL_ID}`; | ||
|
||
async function getToken() { | ||
const url = `${baseUrl}/users/login`; | ||
const requestBody = {"login_id":`${process.env.LOGIN_ID_MATTERMOST}`,"password":`${process.env.PASSWORD_MATTERMOST}`}; | ||
|
||
try { | ||
const response = await axios.post(url, requestBody, { | ||
headers: { 'Content-Type': 'application/json' } | ||
}); | ||
return response.headers['token']; | ||
} catch (error) { | ||
console.error('Error:', error); | ||
return null; | ||
} | ||
} | ||
|
||
// async function uploadFile() { | ||
// const url = `${baseUrl}/files`; | ||
// | ||
// const token = await getToken(); | ||
// | ||
// const fileBuffer = fs.readFileSync('playwright-report.zip'); | ||
// const filename = 'playwright-report.zip'; | ||
// | ||
// | ||
// | ||
// const formData = new FormData(); | ||
// formData.append('channel_id', channel_id); | ||
// formData.append('files', fileBuffer, { filename }); | ||
// | ||
// | ||
// try { | ||
// const response = await axios.post(url, formData, { | ||
// headers: { | ||
// 'Content-Type': 'multipart/form-data', | ||
// Authorization: `Bearer ${token}`, | ||
// }, | ||
// }); | ||
// | ||
// console.log('Ответ сервера:', response.data); | ||
// return response.data; | ||
// } catch (error) { | ||
// console.error('Ошибка загрузки файла:', error); | ||
// return null; | ||
// } | ||
// } | ||
|
||
async function sendMessage() { | ||
const url = `${baseUrl}/posts`; | ||
const token = await getToken(); | ||
|
||
// await uploadFile() | ||
function roundNumber(num) { | ||
return Math.round(num * 100) / 100; | ||
} | ||
const results = await readResultsFromFile() | ||
const messageWithLink = | ||
`**Total Tests** : **${results.Passed+results.Failed+results.Flaky}** :person_doing_cartwheel: **Success Percentage:** **${roundNumber(results.PercentPassed)}%** | ||
:white_check_mark: Success: ${results.Passed} | ||
:x: Failure: ${results.Failed} | ||
:ballot_box_with_check: Flaky: ${results.Flaky} | ||
:cat2: GitRun: https://github.com/penpot/penpotqa/actions/runs/${process.env.GITHUB_RUN_ID}`; | ||
const requestBody = { channel_id: channel_id, message: messageWithLink }; | ||
|
||
try { | ||
const response = await axios.post(url, requestBody, { | ||
headers: { | ||
'Content-Type': 'application/json', | ||
'Authorization': `Bearer ${token}` | ||
} | ||
}); | ||
|
||
return response.data; | ||
} catch (error) { | ||
console.error('Error:', error); | ||
return null; | ||
} | ||
} | ||
|
||
module.exports = { sendMessage }; |
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,55 @@ | ||
const fs = require('fs'); | ||
|
||
async function readResultsFromFile() { | ||
try { | ||
return JSON.parse(fs.readFileSync('testResults.json', 'utf8')); | ||
} catch (error) { | ||
console.error('Error reading JSON file:', error); | ||
return null; | ||
} | ||
} | ||
|
||
async function updateTestResults(result, retryCount) { | ||
if (!fs.existsSync('testResults.json')) { | ||
const initialResults = { Passed: 0, Failed: 0, Flaky: 0, PercentPassed: 0 }; | ||
try { | ||
fs.writeFileSync('testResults.json', JSON.stringify(initialResults, null, 2)); | ||
console.log('Test results file created:', initialResults); | ||
} catch (err) { | ||
console.error('Error creating testResults.json:', err); | ||
return; | ||
} | ||
} | ||
|
||
let testResults; | ||
try { | ||
const data = fs.readFileSync('testResults.json', 'utf8'); | ||
testResults = JSON.parse(data); | ||
} catch (err) { | ||
console.error('Error reading testResults.json:', err); | ||
return; | ||
} | ||
|
||
if (result === 'passed') { | ||
testResults.Passed++; | ||
} else if (result === 'failed' && retryCount === 2) { | ||
testResults.Failed++; | ||
} else if (result === 'flaky') { | ||
testResults.Flaky++; | ||
} | ||
|
||
const totalTests = testResults.Passed + testResults.Failed | ||
testResults.PercentPassed = (testResults.Passed / totalTests) * 100; | ||
|
||
|
||
try { | ||
fs.writeFileSync('testResults.json', JSON.stringify(testResults, null, 2)); | ||
console.log('Test results updated:', testResults); | ||
} catch (err) { | ||
console.error('Error writing testResults.json:', err); | ||
} | ||
} | ||
|
||
module.exports = { readResultsFromFile, updateTestResults}; | ||
|
||
|
Oops, something went wrong.