This package provides isolated E2E tests by generating a new application with local packages and then running tests again that code by executing it and verifying expected behavior.
Tests can be invoked by running pnpm run test.e2e.cli
.
Note that running E2E tests requires the workspace projects to be prebuilt manually!
E2E project does the following internally:
-
Vitest is configured to run a setup function once PRIOR TO ALL tests. During the setup
@builder.io/qwik
,@builder.io/qwik-city
andeslint-plugin-qwik
packages will be packed withpnpm pack
Those will be used at a step 2 for every test. Tarballs are located intemp/tarballs
folder within this repo. It is assumed that packages are built before E2E is executed. -
Simulates
npm create qwik
locally using direct commandnode packages/create-qwik/create-qwik.cjs playground {outputDir}
- By default
outputDir
is an auto-generated one usingtmp
npm package. The application that is created here will be removed after the test is executed - It is possible to install into custom folder using environment variable
TEMP_E2E_PATH
. Here's how the command would look like in this case: - with absolute path
TEMP_E2E_PATH=/Users/name/projects/tests pnpm run test.e2e.cli
- with path relative to the qwik workspace
TEMP_E2E_PATH=temp/e2e-folder pnpm run test.e2e.cli
Note that provided folder should exist. If custom path is used, generated application will not be removed after the test completes, which is helpful for debugging.
- By default
-
Uses packed
@builder.io/qwik
,@builder.io/qwik-city
andeslint-plugin-qwik
packages to update package.json file of the generated application withfile:path-to-package.tgz
. -
Runs actual tests. Please pay attention at the
beforeAll
hook in the spec file
beforeAll(() => {
const config = scaffoldQwikProject();
global.tmpDir = config.tmpDir;
return async () => {
await killAllRegisteredProcesses();
config.cleanupFn();
};
});
Notice that beforeAll
returns a function, which will be executed after the test completes either with success or failure.
Both config.cleanupFn();
and killAllRegisteredProcesses
there are extremely important:
config.cleanupFn()
is used in order to remove temporary folder with generated project after the test is executed (again, it's not being removed ifTEMP_E2E_PATH
is provided).killAllRegisteredProcesses
should be used to remove any active ports as we are serving the app during the test execution. Processes are being registered internally whenrunCommandUntil
is executed. If you're executing something manually, you can useregisterExecutedChildProcess
utility to register the process. DespitekillAllRegisteredProcesses
will kill all processes when test exists, it is also a good practice to kill the process manually within theit
statement usingawait promisifiedTreeKill(yourChildProcess.pId, 'SIGKILL')
Right now we have only one test file within this project. This means only one test application will be created and used, which is good from the execution time standpoint. If more files are added, it shouldn't potentially be a problem as we have fileParallelism: false
set in the vite.config.ts
, which means only one test will be executed at a time. This obviously slows down the execution time, but is safer, because we're working with a real file system.