Skip to content

Add Jest unit test suite for the GF-1 library - #5

Open
devin-ai-integration[bot] wants to merge 1 commit into
masterfrom
devin/1784999981-jest-unit-tests
Open

Add Jest unit test suite for the GF-1 library#5
devin-ai-integration[bot] wants to merge 1 commit into
masterfrom
devin/1784999981-jest-unit-tests

Conversation

@devin-ai-integration

Copy link
Copy Markdown

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.js is a plain browser script: every function is a top-level declaration and nothing is exported, so require()-ing it from a test yields an empty object. Rather than modifying the shipped source, tests/gf-transform.js is a Jest transformer that appends an export epilogue at transform time and delegates to babel-jest so Istanbul instrumentation (and thus the coverage report) still applies:

// tests/gf-transform.js
process(src, path, options) {
  const names = [...src.matchAll(/function\s+(_[A-Za-z0-9_]*)\s*\(/g)].map(m => m[1]);
  const epilogue = `;module.exports = { ${names}, _gData, _error_message, ...,
     setRunConsole: v => { run_console = v; } };`;
  return babelTransformer.process(src + epilogue, path, options);
}

The setRunConsole escape hatch lets tests/logging.test.js flip the library's run_console flag and assert on the _writeLog diagnostics, which are otherwise dead code.

Suites, by area of the library:

file covers
tests/type-utils.test.js _isArray, _isFunction, _isUndefined, _vardump, _cleanArray
tests/string-utils.test.js _checkEmail, _isUrl, _escapeHtml, _moneyFormat, _replaceJS/_replaceMaster/_returnMaster, _charToDec/_decToChar, _randomStr/_randomInt, _encryptInt/_decryptInt round trip
tests/date.test.js _getYear/_getMonth/_getDay/_getDate/_getDayName/_getMonthName/_getTime
tests/dom.test.js _getById, _printTo, _clear, _setValue, _getValById/_getValByName, visibility helpers, _required, _qSelector*, _textStyle
tests/components.test.js _addList, _addItemTable, _addOption/_getOption
tests/cookie-storage.test.js _setCookie/_getCookie/_deleteCookie, _saveStorage/_getStorage (incl. the {id,status,token,ip,key} object form)
tests/events.test.js click/key/mouse/focus/drag handlers, _keyArrow, _keyCustom, _onKeyUpToText, _rightClick
tests/ajax.test.js _requestGET/POST/PUT/DELETE, _loadDoc, _checkInternet, _import against a fake XMLHttpRequest
tests/canvas.test.js _drawCircle/_drawText/_drawLine/_drawImage/_clearCanvas against a stubbed 2d context
tests/window-location.test.js _GET, _putUrl, _myUrl, _getHost, counters, _writeAlert, _animation, _confirm, _newTab/_newIframe, _writeLog
tests/browser-window.test.js _detectBrowser, _openUrl/_refresh, _getLocation, _newForm/_print, _previewImage, scroll helpers
tests/logging.test.js run_console diagnostic paths and the _gData class

Tests assert the library's current behaviour, including its quirks (e.g. _getCookie returns false when the requested cookie isn't the first one, _showMe sets visibility: block); no library code was changed, so nothing is fixed here — the suite pins today's behaviour so future changes are safe.

app.js and code/part-*.js are page-specific demo scripts bound to the documentation site's DOM ids, so they are excluded from collectCoverageFrom rather than tested.

Link to Devin session: https://app.devin.ai/sessions/1c87befeef8849768a3adcdc8d231ff2
Requested by: @lamhotsimamora

@lamhotsimamora lamhotsimamora self-assigned this Jul 25, 2026
@devin-ai-integration

Copy link
Copy Markdown
Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant