Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/docs/filters/socketio/entries.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ def get_type
def additional_entries
return [] unless slug.end_with?('api')

css('h3').each_with_object([]) do |node, entries|
# In v4 the h3 headings group API members, except for the top-level io entries.
selector = version == '4' ? 'h3[id^="io"], h4[id]' : 'h3'
css(selector).each_with_object([]) do |node, entries|
name = node.content

entries << [name, node['id'], self.name.remove(' API')]
Expand Down
2 changes: 1 addition & 1 deletion lib/docs/scrapers/socketio.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Socketio < UrlScraper
HTML

version '4' do
self.release = '4.5.2'
self.release = '4.8.4'
self.base_url = "https://socket.io/docs/v#{version}"
end

Expand Down
38 changes: 38 additions & 0 deletions test/lib/docs/scrapers/socketio_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
require_relative '../../../test_helper'
require_relative '../../../../lib/docs'

class SocketioScraperTest < Minitest::Test
def test_indexes_v4_api_members_without_the_group_headings
result = scrape('4', <<~HTML)
<h3 id="iourl">io([url][, options])</h3>
<h3 id="methods">Methods</h3>
<h4 id="socketemitwithackeventname-args">socket.emitWithAck(eventName[, ...args])</h4>
HTML

entries = result[:entries].map { |entry| [entry.name, entry.path, entry.type] }
assert_equal [
['Client API', 'client-api', 'Guides'],
['io([url][, options])', 'client-api#iourl', 'Client'],
['socket.emitWithAck(eventName[, ...args])', 'client-api#socketemitwithackeventname-args', 'Client']
], entries
assert Nokogiri::HTML.fragment(result[:output]).at_css('h4#socketemitwithackeventname-args')
end

def test_keeps_v3_api_members_indexed_at_their_existing_heading_level
result = scrape('3', '<h3 id="socketemit">socket.emit()</h3>')

member = result[:entries].last
assert_equal 'socket.emit()', member.name
assert_equal 'client-api#socketemit', member.path
assert_equal 'Client', member.type
end

private

def scrape(version, headings)
scraper = Docs::Socketio.versions.find { |item| item.version == version }.new
context = scraper.options.merge(url: Docs::URL.parse("https://socket.io/docs/v#{version}/client-api"), download_images: false)
html = "<article><div class=\"theme-doc-markdown\"><h1>Client API</h1>#{headings}</div></article>"
scraper.pipeline.call(Docs::Parser.new(html).html, context)
end
end