Karma integration test for @lwc/compiler, @lwc/engine-dom, and @lwc/synthetic-shadow.
Starts the Karma server in watch mode and start Google Chrome. Note that you can open different browsers to run the tests in parallel on all the browsers. While the server in running, updating a fixture will trigger the suite to run.
Starts the Karma server in watch mode and start Google Chrome, to run the hydration test suite. Note that you can open different browsers to run the tests in parallel on all the browsers. While the server in running, updating a fixture will trigger the suite to run.
Run the test suite a single time on Google Chrome.
Run the hydration test suite a single time on Google Chrome.
Combine the coverage produced by the different runs into a single coverage report.
Every time the test suite runs with the COVERAGE=1 environment variable it produces a folder based on the run configuration and browser, in the coverage/ folder. Running the coverage command merge all the coverages files in the into a single report in the coverage/combined folder.
This set of environment variables applies to the start and test commands:
LEGACY_BROWSERS=1: Run SauceLabs tests in legacy browsers.DISABLE_SYNTHETIC=1: Run without any synthetic shadow polyfill patches.FORCE_NATIVE_SHADOW_MODE_FOR_TEST=1: Force tests to run in native shadow mode with synthetic shadow polyfill patches.ENABLE_ARIA_REFLECTION_GLOBAL_POLYFILL=1: ARIA string reflection as a global polyfill.NODE_ENV_FOR_TEST: Set theNODE_ENVto be used for the tests (at runtime, in the browser).COVERAGE=1: Gather engine code coverage, and store it in thecoveragefolder.GREP="pattern": Filter the spec to run based on the pattern.API_VERSION=<version>: API version to use when compiling.DISABLE_SYNTHETIC_SHADOW_SUPPORT_IN_COMPILER=1: Disable synthetic shadow in the compiler itself.DISABLE_STATIC_CONTENT_OPTIMIZATION=1: Disable static content optimization by settingenableStaticContentOptimizationtofalse.ENABLE_EXPERIMENTAL_SIGNALS=1: Enables tests for experimental signals protocol.
DISABLE_SYNTHETIC=1 yarn test # Run tests without any synthetic shadow polyfills
GREP=ShadowRoot yarn start # Run "ShadowRoot" related tests in watch mode
COVERAGE=1 yarn test # Compute coverage after a single test runTo test Sauce Labs the same way we do in CI, run the following steps:
Start the Sauce Connect (sc) executable and wait for it to say that it's ready. (When you sign into SauceLabs, on the "Tunnel Proxies" page, there is a command you can copy-paste.)
In another console tab, start the tests using yarn start.
In another console tab, export the following env vars:
SAUCE_USERNAMESAUCE_KEYSAUCE_TUNNEL_ID– this is actually your tunnel name, not the ID. Copy it from thesccommand you just ran.
Run:
npx karma start ./scripts/karma-configs/test/sauce.js --single-runThis will connect to Sauce Labs, start the browser, and run the tests.
You can also pass in --log-level=debug to karma for debug logging.
- The test suite uses jasmine for test runner. You can find more details about jasmine here: https://jasmine.github.io/api/3.3/global
- On top of the standard jasmine matchers, the test suite also register custom matchers:
toLogErrorDev(message):expecta function to log an error with a specific message in DEV only.toThrowErrorDev(Error, message):expecta function to throw an error with a specific Error constructor and a specific message.
- Some of the test command options are available in the test suite on the global
process.envobject:process.env.DISABLE_SYNTHETIC: is set tofalseby default andtrueif theDISABLE_SYNTHETICenvironment variable is set.FORCE_NATIVE_SHADOW_MODE_FOR_TEST: is set tofalseby default andtrueif theFORCE_NATIVE_SHADOW_MODE_FOR_TESTenvironment variable is set.
- The test setup file (
test-setup.js) will automatically clean up the DOM before and after each test. So you don't have to do anything to clean up. However, you should usebeforeEach()rather thanbeforeAll()to add DOM elements for your test, so that the cleanup code can properly clean up the DOM.