Does not split tests into partitions under vite
I run this
pnpm vite build --mode test
followed by this
pnpm ember exam --path=dist --split=20 --partition=2
(running ember-exam 9.1.0, ember-qunit 9.0.2)
But it always runs all tests. Output is no different when I change the partition number
Random option does seem to randomize though, when I add --random="abc" to the end for example.
Have I misconfigured something? Are others able to get partitioned tests with ember-exam under vite?
I think it's a combination of two issues;
- ember-exam not finding the test files to split, so is actually filtering on 0 tests
- qunit runs all tests that have been imported via the
import.meta.glob("./**/*.{js,ts,gjs,gts}", { eager: true })intests/index.html
ember-exam relies (somewhat) on ember-qunit's TestLoader, specifically here where it calls super.loadModules()
https://github.com/ember-cli/ember-exam/blob/d56afe63b076e889dcf5210b2fb5b9168939d30e/addon-test-support/-private/ember-exam-test-loader.js#L78
ember-qunit's loadModules() function ultimately relies on requirejs.entries which finds no test files under vite
So ember-exam's splitting/filtering is then applied to no files.
From there, qunit runs on all the files that were imported. Based on the (current) blueprint for vite, the tests/index.html file contains import.meta.glob("./**/*.{js,ts,gjs,gts}", { eager: true }) - so ends up running all the tests.
I'll try to post a patch here for others and to help inform a PR
I changed my tests/index.html file
<script type="module">
import { start } from "./test-helper";
- import.meta.glob("./**/*.{js,ts,gjs,gts}", { eager: true });
+ /* Import all test-related files _except_ tests. ember-exam will import the test files */
+ import.meta.glob("./**/!(*{-,_}test).{js,ts,gjs,gts}", { eager: true });
start();
</script>
And a pnpm patch for ember-exam's ember-exam-test-loader.js file
diff --git a/addon-test-support/-private/ember-exam-test-loader.js b/addon-test-support/-private/ember-exam-test-loader.js
index d12900ecc5c8cd8ed534f395b350e040c950ab82..f6b7dc127c9aeacb326c83aedb8341e3f2b37bd7 100644
--- a/addon-test-support/-private/ember-exam-test-loader.js
+++ b/addon-test-support/-private/ember-exam-test-loader.js
@@ -75,7 +75,9 @@ export default class EmberExamTestLoader extends TestLoader {
partitions = [partitions];
}
- super.loadModules();
+ const allTestFiles = import.meta.glob("/**/*{-,_}test.{js,ts,gjs,gts}");
+ this._testModules = Object.keys(allTestFiles)
+
this.setupModuleMetadataHandler();
if (modulePath || filePath) {
@@ -104,10 +106,7 @@ export default class EmberExamTestLoader extends TestLoader {
split,
partitions,
);
- this._testModules.forEach((moduleName) => {
- super.require(moduleName);
- super.unsee(moduleName);
- });
+ this._testModules.forEach((moduleName) => allTestFiles[moduleName]());
}
}
I'm not sure how to make the above patch backwards compatible for those not on vite, and also the tests/index.html change likely only works if running ember-exam with this patch - I'm not sure how that would be best adapted to some kind of generic vite blueprint change that would work for everyone
A better approach would be to continue importing all test files via the tests/index.html glob, but have ember-exam somehow configure Qunit to only run the split & filtered modules. But I couldn't get that working
ember-qunit's loadModules() function ultimately relies on requirejs.entries which finds no test files under vite
ember-exam isn't working for me after upgrading to Vite either:
Fixed in #1430
should this issue be marked as fixed since #1430 has shipped with ember-exam@10 ?
Yes! Tyty!