Skip to content

test: cover parser version request behavior#980

Open
999axel999 wants to merge 1 commit into
objectionary:masterfrom
999axel999:zerocracy/971-cover-parser-version-behaviors
Open

test: cover parser version request behavior#980
999axel999 wants to merge 1 commit into
objectionary:masterfrom
999axel999:zerocracy/971-cover-parser-version-behaviors

Conversation

@999axel999

Copy link
Copy Markdown

Summary

  • Replace the duplicate parser-version URL test with a request-stubbed assertion for the exact Maven Central POM URL and timeout options.
  • Replace the no-op network-error test with a request-stubbed failure that verifies exists() returns false from its catch branch.

Closes #971

Tests

  • node ..\objectionary__eoc_fix\node_modules\mocha\bin\mocha.js test\test_parser_version.js --grep 'constructs correct Maven Central URL|handles network errors gracefully' --timeout 1200000 -> 2 passing
  • node ..\objectionary__eoc_fix\node_modules\eslint\bin\eslint.js test\test_parser_version.js -> passed
  • git diff --check -> passed
  • git merge-tree --write-tree origin/master HEAD -> passed

@999axel999 999axel999 marked this pull request as ready for review June 7, 2026 02:47

@Thayorns Thayorns left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A test should inject the request collaborator through a constructor, not by hijacking require.

Also, this PR is a duplicate, the issue is closed already

* @param {Function} check Test callback
* @return {*} Callback result
*/
const withRequestStub = (request, check) => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would recommend to rename this function to be less composite

* Load parser-version with a temporary sync-request implementation.
* @param {Function} request Request stub
* @param {Function} check Test callback
* @return {*} Callback result

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The doc says @return {*} — returning an arbitrary passthrough invites null propagation

const withRequestStub = (request, check) => {
const parserPath = require.resolve(parserModule),
requestPath = require.resolve(requestModule),
originalParser = require.cache[parserPath],

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

require.cache — this is shared global state and reflection-like introspection of the module system (require.resolve, cache surgery). Type/internals introspection is prohibited

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.

Duplicate tests in test/test_parser_version.js provide false coverage for URL construction and network-error handling

2 participants