TESTING.md
Open MCT Testing is iterating and improving at a rapid pace. This document serves to capture and index existing testing documentation and house documentation which no other obvious location as our testing evolves.
Documentation located here
Unit testing is essential part of our test strategy and complements our e2e testing strategy.
beforeEach is preferable to beforeAll to avoid leaking of state between tests.afterEach or afterAll should be used to do any clean up necessary to prevent leakage of state between test specs. This can happen when functions on window are wrapped, or when the URL is changed. A convenience function is provided for resetting the URL and clearing builtin spies between tests.The unit tests can be executed in one of two ways:
npm run test which runs the entire suite against headless chrome
npm run test:debug for debugging the tests in realtime in an active chrome session.
Documentation located here
It's up to the individual developer as to whether they want to add line coverage in the form of a unit test or e2e test.
Line Code Coverage is generated by our unit tests and e2e tests, then combined by (Codecov.io Flags), and finally reported in GitHub PRs by Codecov.io's PR Bot. This workflow gives a comprehensive (if flawed) view of line coverage.
Line coverage is generated by our karma-coverage-istanbul-reporter package as defined in our karma.conf.js file:
coverageIstanbulReporter: {
fixWebpackSourcePaths: true,
skipFilesWithNoCoverage: true,
dir: 'coverage/unit', //Sets coverage file to be consumed by codecov.io
reports: ['lcovonly']
},
Once the file is generated, it can be published to codecov with
"cov:unit:publish": "codecov --disable=gcov -f ./coverage/unit/lcov.info -F unit",
The e2e line coverage is a bit more complex than the karma implementation. This is the general sequence of events:
npm run start:coverage command with config webpack.coverage.mjs and the babel-plugin-istanbul plugin to generate code coverage during e2e test execution using our custom baseFixture..nyc_report directory.lcov file with the following command npm run cov:e2e:reportnpm run cov:e2e:ci:publish.npm run cov:e2e:full:publish flag. Since this happens about once a day, we have leveraged codecov.io's carryforward flag to report on lines covered outside of each commit on an individual PR.Our code coverage implementation has some known limitations:
The following is an evolving guide to troubleshoot CI and PR issues.
There are a few reasons that your GitHub PR could be failing beyond simple failed tests.
(Required) emblem next to the step details in GitHub Checks.pr:<label> label added to your PR.(CircleCI's test insights feature)[https://circleci.com/blog/introducing-test-insights-with-flaky-test-detection/] collects historical data about the individual test results for both unit and e2e tests. Note: only a 14 day window of flake is available.
Although rare, it is possible that your test can pass locally but fail in CI.
It's possible that you're running with dependencies or a local environment which is out of sync with the branch you're working on. Make sure to execute the following:
nvm use
npm run clean
npm install
In extreme cases, tests can fail due to the constraints of running within a container. To execute tests in exactly the same way as run in CircleCI.
// Replace {X.X.X} with the current Playwright version
// from our package.json or circleCI configuration file
docker run --rm --network host --cpus="2" -v $(pwd):/work/ -w /work/ -it mcr.microsoft.com/playwright:v{X.X.X}-focal /bin/bash
npm install
At this point, you're running inside the same container and with 2 cpu cores. You can specify the unit tests:
npm run test
or e2e tests:
npx playwright test --config=e2e/playwright-ci.config.js --project=chrome --grep <the testcase name>