When working with vite, running the dev server and generating the production build with Rollup are two different actions that both have a specific execution. For instance, when dealing with public assets provided by the app and addons:
when running the vite dev server, the assets plugin uses a middleware to catch the assets-related request, find the actual location of the asset, and serve it.
when building the app (like for a production build), the assets plugin will emit the public assets in the dist/ output, where they are supposed to be.
This case highlights why we need to test some behaviors for both dev mode and build mode now the test suite is using vite.
Testing dev mode easily
This PR implements a CommandWatcher utility to ease running a vite dev server in tests. It relies on the former EmberCLI class that was used to run ember serve, but it makes it more generic (you can now choose the name of the command like ember or vite) and it makes it an importable helper so we can test the dev mode in multiple test files.
Compat dummy app test
The first use case for the new CommandWatcher is the compat-dummy-app-test. This PR prepares the field so the tests that check public assets presence now use vite and check both the dev mode and the build.
This preparation work is required to complete #1859, which will remove the part of the code that is now managed by the assets plugin: in #1859, compat-dummy-app-test will have to stop testing public assets are present in the rewritten app and instead test they are present in the dist (in build mode) or served correctly (in dev mode).
Here, aside of the assertions, we do the following things:
We update the addon template used for the dummy app test scenarios. vite is now configured to run the assets plugin and we also update ember-qunit to fix an issue in the development build.
The test waits for the dev server to be ready, and it knows when it's ready using a regexp matching the text that is supposed to be output on the server when it's started. This regexp is now slightly more flexible, and in CommandWatcher implementation, we strip the Ansi characters before analyzing the server output, because vite server colorize the text, which can mess-up the regex.
Context
When working with vite, running the dev server and generating the production build with Rollup are two different actions that both have a specific execution. For instance, when dealing with public assets provided by the app and addons:
assets
plugin uses a middleware to catch the assets-related request, find the actual location of the asset, and serve it.assets
plugin will emit the public assets in thedist/
output, where they are supposed to be.This case highlights why we need to test some behaviors for both dev mode and build mode now the test suite is using vite.
Testing dev mode easily
This PR implements a
CommandWatcher
utility to ease running a vite dev server in tests. It relies on the formerEmberCLI
class that was used to runember serve
, but it makes it more generic (you can now choose the name of the command likeember
orvite
) and it makes it an importable helper so we can test the dev mode in multiple test files.Compat dummy app test
The first use case for the new
CommandWatcher
is thecompat-dummy-app-test
. This PR prepares the field so the tests that check public assets presence now use vite and check both the dev mode and the build.This preparation work is required to complete #1859, which will remove the part of the code that is now managed by the
assets
plugin: in #1859,compat-dummy-app-test
will have to stop testing public assets are present in the rewritten app and instead test they are present in thedist
(in build mode) or served correctly (in dev mode).Here, aside of the assertions, we do the following things:
assets
plugin and we also updateember-qunit
to fix an issue in the development build.CommandWatcher
implementation, we strip the Ansi characters before analyzing the server output, because vite server colorize the text, which can mess-up the regex.