Skip to content

Commit

Permalink
Enable more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bglw committed May 25, 2022
1 parent d395f90 commit 630d88c
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 11 deletions.
53 changes: 48 additions & 5 deletions pagefind/features/exclusions.feature
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
@skip
Feature: Exclusions

Scenario: Elements within search regions can be excluded from indexing and excerpts
Expand All @@ -10,8 +9,11 @@ Feature: Exclusions
Given I have a "public/cat/index.html" file with the content:
"""
<body>
<p>Hello World, from Pagefind</p>
<p>Hello World, from <span data-pagefind-ignore>not</span> Pagefind</p>
<p data-pagefind-ignore>Goodbye</p>
<div data-pagefind-ignore>
<p>Nested content</p>
</div>
<p>Huzzah!</p>
</body>
"""
Expand All @@ -26,11 +28,52 @@ Feature: Exclusions
let searchone = await pagefind.search("hello");
let searchonedata = await searchone[0].data();
document.querySelector('[search-one]').innerText = searchonedata.content;
document.querySelector('[data-search-one]').innerText = searchonedata.content;
let searchtwo = await pagefind.search("goodbye");
document.querySelector('[data-search-two]').innerText = `${searchtwo.length} result(s)`;
}
"""
Then The selector "[data-search-one]" should contain "Hello World, from Pagefind. Huzzah!"
Then The selector "[data-search-two]" should contain "0 result(s)"

Scenario: Some elements are excluded automatically
Given I have a "public/index.html" file with the content:
"""
<p data-search-one></p>
<p data-search-two></p>
"""
Given I have a "public/cat/index.html" file with the content:
"""
<body>
<p>Hello World, from Pagefind</p>
<script>let value = "Goodbye";</script>
<svg>goodbye</svg>
<form>
<label>
Goodbye
<input type="goodbye" />
</label>
</form>
<p>Hooray!</p>
</body>
"""
When I run my program
Then I should see "Running Pagefind" in stdout
When I serve the "public" directory
When I load "/"
When I evaluate:
"""
async function() {
let pagefind = await import("/_pagefind/pagefind.js");
let searchone = await pagefind.search("hello");
let searchonedata = await searchone[0].data();
document.querySelector('[data-search-one]').innerText = searchonedata.content;
let searchtwo = await pagefind.search("goodbye");
document.querySelector('[search-two]').innerText = `${searchtwo.length} result(s)`;
document.querySelector('[data-search-two]').innerText = `${searchtwo.length} result(s)`;
}
"""
Then The selector "[data-search-one]" should contain "Hello World, from Pagefind\nHuzzah!"
Then The selector "[data-search-one]" should contain "Hello World, from Pagefind. Hooray!"
Then The selector "[data-search-two]" should contain "0 result(s)"
4 changes: 4 additions & 0 deletions pagefind/features/spellcheck.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@skip
Feature: Spellcheck

Scenario: Spelling correction can be returned for the unique words in the dataset
18 changes: 12 additions & 6 deletions pagefind/features/stemming.feature
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
@skip
Feature: Word Stemming
Background:
Given I have a "public/index.html" file with the content:
"""
<ul>
<li data-result>
</ul>
"""

Scenario: Searching for a word will match against the stem of that word
Given I have a "public/cat/index.html" file with the content:
Expand All @@ -21,10 +27,10 @@ Feature: Word Stemming
let results = await pagefind.search("meowed");
let data = await results[0].data();
document.querySelector('[data-url]').innerText = data.url;
document.querySelector('[data-result]').innerText = data.url;
}
"""
Then The selector "[data-url]" should contain "/cat/"
Then The selector "[data-result]" should contain "/cat/"

Scenario: Search is case independent
Given I have a "public/cat/index.html" file with the content:
Expand All @@ -43,11 +49,11 @@ Feature: Word Stemming
async function() {
let pagefind = await import("/_pagefind/pagefind.js");
let results = await pagefind.search("meOWer");
let results = await pagefind.search("meOWings");
let data = await results[0].data();
document.querySelector('[data-url]').innerText = data.url;
document.querySelector('[data-result]').innerText = data.url;
}
"""
Then The selector "[data-url]" should contain "/cat/"
Then The selector "[data-result]" should contain "/cat/"

1 change: 1 addition & 0 deletions pagefind/src/output/stubs/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class Pagefind {
async search(term) {
let start = Date.now();
let ptr = await this.getPtr();
term = term.toLowerCase();

let chunks = this.backend.request_indexes(ptr, term);
await Promise.all(chunks.split(' ').map(chunk => this.loadChunk(chunk)));
Expand Down

0 comments on commit 630d88c

Please sign in to comment.