Skip to content

Commit b81b294

Browse files
committed
test(integration): Add custom site for testing plugin integration
1 parent 92d34b8 commit b81b294

File tree

14 files changed

+184
-14
lines changed

14 files changed

+184
-14
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ coverage/
55
docs-dev/
66
gemfiles/*.lock
77
spec/site/_site
8+
spec/integration/site/_site
89

910

1011
.DS_Store

scripts/test_integration_prepare

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ if [[ -z "$ALGOLIA_INDEX_NAME" ]]; then
1515
fi
1616

1717

18-
cd ./spec/site
18+
cd ./spec/integration/site
1919
bundle install --quiet
2020

2121
bundle exec jekyll build --trace

spec/integration/main_spec.rb

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,31 @@
22

33
require_relative './spec_helper'
44

5+
# rubocop:disable Metrics/BlockLength
56
describe('pushed index') do
67
before(:all) do
78
@index = Algolia::Index.new(ENV['ALGOLIA_INDEX_NAME'])
89
end
910

1011
describe('built website') do
12+
# Files excluded from indexing should still be written on disk
1113
it { should have_file('404.html') }
1214
it { should have_file('index.html') }
1315
end
1416

15-
describe 'nbHits' do
16-
subject { @index.search('', distinct: distinct)['nbHits'] }
17-
18-
context 'by default' do
19-
let(:distinct) { nil }
20-
it { should eq 35 }
17+
# Custom hooks are executed, even if github-pages is added as a gem
18+
describe 'hooks' do
19+
describe 'exclude a file through should_be_excluded?' do
20+
subject { @index.search('iamexcludedthroughhooks')['hits'].length }
21+
it { should eq 0 }
2122
end
22-
context 'with distinct:true' do
23-
let(:distinct) { true }
24-
it { should eq 35 }
23+
describe 'update all records through before_indexing_each' do
24+
subject { @index.search('')['hits'][0]['added_through_each'] }
25+
it { should eq true }
2526
end
26-
context 'with distinct:false' do
27-
let(:distinct) { false }
28-
it { should eq 72 }
27+
describe 'add a new record through before_indexing_all' do
28+
subject { @index.search('iamaddedthroughhooks')['hits'].length }
29+
it { should eq 1 }
2930
end
3031
end
3132

@@ -51,4 +52,22 @@
5152
it { should eq 'Math symbols' }
5253
end
5354
end
55+
56+
describe 'nbHits' do
57+
subject { @index.search('', distinct: distinct)['nbHits'] }
58+
59+
context 'by default' do
60+
let(:distinct) { nil }
61+
it { should eq 5 }
62+
end
63+
context 'with distinct:true' do
64+
let(:distinct) { true }
65+
it { should eq 5 }
66+
end
67+
context 'with distinct:false' do
68+
let(:distinct) { false }
69+
it { should eq 9 }
70+
end
71+
end
5472
end
73+
# rubocop:enable Metrics/BlockLength

spec/integration/site/404.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
title: 404 Not Found
3+
---
4+
5+
This is a classical error page, as suggested by
6+
[GitHub pages](https://help.github.com/articles/creating-a-custom-404-page-for-your-github-pages-site/).
7+
8+
It should not be indexed.
9+

spec/integration/site/Gemfile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# frozen_string_literal: true
2+
3+
source 'https://rubygems.org'
4+
5+
gem 'jekyll', '~> 3.7.3'
6+
7+
gem 'minima', '~> 2.0'
8+
9+
group :jekyll_plugins do
10+
gem 'github-pages', '~> 183'
11+
gem 'jekyll-algolia', path: '../../../'
12+
gem 'jekyll-feed', '~> 0.6'
13+
gem 'jekyll-paginate', '~> 1.1'
14+
gem 'jekyll-tagging', '~> 1.1'
15+
end
16+
17+
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
18+
gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw jruby]

spec/integration/site/_config.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
collections:
2+
my-collection:
3+
output: true
4+
timezone: Europe/Paris
5+
remote_theme: "mmistakes/minimal-mistakes"
6+
7+
algolia:
8+
application_id: APPID
9+
index_name: INDEXNAME
10+
files_to_exclude:
11+
- index.html
12+
- excluded.html
13+
- excluded_dir/*.html
14+
settings:
15+
attributesToSnippet: ['content:10']
16+
separatorsToIndex: '∀λ→'
17+
18+
# jekyll-paginate lets you define the path to the pagination pages
19+
paginate: 5
20+
paginate_path: "/blog/pages/:num"
21+
22+
# jekyll-tagging lets you define where to save the tag files
23+
tag_page_layout: tag
24+
tag_page_dir: tags
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
title: Sample item
3+
---
4+
5+
This is a sample item
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# frozen_string_literal: true
2+
3+
module Jekyll
4+
module Algolia
5+
# Custom user hooks
6+
module Hooks
7+
def self.should_be_excluded?(filepath)
8+
filepath == 'excluded-from-hook.html'
9+
end
10+
11+
def self.before_indexing_each(record, _node, _context)
12+
record[:added_through_each] = true
13+
record
14+
end
15+
16+
def self.before_indexing_all(records, _context)
17+
records << {
18+
content: 'Added through hooks [iamaddedthroughhooks]'
19+
}
20+
records
21+
end
22+
end
23+
end
24+
end
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
title: "Test post"
3+
tags:
4+
- tag
5+
- another tag
6+
categories:
7+
- foo
8+
- bar
9+
custom: Foo
10+
---
11+
12+
Introduction text that also includes [some link](https://www.algolia.com). To
13+
add a bit of fancy, we will also __bold__ and _italicize_ some text.
14+
15+
# Main title
16+
17+
We like writing stuff and then indexing it in a very fast engine. Here is why
18+
a fast engine is good for you:
19+
20+
* fast
21+
* fast
22+
* fast
23+
* and fast
24+
25+
## Built with hands
26+
27+
All this text was typed with my own hands, on my own keyboard. I also did use
28+
a Chair© and a Table™.
29+
30+
## Features
31+
32+
The whole plugin is composed of parts of `code`, and sometime even
33+
<code>&lt;code&gt;</code>.
34+
35+
Code is __✔ checked__ and errors are __✘ deleted__.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
title: Excluded file
3+
---
4+
5+
<p>This should not be indexed because it is specifically excluded with a user hook</p>
6+
7+
<p>iamexcludedhroughhooks</p>

0 commit comments

Comments
 (0)