Skip to content

Commit 2dc2b1b

Browse files
committed
don't actually need the env var
1 parent ff23b75 commit 2dc2b1b

File tree

4 files changed

+25
-22
lines changed

4 files changed

+25
-22
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"update-snapshots": "npm test run -- -u",
2323
"e2e": "playwright test",
2424
"e2ec": "playwright test --project=chrome",
25-
"e2e-coverage": "rm -rf .nyc_output coverage && COVERAGE=1 npm run e2ec && nyc report --reporter=html --report-dir=coverage && echo 'report at coverage/index.html'",
25+
"e2e-coverage": "rm -rf .nyc_output coverage && npm run e2ec && nyc report --reporter=html --report-dir=coverage && echo 'report at coverage/index.html'",
2626
"visual:baseline": "./tools/generate-visual-baseline.sh",
2727
"visual:compare": "playwright test -c playwright.visual.config.ts",
2828
"lint": "oxlint --type-aware",

playwright.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export default {
5050
],
5151
// use different port so it doesn't conflict with local dev server
5252
webServer: {
53-
command: `${process.env.COVERAGE ? 'VITE_COVERAGE=true ' : ''}npm run start:msw -- --port 4009`,
53+
command: 'npm run start:msw -- --port 4009',
5454
port: 4009,
5555
},
5656
} satisfies PlaywrightTestConfig

test/e2e/fixtures.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,13 @@ import { mkdirSync, writeFileSync } from 'fs'
99
import { resolve } from 'path'
1010
import { test as base, type Page } from '@playwright/test'
1111

12-
const coverageEnabled = !!process.env.COVERAGE
1312
const coverageDir = resolve('.nyc_output')
1413

1514
// Counter for unique filenames within this worker process
1615
let coverageCounter = 0
1716

1817
async function collectCoverage(page: Page): Promise<void> {
19-
if (!coverageEnabled) return
20-
21-
const coverage = await page.evaluate(() => {
22-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
23-
return (window as any).__coverage__
24-
})
25-
18+
const coverage = await page.evaluate(() => (window as any).__coverage__) // eslint-disable-line @typescript-eslint/no-explicit-any
2619
if (!coverage) return
2720

2821
mkdirSync(coverageDir, { recursive: true })

vite.config.ts

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -135,18 +135,28 @@ export default defineConfig(({ mode }) => ({
135135
}),
136136
react(),
137137
apiMode === 'remote' && basicSsl(),
138-
!!process.env.VITE_COVERAGE &&
139-
istanbul({
140-
include: 'app/**/*',
141-
exclude: [
142-
'app/api/__generated__',
143-
'**/*.spec.*',
144-
'app/api/window.ts',
145-
'app/components/MswBanner.tsx',
146-
],
147-
extension: ['.ts', '.tsx'],
148-
requireEnv: true,
149-
}),
138+
// Docs: https://github.com/ifaxity/vite-plugin-istanbul
139+
istanbul({
140+
include: 'app/**/*',
141+
exclude: [
142+
'app/api/__generated__',
143+
'**/*.spec.*',
144+
'app/api/window.ts',
145+
'app/components/MswBanner.tsx',
146+
],
147+
extension: ['.ts', '.tsx'],
148+
// We technically do not need checkProd to prevent instrumenting in
149+
// production because the plugin won't instrument in build mode by default
150+
// (tested by comparing with forceBuildInstrument: true, which increases
151+
// the bundle size a ton), and we only use build mode in prod.
152+
//
153+
// Initially this used requireEnv to only instrument when VITE_COVERAGE
154+
// is set, but instrumenting didn't seem to slow the tests down at all. So
155+
// it seems fine to always instrument and always collect coverage if it's
156+
// present (see test/e2e/fixtures.ts`). This keeps things simple in CI
157+
// as well.
158+
checkProd: true,
159+
}),
150160
],
151161
html: {
152162
// don't include a placeholder nonce in production.

0 commit comments

Comments
 (0)