Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: #3737 #3738

Merged
merged 1 commit into from
Sep 14, 2021
Merged

fix: #3737 #3738

merged 1 commit into from
Sep 14, 2021

Conversation

AyushRawal
Copy link
Contributor

return valid json with npm search module_not_exists --json

References

Fixes #3737

@AyushRawal AyushRawal requested a review from a team as a code owner September 11, 2021 08:10
@wraithgar
Copy link
Member

Can a test be added to test/lib/search.js that covers this case?

@AyushRawal
Copy link
Contributor Author

AyushRawal commented Sep 14, 2021

@wraithgar Does this look good ?

t.test('search <invalid-module> --json', (t) => {
  const src = new Minipass()
  src.objectMode = true

  npm.flatOptions.json = true
  config.json = true
  const libnpmsearch = {
    stream () {
      return src
    },
  }

  const Search = t.mock('../../lib/search.js', {
    ...mocks,
    libnpmsearch,
  })
  const search = new Search(npm)

  search.exec(['foo'], (err) => {
    if (err)
      throw err

    t.equal(result, '\n[]\n', 'should have expected empty square brackets')

    config.json = false
    t.end()
  })

  src.end()
})

@wraithgar
Copy link
Member

Yeah I think that should do it, a src that ends w/o sending any data, that's the code path here.

@darcyclarke darcyclarke added semver:patch semver patch level for changes Release 7.x work is associated with a specific npm 7 release labels Sep 14, 2021
@wraithgar wraithgar self-assigned this Sep 14, 2021
@wraithgar wraithgar changed the base branch from latest to release-next September 14, 2021 21:08
@wraithgar wraithgar merged commit b807cd6 into npm:release-next Sep 14, 2021
@fritzy fritzy mentioned this pull request Sep 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Release 7.x work is associated with a specific npm 7 release semver:patch semver patch level for changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] npm search module_does_not_exist --json returns invalid JSON
3 participants