Skip to content

Commit

Permalink
Spec out tests, implement bundle dir
Browse files Browse the repository at this point in the history
  • Loading branch information
bglw committed May 20, 2022
1 parent 3efb250 commit 8f0322c
Show file tree
Hide file tree
Showing 20 changed files with 510 additions and 57 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ jobs:
- name: Test CLI
working-directory: ./pagefind
run: TEST_BINARY=../target/release/pagefind cargo test --release
run: TEST_BINARY=../target/release/pagefind cargo test --release --test cucumber -- -c 16 --tags "not @skip"
- name: Build
working-directory: ./pagefind
run: RELEASE_VERSION=${GITHUB_REF#refs/tags/} cargo build --release --target ${{ matrix.target }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,4 @@ jobs:

- name: Test CLI
working-directory: ./pagefind
run: TEST_BINARY=../target/release/pagefind cargo test --release
run: TEST_BINARY=../target/release/pagefind cargo test --release --test cucumber -- -c 16 --tags "not @skip"
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## Tests

- `TEST_BINARY=../target/release/pagefind cargo test --release`
- `TEST_BINARY=../target/release/pagefind cargo test --release --test cucumber -- -c 16 --tags "not @skip"`
- `TEST_BINARY=../target/release/pagefind cargo test --release --test cucumber -- --name "<test>"`
57 changes: 30 additions & 27 deletions pagefind/features/base.feature
Original file line number Diff line number Diff line change
@@ -1,29 +1,32 @@
Feature: Base Tests
Background:
Given I have a "public/index.html" file with the content:
"""
<p data-url>
</p>
"""

Scenario: Search for a word
Given I have a "public/index.html" file with the content:
"""
<p data-url>
</p>
"""
Given I have a "public/cat/index.html" file with the content:
"""
<body>
<h1>world</h1>
</body>
"""
When I run my program
Then DEBUG I should see "Running Pagefind" in stdout
Then I should see the file "public/_pagefind/pagefind.js"
When I serve the "public" directory
When I load "/"
When I evaluate:
"""
async function() {
let pagefind = await import("/_pagefind/pagefind.js");
let results = await pagefind.search("world");
let data = await results[0].data();
document.querySelector('[data-url]').innerText = data.url;
}
"""
Then The selector "[data-url]" should contain "/cat/"
Scenario: Search for a word
Given I have a "public/cat/index.html" file with the content:
"""
<body>
<h1>world</h1>
</body>
"""
When I run my program
Then I should see "Running Pagefind" in stdout
Then I should see the file "public/_pagefind/pagefind.js"
When I serve the "public" directory
When I load "/"
When I evaluate:
"""
async function() {
let pagefind = await import("/_pagefind/pagefind.js");
let results = await pagefind.search("world");
let data = await results[0].data();
document.querySelector('[data-url]').innerText = data.url;
}
"""
Then The selector "[data-url]" should contain "/cat/"
75 changes: 75 additions & 0 deletions pagefind/features/build_options.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
Feature: Build Options

@skip
Scenario: Settings can be pulled from configuration files

@skip
Scenario: Settings can be pulled from commandline flags

@skip
Scenario: Settings can be pulled from environment variables

Scenario: Source folder can be configured
Given I have a "my_website/index.html" file with the content:
"""
<p data-url>
</p>
"""
Given I have a "my_website/cat/index.html" file with the content:
"""
<body>
<h1>world</h1>
</body>
"""
When I run my program with the flags:
| --source my_website |
Then I should see "Running Pagefind" in stdout
Then I should see the file "my_website/_pagefind/pagefind.js"
When I serve the "my_website" directory
When I load "/"
When I evaluate:
"""
async function() {
let pagefind = await import("/_pagefind/pagefind.js");
let results = await pagefind.search("world");
let data = await results[0].data();
document.querySelector('[data-url]').innerText = data.url;
}
"""
Then The selector "[data-url]" should contain "/cat/"

Scenario: Output path can be configured
Given I have a "public/index.html" file with the content:
"""
<p data-url>
</p>
"""
Given I have a "public/cat/index.html" file with the content:
"""
<body>
<h1>world</h1>
</body>
"""
When I run my program with the flags:
| --bundle_dir _search |
Then I should see "Running Pagefind" in stdout
Then I should see the file "public/_search/pagefind.js"
When I serve the "public" directory
When I load "/"
When I evaluate:
"""
async function() {
let pagefind = await import("/_search/pagefind.js");
let results = await pagefind.search("world");
let data = await results[0].data();
document.querySelector('[data-url]').innerText = data.url;
}
"""
Then The selector "[data-url]" should contain "/cat/"

@skip
Scenario: Selector used for indexing can be configured
104 changes: 103 additions & 1 deletion pagefind/features/exact_phrase.feature
Original file line number Diff line number Diff line change
@@ -1,5 +1,107 @@
@skip
Feature: Exact Phrase Matching
Background:
Given I have a "public/index.html" file with the content:
"""
<p data-count></p>
<p data-result></p>
"""

Scenario: Searching in quotes will return pages with exact matches
Scenario: Exact matches will be discouraged across sentence boundaries
Given I have a "public/cat/index.html" file with the content:
"""
<body>
<h1>Happy post about cats</h1>
</body>
"""
Given I have a "public/dog/index.html" file with the content:
"""
<body>
<h1>A post about how cats do not like dogs</h1>
</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 results = await pagefind.search(`"about cats"`);
document.querySelector('[data-count]').innerText = `${results.length} result(s)`;
let data = await results[0].data();
document.querySelector('[data-result]').innerText = data.url;
}
"""
Then The selector "[data-count]" should contain "1 result(s)"
Then The selector "[data-result]" should contain "/cat/"

Scenario: Exact matches will be discouraged across element boundaries
Given I have a "public/catone/index.html" file with the content:
"""
<body>
<p>Happy post</p>
<p>about cats</p>
</body>
"""
Given I have a "public/cattwo/index.html" file with the content:
"""
<body>
<p>Happy post about cats</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 results = await pagefind.search(`"post about"`);
document.querySelector('[data-count]').innerText = `${results.length} result(s)`;
let data = await results[0].data();
document.querySelector('[data-result]').innerText = data.url;
}
"""
Then The selector "[data-count]" should contain "1 result(s)"
Then The selector "[data-result]" should contain "/cattwo/"

Scenario: Exact matches will match across stop words
Given I have a "public/cat/index.html" file with the content:
"""
<body>
<h1>Happy post about the cats</h1>
</body>
"""
# This file will _also_ match, due to our stop word culling
Given I have a "public/dog/index.html" file with the content:
"""
<body>
<h1>A post not about happy cats</h1>
</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 results = await pagefind.search(`"about the cats"`);
document.querySelector('[data-count]').innerText = `${results.length} result(s)`;
let data = await Promise.all(results.map(result => result.data()));
document.querySelector('[data-result]').innerText = data.map(d => d.url).join(', ');
}
"""
Then The selector "[data-count]" should contain "2 result(s)"
Then The selector "[data-result]" should contain "/cat/, /dog/"

36 changes: 36 additions & 0 deletions pagefind/features/exclusions.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
@skip
Feature: Exclusions

Scenario: Elements within search regions can be excluded from indexing and excerpts
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>
<p data-pagefind-ignore>Goodbye</p>
<p>Huzzah!</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('[search-one]').innerText = searchonedata.content;
let searchtwo = await pagefind.search("goodbye");
document.querySelector('[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-two]" should contain "0 result(s)"
Loading

0 comments on commit 8f0322c

Please sign in to comment.