Skip to content

Commit

Permalink
Merge pull request #597 from w3c/metrics-fix
Browse files Browse the repository at this point in the history
Fix Test Database Seeder to Support TestPlanReport Metrics
  • Loading branch information
alflennik authored Apr 10, 2023
2 parents 5a5fb3a + 70bb8bb commit 232e26b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,38 @@ const {
const populateData = require('../../services/PopulatedData/populateData');
const sortArrayLikeArray = require('../../util/sortArrayLikeArray');
const createTestResultSkeleton = require('./createTestResultSkeleton');
const getMetrics = require('../../util/getMetrics');
const {
updateTestPlanReport
} = require('../../models/services/TestPlanReportService');
const runnableTestsResolver = require('../TestPlanReport/runnableTestsResolver');
const finalizedTestResultsResolver = require('../TestPlanReport/finalizedTestResultsResolver');

const findOrCreateTestResultResolver = async (
{ parentContext: { id: testPlanRunId } },
{ testId, atVersionId, browserVersionId },
{ user }
) => {
const fixTestPlanReportMetrics = async testPlanReportStale => {
const { testPlanReport } = await populateData({
testPlanReportId: testPlanReportStale.id
});
const runnableTests = runnableTestsResolver(testPlanReport);
const finalizedTestResults = finalizedTestResultsResolver({
...testPlanReport
});
const metrics = getMetrics({
testPlanReport: {
...testPlanReport,
finalizedTestResults,
runnableTests
}
});
await updateTestPlanReport(testPlanReport.id, {
metrics: { ...testPlanReport.metrics, ...metrics }
});
};

const {
testPlanRun,
testPlanReport,
Expand Down Expand Up @@ -66,6 +92,7 @@ const findOrCreateTestResultResolver = async (
await updateTestPlanRun(testPlanRun.id, {
testResults: newTestResults
});
await fixTestPlanReportMetrics(testPlanReport);
} else {
// atVersionId and browserVersionId update
const testResultIndex = testPlanRun.testResults.findIndex(
Expand All @@ -79,6 +106,7 @@ const findOrCreateTestResultResolver = async (
await updateTestPlanRun(testPlanRun.id, {
testResults: newTestResults
});
await fixTestPlanReportMetrics(testPlanReport);
}

return populateData({ testResultId: newTestResult.id });
Expand Down
4 changes: 1 addition & 3 deletions server/tests/integration/embed.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,7 @@ describe('embed', () => {
const copyEmbedButtonOnClick = copyEmbedButton.getAttribute('onclick');
const table = document.querySelector('table');
const cellWithData = Array.from(table.querySelectorAll('td')).find(td =>
// TODO: change check to \d+ instead of \d* as soon as the missing
// number issue is fixed
td.innerHTML.match(/<b>\s*\d*%\s*<\/b>\s*supported/)
td.innerHTML.match(/<b>\s*\d+%\s*<\/b>\s*supported/)
);

expect(res.text).toEqual(res2.text);
Expand Down

0 comments on commit 232e26b

Please sign in to comment.