-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add code coverage for local runs (#1084)
- Loading branch information
1 parent
67701f9
commit 616511c
Showing
29 changed files
with
586 additions
and
118 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { test as testBase } from '@playwright/test'; | ||
// eslint-disable-next-line import/no-extraneous-dependencies | ||
import { addCoverageReport } from 'monocart-reporter'; | ||
|
||
const test = testBase.extend({ | ||
autoTestFixture: [ | ||
async ({ page }, use) => { | ||
const isChromium = test.info().project.name === 'tests-chromium'; | ||
|
||
if (isChromium && !process.env.CI) { | ||
await Promise.all([ | ||
page.coverage.startJSCoverage({ | ||
resetOnNavigation: false, | ||
}), | ||
]); | ||
} | ||
|
||
await use('autoTestFixture'); | ||
|
||
if (isChromium && !process.env.CI) { | ||
const [jstCoverage] = await Promise.all([page.coverage.stopJSCoverage()]); | ||
|
||
await addCoverageReport(jstCoverage, test.info()); | ||
} | ||
}, | ||
{ | ||
scope: 'test', | ||
auto: true, | ||
}, | ||
], | ||
}); | ||
|
||
export { test }; |
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,60 @@ | ||
import fs from 'fs'; | ||
import { CDPClient } from 'monocart-coverage-reports'; | ||
import { addCoverageReport } from 'monocart-reporter'; | ||
import path from 'path'; | ||
import { fileURLToPath } from 'url'; | ||
|
||
const globalTeardown = async (config) => { | ||
if (!process.env.CI) { | ||
const client = await CDPClient({ | ||
port: 9230, | ||
}); | ||
|
||
console.log('..... global teardown .....'); | ||
|
||
const dir = await client.writeCoverage(); | ||
|
||
await client.stopCoverage(); | ||
|
||
if (!fs.existsSync(dir)) { | ||
console.log('not found coverage dir'); | ||
|
||
return; | ||
} | ||
|
||
const files = fs.readdirSync(dir); | ||
|
||
// eslint-disable-next-line no-restricted-syntax | ||
for (const filename of files) { | ||
const content = fs.readFileSync(path.resolve(dir, filename)).toString('utf-8'); | ||
const json = JSON.parse(content); | ||
let coverageList = json.result; | ||
|
||
coverageList = coverageList.filter((entry) => entry.url && entry.url.startsWith('file:')); | ||
coverageList = coverageList.filter((entry) => entry.url.includes('next/server/app')); | ||
coverageList = coverageList.filter((entry) => !entry.url.includes('manifest.js')); | ||
|
||
coverageList.forEach((entry) => { | ||
const filePath = fileURLToPath(entry.url); | ||
|
||
if (fs.existsSync(filePath)) { | ||
entry.source = fs.readFileSync(filePath).toString('utf8'); | ||
} else { | ||
console.log('not found file', filePath); | ||
} | ||
}); | ||
|
||
// there is no test info on teardown, just mock one with required config | ||
const mockTestInfo = { | ||
config, | ||
}; | ||
|
||
// eslint-disable-next-line no-await-in-loop | ||
await addCoverageReport(coverageList, mockTestInfo); | ||
} | ||
} else { | ||
console.log('global teardown...'); | ||
} | ||
}; | ||
|
||
export default globalTeardown; |
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
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
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
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
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
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
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
Oops, something went wrong.