Add Jest unit test suite for the GF-1 library - #5
Open
devin-ai-integration[bot] wants to merge 1 commit into
Open
Add Jest unit test suite for the GF-1 library#5devin-ai-integration[bot] wants to merge 1 commit into
devin-ai-integration[bot] wants to merge 1 commit into
Conversation
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The repo had no tests, no test runner and no CI: coverage of every module was 0%.
JS/GF-1.js(~60 KB, 123 functions) is the whole library and was therefore the least covered module by far, so this PR adds a Jest + jsdom suite around it — 206 tests, 98% of its functions and 66% of its statements executed — plus a GitHub Actions workflow that runs it.JS/GF-1.jsis a plain browser script: every function is a top-level declaration and nothing is exported, sorequire()-ing it from a test yields an empty object. Rather than modifying the shipped source,tests/gf-transform.jsis a Jest transformer that appends an export epilogue at transform time and delegates tobabel-jestso Istanbul instrumentation (and thus the coverage report) still applies:The
setRunConsoleescape hatch letstests/logging.test.jsflip the library'srun_consoleflag and assert on the_writeLogdiagnostics, which are otherwise dead code.Suites, by area of the library:
tests/type-utils.test.js_isArray,_isFunction,_isUndefined,_vardump,_cleanArraytests/string-utils.test.js_checkEmail,_isUrl,_escapeHtml,_moneyFormat,_replaceJS/_replaceMaster/_returnMaster,_charToDec/_decToChar,_randomStr/_randomInt,_encryptInt/_decryptIntround triptests/date.test.js_getYear/_getMonth/_getDay/_getDate/_getDayName/_getMonthName/_getTimetests/dom.test.js_getById,_printTo,_clear,_setValue,_getValById/_getValByName, visibility helpers,_required,_qSelector*,_textStyletests/components.test.js_addList,_addItemTable,_addOption/_getOptiontests/cookie-storage.test.js_setCookie/_getCookie/_deleteCookie,_saveStorage/_getStorage(incl. the{id,status,token,ip,key}object form)tests/events.test.js_keyArrow,_keyCustom,_onKeyUpToText,_rightClicktests/ajax.test.js_requestGET/POST/PUT/DELETE,_loadDoc,_checkInternet,_importagainst a fakeXMLHttpRequesttests/canvas.test.js_drawCircle/_drawText/_drawLine/_drawImage/_clearCanvasagainst a stubbed 2d contexttests/window-location.test.js_GET,_putUrl,_myUrl,_getHost, counters,_writeAlert,_animation,_confirm,_newTab/_newIframe,_writeLogtests/browser-window.test.js_detectBrowser,_openUrl/_refresh,_getLocation,_newForm/_print,_previewImage, scroll helperstests/logging.test.jsrun_consolediagnostic paths and the_gDataclassTests assert the library's current behaviour, including its quirks (e.g.
_getCookiereturnsfalsewhen the requested cookie isn't the first one,_showMesetsvisibility: block); no library code was changed, so nothing is fixed here — the suite pins today's behaviour so future changes are safe.app.jsandcode/part-*.jsare page-specific demo scripts bound to the documentation site's DOM ids, so they are excluded fromcollectCoverageFromrather than tested.Link to Devin session: https://app.devin.ai/sessions/1c87befeef8849768a3adcdc8d231ff2
Requested by: @lamhotsimamora