Skip to content

Commit

Permalink
Use Vitest v1.0.0-beta.4, run browser tests in CI
Browse files Browse the repository at this point in the history
Per commit af2084b, running headless
browser tests at this moment requires at least Vitest v1.0.0-beta.3.
Updating to the beta version seems fine to me so far.

I found a way to run the headless browser tests in CI without making a
mess of the package.json script by using alternative config files.

Updated vite.config.js to use defineConfig() to make type information
available in IntelliJ. Added the buildDir() function to vite.config.js
to help configure test.outputFile in vitest.config.ci-browser.js.

---

I played around with trying to collect coverage from running the tests
in the browser. I'll try to add it in a future commit, but the basic
issues are:

- @vitest/coverage-istanbul is required, because @vitest/coverage-v8
  doesn't work in the browser.

- The command to run coverage is then:
  pnpm test -- --browser --coverage.enabled --coverage.provider=istanbul

- It currently reports 0% coverage, because when the tests call
  window.open() (via PageLoader.load()), the modules are loaded in a
  separate process.

I confirmed this last point using a temporary test that imported the
main.js module directly after creating a <div id="app"> on
window.document, generating 100% coverage. Running the test using
Node.js and JSDOM doesn't have the same problem, because JSDOM doesn't
open a new process.

I've ideas on how to handle this and generate coverage from the
browser-run tests in an elegant way that I'll try soon. I'm not sure
that I'll absolutely enable this in CI, but we'll see after I try out
these ideas and think about it some more.
  • Loading branch information
mbland committed Nov 16, 2023
1 parent af2084b commit 98c3ce1
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 135 deletions.
2 changes: 1 addition & 1 deletion strcalc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ val mergeTestReports = fun(resultsDir: File) {

// The `pnpm_test-ci` output is already merged. Trying to merge it again
// results in an empty file, so skip it.
if (taskName == "test-frontend") return
if (taskName.startsWith("test-frontend")) return

val relResultsDir = relativeToRootDir(resultsDir.toPath())
val reportTaskName = "merged-report-$taskName"
Expand Down
10 changes: 5 additions & 5 deletions strcalc/src/main/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@
"test": "vitest",
"test-run": "vitest run",
"test-ui": "vitest --ui --coverage",
"test-ci": "vitest run --coverage --reporter=junit --reporter=default",
"test-ci": "vitest run --config vitest.config.ci-jsdom.js && vitest run --config vitest.config.ci-browser.js",
"coverage": "vitest run --coverage"
},
"devDependencies": {
"@stylistic/eslint-plugin-js": "^1.2.0",
"@vitest/browser": "^0.34.6",
"@vitest/coverage-v8": "^0.34.6",
"@vitest/ui": "^0.34.6",
"@vitest/browser": "1.0.0-beta.4",
"@vitest/coverage-v8": "1.0.0-beta.4",
"@vitest/ui": "1.0.0-beta.4",
"eslint": "^8.53.0",
"eslint-plugin-vitest": "^0.3.9",
"jsdom": "^22.1.0",
"vite": "^4.5.0",
"vitest": "^0.34.6",
"vitest": "1.0.0-beta.4",
"webdriverio": "^8.23.0"
}
}
Loading

0 comments on commit 98c3ce1

Please sign in to comment.