Migrate example tests for Web Test Runner#1298
Conversation
| <script> | ||
| var domainsBlocked = ['localhost']; | ||
|
|
||
| function ignoreFilesUncaught(isUncaught, args, payload) { | ||
| try { | ||
| var filename = payload.data.body.trace.frames[0].filename; | ||
|
|
||
| var isBlocked = domainsBlocked.some(function (domain) { | ||
| return filename.indexOf(domain) !== -1; | ||
| }); | ||
|
|
||
| if (isUncaught && isBlocked) { | ||
| console.log('Ignoring error from ' + filename); | ||
| return true; | ||
| } | ||
| } catch (e) { | ||
| console.error(e); | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| var _rollbarConfig = { | ||
| let _rollbarConfig = { | ||
| accessToken: 'POST_CLIENT_ITEM_TOKEN', | ||
| rollbarJsUrl: '/dist/rollbar.js', | ||
| captureUncaught: true, | ||
| //checkIgnore: ignoreFilesUncaught, | ||
| payload: { | ||
| environment: 'test', | ||
| }, | ||
| }; | ||
| </script> |
There was a problem hiding this comment.
This script wasn't being used.
| <title>Webpack Example</title> | ||
|
|
||
| <script src="../dist/bundle.js"></script> | ||
| <script src="/examples/webpack/dist/bundle.js"></script> |
There was a problem hiding this comment.
WTR/Playwright quirk, uses project root not current dir
| // Karma headless chrome won't dispatch DOMContentLoaded, | ||
| // so we need to do it manually. | ||
| var event = document.createEvent('Event'); | ||
| event.initEvent('DOMContentLoaded', true, true); | ||
| document.dispatchEvent(event); | ||
| // DOMContentLoaded is not dispatched automatically in WTR/Playwright | ||
| document.dispatchEvent(new Event('DOMContentLoaded', { bubbles: true })); |
There was a problem hiding this comment.
event.initEvent is deprecated.
| setTimeout(function () { | ||
| done(); | ||
| }, 1000); | ||
| await setTimeout(250); |
There was a problem hiding this comment.
1s wait is unnecessary and slows the test down, 10 is enough, left 250 just in case.
| // Prevent WTR/Mocha from failing the test on uncaught errors. | ||
| __originalOnError = window.onerror; | ||
| window.onerror = () => false; |
There was a problem hiding this comment.
We store the original error and replace it with one that just returns false to signal the exception has been handled and to prevent propagation. Then Rollbar will swap its onerror with this one instead of WTR/Mocha/React's.
| document.write(window.__html__['examples/universal-browser/test.html']); | ||
| await loadHtml('examples/universal-browser/test.html'); |
There was a problem hiding this comment.
write is deprecated. window.__html__ is Karma magic, so we needed a new way to load HTML.
| # 1. there being minified snippets all over the place and | ||
| # 2. some tests fail cause they depend on some sources being exactly as they are | ||
| examples | ||
| !test/examples |
There was a problem hiding this comment.
prettify was ignoring js files in test/examples.
* Initial Karma to Web Test Runner migration (#1289) * Fix hanging tests and expand WTR migration (#1295) * Migrate example tests for Web Test Runner (#1298) * Migrate browser transform and core tests for Web Test Runner (#1299) * Migrate browser tests from Karma to Web Test Runner (#1300) * Initial migration of react native tests (#1301) * Remove Grunt and Karma (#1302)
Caution
This PR is being merged into a feature branch:
matux/wtr.Note
Multiple comments in the diff with details/reasoning about specific changes.
Description of the change
This PR completes the migration of example tests from Karma to Web Test Runner, fixing critical issues with loading HTML fixtures and handling uncaught errors.
New Test Utilities
test/util/fixtures.js: AddedloadHtmlhelper to load HTML fixtures in a WTR/Playwright-friendly way with proper script handlingtest/util/timers.js: Added promise-basedsetTimeoutto avoid cases where bothawaitanddonewere needed (which is illegal).Migrated Example Tests
test/examples/react.test.js: Migrated React example test with proper uncaught error handlingtest/examples/universalBrowser.test.js: Migrated universal browser testtest/examples/universalBrowserConfig.test.js: Migrated universal browser config testtest/examples/webpack.test.js: Migrated webpack example testFixes
Test Results
Technical Notes
The main two challenges were
window.onerrorhandler that fails tests on any uncaught error. This conflicted with tests verifying Rollbar's error catching. Solution: temporarily disable Mocha's handler during these tests, allowing Rollbar to catch errors without WTR interference.Related issues
SDK-493/replace-karma-with-webtest-runner-for-modern-performant-browser