Skip to content
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

Generating code coverage on Azure pipelines #19

Open
tchanias opened this issue Nov 27, 2023 · 0 comments
Open

Generating code coverage on Azure pipelines #19

tchanias opened this issue Nov 27, 2023 · 0 comments

Comments

@tchanias
Copy link

System info

● Playwright Version: Latest
● Operating System: Win 11
● Browser: MS Edge

Steps
npm i && npx playwright install --with-deps
npm i vite-plugin-istanbul
npm i nyc
npx playwright test --project "e2e tests on pipeline"
npx nyc report --reporter=text

Configs:
vite.config.ts

image

baseFixtures.ts

`import * as fs from 'fs'
import * as path from 'path'
import * as crypto from 'crypto'
import { fileURLToPath } from 'url'
import { test as baseTest } from '@playwright/test'

const filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(filename)
const istanbulCLIOutput = path.join(__dirname, '..', '.nyc_output')

export function generateUUID(): string {
return crypto.randomBytes(16).toString('hex')
}

export const test = baseTest.extend({
context: async ({ context }, use) => {
await context.addInitScript(() =>
window.addEventListener('beforeunload', () =>
(window as any).collectIstanbulCoverage(JSON.stringify((window as any).coverage)),
),
)
await fs.promises.mkdir(istanbulCLIOutput, { recursive: true })
await context.exposeFunction('collectIstanbulCoverage', (coverageJSON: string) => {
if (coverageJSON)
fs.writeFileSync(path.join(istanbulCLIOutput, playwright_coverage_${generateUUID()}.json), coverageJSON)
})
await use(context)
for (const page of context.pages()) {
await page.evaluate(() => (window as any).collectIstanbulCoverage(JSON.stringify((window as any).coverage)))
}
},
})

export const expect = test.expect`

Expected
When running the tests locally, the coverage json files are generated under the nyc_report folder as expected and the report can be displayed normally either in text or html form.

On the azure pipeline environment, all tests are still passing, the nyc_folder is created but there are no json files created under it.
Thus, this is the output I get from the npx nyc report --reporter=text command.

image

I am not really sure what I have done incorrectly or whether this tool was never supposed to be able to work on azure pipelines at all though, Some input or tips towards the right direction would be greatly appreciated. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant