-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use upcoming Bridgetown 2 test setup
It supports testing static pages and Roda routes with the same setup. I extracted it from bridgetownrb/bridgetown#954 With Jared's advice he gave me in Discord.
- Loading branch information
1 parent
8470438
commit 8cc2ba1
Showing
9 changed files
with
125 additions
and
6 deletions.
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
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 |
---|---|---|
|
@@ -25,7 +25,6 @@ bower_components | |
.env | ||
|
||
# Dev and build only files | ||
.devcontainer | ||
.git | ||
Dockerfile | ||
.dockerignore | ||
|
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
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
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
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,11 @@ | ||
module TestOutput | ||
unless Bridgetown.env.development? | ||
Bridgetown::Hooks.register_one :site, :post_write do | ||
# Load test suite to run on exit | ||
require "nokogiri" | ||
Dir["test/**/*.rb"].each { |file| require_relative("../#{file}") } | ||
rescue LoadError | ||
Bridgetown.logger.warn "Testing:", "To run tests, you must first run `bundle install --with test`" | ||
end | ||
end | ||
end |
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,47 @@ | ||
# frozen_string_literal: true | ||
|
||
# This file can be required by project test suites to set up the Minitest environment | ||
|
||
require "bridgetown" | ||
|
||
ENV["BRIDGETOWN_NO_BUNDLER_REQUIRE"] = nil | ||
Bridgetown.begin! | ||
|
||
Bridgetown::Builders::PluginBuilder.then do | ||
Bridgetown::Builders::DSL::Inspectors.setup_nokolexbor | ||
end | ||
|
||
require "bridgetown-core/rack/boot" | ||
class Bridgetown::Rack::Logger | ||
def add(*) | ||
super if ENV["SERVER_LOGS"] == "true" | ||
end | ||
end | ||
|
||
Bridgetown::Current.preloaded_configuration = Bridgetown.configuration | ||
Bridgetown::Rack.boot | ||
|
||
require "rack/test" | ||
|
||
class Bridgetown::Test < Minitest::Test | ||
include Rack::Test::Methods | ||
|
||
attr_reader :document | ||
|
||
def roda_app_class = RodaApp | ||
|
||
def app = roda_app_class.app | ||
|
||
def site | ||
roda_app_class.opts[:bridgetown_site] | ||
end | ||
|
||
def html(request) = @document = Nokolexbor::Document.parse(request.body) | ||
|
||
def json(request) = @document = JSON.parse(request.body) | ||
|
||
def routes = JSON.parse(File.read( | ||
File.join(Bridgetown::Current.preloaded_configuration.root_dir, | ||
".routes.json") | ||
)) | ||
end |
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,5 @@ | ||
require "minitest/autorun" | ||
require "minitest/reporters" | ||
Minitest::Reporters.use! [Minitest::Reporters::ProgressReporter.new] | ||
|
||
require_relative "bridgetown_test" |
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,9 @@ | ||
require "minitest_helper" | ||
|
||
class TestHomepage < Bridgetown::Test | ||
def test_homepage | ||
html get "/" | ||
|
||
assert document.query_selector("body") | ||
end | ||
end |