ember-exam icon indicating copy to clipboard operation
ember-exam copied to clipboard

Does not split tests into partitions under vite

Open Techn1x opened this issue 8 months ago • 2 comments

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?

Techn1x avatar Apr 28 '25 06:04 Techn1x

I think it's a combination of two issues;

  1. ember-exam not finding the test files to split, so is actually filtering on 0 tests
  2. qunit runs all tests that have been imported via the import.meta.glob("./**/*.{js,ts,gjs,gts}", { eager: true }) in tests/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

Techn1x avatar Apr 28 '25 08:04 Techn1x

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

Techn1x avatar Apr 28 '25 08:04 Techn1x

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:

Image

amk221 avatar Jul 16 '25 10:07 amk221

Fixed in #1430

NullVoxPopuli avatar Jul 24 '25 17:07 NullVoxPopuli

should this issue be marked as fixed since #1430 has shipped with ember-exam@10 ?

bartocc avatar Sep 18 '25 14:09 bartocc

Yes! Tyty!

NullVoxPopuli avatar Sep 18 '25 16:09 NullVoxPopuli