-
Notifications
You must be signed in to change notification settings - Fork 127
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add relevant tests to preserve pre-1.0 configuration options
- Loading branch information
Showing
10 changed files
with
1,014 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # | ||
# This file represents a backwards-compatible setup as it existed before 1.0 # | ||
# These tests should remain as a permanent regresison check for older sites # | ||
# It is very unlikely that the tests in this file should be touched # | ||
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # | ||
|
||
Feature: Base Tests | ||
Background: | ||
Given I have the environment variables: | ||
| PAGEFIND_SOURCE | public | | ||
Given I have a "public/index.html" file with the body: | ||
""" | ||
<p data-url>Nothing</p> | ||
""" | ||
|
||
Scenario: Search for a word | ||
Given I have a "public/cat/index.html" file with the body: | ||
""" | ||
<link rel="pre-1.0-signal" href="_pagefind" > | ||
<h1>world</h1> | ||
""" | ||
When I run my program | ||
Then I should see "Running Pagefind" in stdout | ||
Then I should see "pre-1.0 compatibility mode" in stderr | ||
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 search = await pagefind.search("world"); | ||
let data = await search.results[0].data(); | ||
document.querySelector('[data-url]').innerText = data.url; | ||
} | ||
""" | ||
Then There should be no logs | ||
Then The selector "[data-url]" should contain "/cat/" | ||
|
||
Scenario: Preload indexes then search for a word | ||
Given I have a "public/cat/index.html" file with the body: | ||
""" | ||
<link rel="pre-1.0-signal" href="_pagefind" > | ||
<h1>world</h1> | ||
""" | ||
When I run my program | ||
Then I should see "Running Pagefind" in stdout | ||
Then I should see "pre-1.0 compatibility mode" in stderr | ||
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"); | ||
await pagefind.preload("wo"); | ||
let search = await pagefind.search("world"); | ||
let data = await search.results[0].data(); | ||
document.querySelector('[data-url]').innerText = data.url; | ||
} | ||
""" | ||
Then There should be no logs | ||
Then The selector "[data-url]" should contain "/cat/" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,218 @@ | ||
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # | ||
# This file represents a backwards-compatible setup as it existed before 1.0 # | ||
# These tests should remain as a permanent regresison check for older sites # | ||
# It is very unlikely that the tests in this file should be touched # | ||
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # | ||
|
||
Feature: Build Options | ||
Background: | ||
Given I have the environment variables: | ||
| PAGEFIND_SOURCE | public | | ||
|
||
Scenario: Source folder can be configured | ||
Given I have a "my_website/index.html" file with the body: | ||
""" | ||
<link rel="pre-1.0-signal" href="_pagefind" > | ||
<p data-url>Nothing</p> | ||
""" | ||
Given I have a "my_website/cat/index.html" file with the body: | ||
""" | ||
<h1>world</h1> | ||
""" | ||
When I run my program with the flags: | ||
| --source my_website | | ||
Then I should see "Running Pagefind" in stdout | ||
Then I should see "pre-1.0 compatibility mode" in stderr | ||
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 search = await pagefind.search("world"); | ||
let data = await search.results[0].data(); | ||
document.querySelector('[data-url]').innerText = data.url; | ||
} | ||
""" | ||
Then There should be no logs | ||
Then The selector "[data-url]" should contain "/cat/" | ||
|
||
Scenario: Output path can be configured | ||
Given I have a "public/index.html" file with the body: | ||
""" | ||
<link rel="pre-1.0-signal" href="_pagefind" > | ||
<p data-url>Nothing</p> | ||
""" | ||
Given I have a "public/cat/index.html" file with the body: | ||
""" | ||
<h1>world</h1> | ||
""" | ||
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 search = await pagefind.search("world"); | ||
let data = await search.results[0].data(); | ||
document.querySelector('[data-url]').innerText = data.url; | ||
} | ||
""" | ||
Then There should be no logs | ||
Then The selector "[data-url]" should contain "/cat/" | ||
|
||
Scenario: Output path can be configured with an absolute path | ||
Given I have a "public/index.html" file with the body: | ||
""" | ||
<link rel="pre-1.0-signal" href="_pagefind" > | ||
<p data-url>Nothing</p> | ||
""" | ||
Given I have a "public/cat/index.html" file with the body: | ||
""" | ||
<h1>world</h1> | ||
""" | ||
# {{humane_temp_dir}} will be replaced with an absolute path here, | ||
# making the bundle-dir value absolute | ||
When I run my program with the flags: | ||
| --bundle-dir {{humane_temp_dir}}/other/_search | | ||
Then I should see "Running Pagefind" in stdout | ||
Then I should see the file "other/_search/pagefind.js" | ||
When I serve the "." directory | ||
When I load "/public/" | ||
When I evaluate: | ||
""" | ||
async function() { | ||
let pagefind = await import("/other/_search/pagefind.js"); | ||
let search = await pagefind.search("world"); | ||
let data = await search.results[0].data(); | ||
document.querySelector('[data-url]').innerText = data.url; | ||
} | ||
""" | ||
Then There should be no logs | ||
Then The selector "[data-url]" should contain "/cat/" | ||
|
||
Scenario: Root selector can be configured | ||
Given I have a "public/index.html" file with the body: | ||
""" | ||
<link rel="pre-1.0-signal" href="_pagefind" > | ||
<p data-url>Nothing</p> | ||
""" | ||
Given I have a "public/cat/index.html" file with the body: | ||
""" | ||
<h1>Ignored</h1> | ||
<div class="content"> | ||
<h1>Hello</h1> | ||
</div> | ||
<p data-pagefind-meta="ignored">Also ignored</p> | ||
""" | ||
When I run my program with the flags: | ||
| --root-selector "body > .content" | | ||
Then I should see "Running Pagefind" in stdout | ||
Then I should see "pre-1.0 compatibility mode" in stderr | ||
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 search = await pagefind.search("hello"); | ||
let data = await search.results[0].data(); | ||
document.querySelector('[data-url]').innerText = `${data.meta.title}, ${data.content} Ignored is ${data.meta.ignored}.`; | ||
} | ||
""" | ||
Then There should be no logs | ||
Then The selector "[data-url]" should contain "Hello, Hello. Ignored is undefined." | ||
|
||
Scenario: File glob can be configured | ||
Given I have a "public/index.html" file with the body: | ||
""" | ||
<link rel="pre-1.0-signal" href="_pagefind" > | ||
<p data-url>Nothing</p> | ||
""" | ||
Given I have a "public/cat/index.htm" file with the body: | ||
""" | ||
<h1>world</h1> | ||
""" | ||
Given I have a "pagefind.yml" file with the content: | ||
""" | ||
glob: "**/*.{htm,html}" | ||
""" | ||
When I run my program | ||
Then I should see "Running Pagefind" in stdout | ||
Then I should see "pre-1.0 compatibility mode" in stderr | ||
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 search = await pagefind.search("world"); | ||
let data = await search.results[0].data(); | ||
document.querySelector('[data-url]').innerText = data.url; | ||
} | ||
""" | ||
Then There should be no logs | ||
Then The selector "[data-url]" should contain "/cat/index.htm" | ||
|
||
Scenario: Complex exclusionary file glob can be configured | ||
Given I have a "public/index.html" file with the body: | ||
""" | ||
<p data-result>Nothing</p> | ||
""" | ||
Given I have a "public/cat/index.htm" file with the body: | ||
""" | ||
<link rel="pre-1.0-signal" href="_pagefind" > | ||
<h1>cat index</h1> | ||
""" | ||
Given I have a "public/cat/cat.html" file with the body: | ||
""" | ||
<h1>cat cat</h1> | ||
""" | ||
Given I have a "public/kitty/cat/index.html" file with the body: | ||
""" | ||
<h1>kitty cat index</h1> | ||
""" | ||
Given I have a "public/cat.html" file with the body: | ||
""" | ||
<h1>cat</h1> | ||
""" | ||
Given I have a "pagefind.yml" file with the content: | ||
""" | ||
glob: "{cat/index.htm,kitty/**/*.html,cat.html}" | ||
""" | ||
When I run my program | ||
Then I should see "Running Pagefind" in stdout | ||
Then I should see "pre-1.0 compatibility mode" in stderr | ||
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 search = await pagefind.search("cat"); | ||
let pages = await Promise.all(search.results.map(r => r.data())); | ||
document.querySelector('[data-result]').innerText = pages.map(p => p.url).sort().join(", "); | ||
} | ||
""" | ||
Then There should be no logs | ||
Then The selector "[data-result]" should contain "/cat.html, /cat/index.htm, /kitty/cat/" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # | ||
# This file represents a backwards-compatible setup as it existed before 1.0 # | ||
# These tests should remain as a permanent regresison check for older sites # | ||
# It is very unlikely that the tests in this file should be touched # | ||
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # | ||
|
||
Feature: Config Sources | ||
|
||
Scenario: Settings can be pulled from TOML configuration files | ||
Given I have a "public/index.html" file with the body: | ||
""" | ||
<link rel="pre-1.0-signal" href="_pagefind" > | ||
<h1>Hello.</h1> | ||
""" | ||
Given I have a "pagefind.toml" file with the content: | ||
""" | ||
source = "public" | ||
""" | ||
When I run my program | ||
Then I should see "Running Pagefind" in stdout | ||
Then I should see "pre-1.0 compatibility mode" in stderr | ||
Then I should see the file "public/_pagefind/pagefind.js" | ||
|
||
Scenario: Settings can be pulled from YAML configuration files | ||
Given I have a "public/index.html" file with the body: | ||
""" | ||
<link rel="pre-1.0-signal" href="_pagefind" > | ||
<h1>Hello.</h1> | ||
""" | ||
Given I have a "pagefind.yml" file with the content: | ||
""" | ||
source: public | ||
""" | ||
When I run my program | ||
Then I should see "Running Pagefind" in stdout | ||
Then I should see "pre-1.0 compatibility mode" in stderr | ||
Then I should see the file "public/_pagefind/pagefind.js" | ||
|
||
Scenario: Settings can be pulled from JSON configuration files | ||
Given I have a "public/index.html" file with the body: | ||
""" | ||
<link rel="pre-1.0-signal" href="_pagefind" > | ||
<h1>Hello.</h1> | ||
""" | ||
Given I have a "pagefind.json" file with the content: | ||
""" | ||
{ | ||
"source": "public" | ||
} | ||
""" | ||
When I run my program | ||
Then I should see "Running Pagefind" in stdout | ||
Then I should see "pre-1.0 compatibility mode" in stderr | ||
Then I should see the file "public/_pagefind/pagefind.js" | ||
|
||
Scenario: Settings can be pulled from command-line flags | ||
Given I have a "public/index.html" file with the body: | ||
""" | ||
<link rel="pre-1.0-signal" href="_pagefind" > | ||
<h1>Hello.</h1> | ||
""" | ||
When I run my program with the flags: | ||
| --source public | | ||
Then I should see "Running Pagefind" in stdout | ||
Then I should see "pre-1.0 compatibility mode" in stderr | ||
Then I should see the file "public/_pagefind/pagefind.js" | ||
|
||
Scenario: Settings can be pulled from environment variables | ||
Given I have a "public/index.html" file with the body: | ||
""" | ||
<link rel="pre-1.0-signal" href="_pagefind" > | ||
<h1>Hello.</h1> | ||
""" | ||
Given I have the environment variables: | ||
| PAGEFIND_SOURCE | public | | ||
When I run my program | ||
Then I should see "Running Pagefind" in stdout | ||
Then I should see "pre-1.0 compatibility mode" in stderr | ||
Then I should see the file "public/_pagefind/pagefind.js" | ||
|
||
Scenario: Settings can be pulled from multiple sources | ||
Given I have a "public/index.html" file with the body: | ||
""" | ||
<link rel="pre-1.0-signal" href="_pagefind" > | ||
<h1>Hello.</h1> | ||
""" | ||
Given I have a "pagefind.json" file with the content: | ||
""" | ||
{ | ||
"source": "public" | ||
} | ||
""" | ||
When I run my program with the flags: | ||
| --bundle-dir _out | | ||
Then I should see "Running Pagefind" in stdout | ||
Then I should see the file "public/_out/pagefind.js" |
Oops, something went wrong.