Skip to content

Commit

Permalink
Moved Vue support to branch vue-support; Logger -> Log for specs
Browse files Browse the repository at this point in the history
  • Loading branch information
noahlh committed Dec 10, 2020
1 parent 09a1a8a commit 63969a8
Show file tree
Hide file tree
Showing 37 changed files with 32 additions and 3,072 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/src/vue-scripts/build/
/src/vue-scripts/server-build/
/src/svelte-scripts/__sapper__/
/src/svelte-scripts/node_modules/
/src/svelte-scripts/node_modules/@sapper
Expand Down
56 changes: 8 additions & 48 deletions config/celestite_amber_init.example.cr
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,18 @@ require "celestite"

ENV["CELESTITE"] = Amber.env.to_s

# Copy Amber logger settings, then change the color of our logger so it stands out

celestite_logger = Amber.settings.logger.dup
celestite_logger.progname = "Celestite"
celestite_logger.color = :green

# The main init...

Celestite.initialize(

# #
# # First, choose your engine.
# # Vue (Celestite::Engine::Vue) & Svelte (Celestite::Engine::Svelte) are currently supported.
# # Be sure to only use one of the below:
# # First, choose your engine. Although for the moment, it isn't much of a choice.
# # Vue (Celestite::Engine::Vue) & Svelte (Celestite::Engine::Svelte) were originally supported,
# # but we're focusing on Svelte for the time being.
# #

# engine: Celestite::Engine::Vue, # Uncomment this for Vue
# engine: Celestite::Engine::Svelte, # Uncomment this for Svelte
engine: Celestite::Engine::Svelte,

# #
# # This is the logger for the node processes to pipe stdout/stderr. We initialized this up above.
# #

logger: celestite_logger,

# #
# # The component_dir defines where our .vue or .svelte components live.
# # The component_dir defines where our .svelte components live.
# #

component_dir: "#{Dir.current}/src/views/",
Expand All @@ -43,40 +28,15 @@ Celestite.initialize(

# #
# # The build_dir_public_path is the relative directory the browser references for the client js build file.
# # This should be "celestite/" for Vue and "/" for Svelte (this is because of subtleties in the
# # underlying frameworks. Not optimal. Will be fixed / cleaned up in the future.)
# # This should be /" for Svelte (this is because of subtleties in the underlying frameworks.) Not optimal.
# # Will be fixed / cleaned up in the future.
# #

# build_dir_public_path: "celestite/", # Uncomment this for Vue
# build_dir_public_path: "/", # Uncomment this for Svelte
build_dir_public_path: "/", #

# #
# # This is the port for the internal node server and defaults to 4000, but you can change it if you'd like!
# #

port: 4000,

# #
# # Vue-specific options below - remove these for Svelte.
# #

# #
# # The routes_file is a small JSON object outlining our front-end routes. Should match our server-side
# # routes. This will eventually be auto-generated since it's annoyingly redundant.
# #

routes_file: "#{Dir.current}/config/routes.js",

# #
# # If you're going to use custom templates, you'll need to specify where they live.
# # Celestite will use a pretty straightforward default template otherwise.
# #

template_dir: "#{Dir.current}/src/views/layouts/",

# #
# # A default template to use if one is not specified in render calls.
# #

default_template: "main.html",
)
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "celestite",
"version": "0.1.2",
"version": "0.1.3",
"repository": "https://github.com/noahlh/celestite",
"author": "Noah Lehmann-Haupt <[email protected]>",
"license": "MIT",
Expand Down
45 changes: 0 additions & 45 deletions package.old.json

This file was deleted.

6 changes: 3 additions & 3 deletions shard.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
name: celestite
version: 0.1.2
version: 0.1.3

scripts:
postinstall: npm install

authors:
- Noah Lehmann-Haupt <nlh@noahlh.com>
- Noah Lehmann-Haupt <nlh@nlh.me>

crystal: 0.32.1
crystal: 0.35.1

license: MIT
48 changes: 4 additions & 44 deletions spec/celestite_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,6 @@ require "./support/**"

describe Celestite do
describe "self.init" do
it "returns a Vue Renderer when called with no arguments" do
renderer = Celestite.initialize(
engine: Celestite::Engine::Vue,
routes_file: "#{__DIR__}/scripts/vue/routes.js",
component_dir: "#{__DIR__}/scripts/vue"
)
renderer.should be_a(Celestite::Renderer)
ensure
renderer.kill_server if renderer
end
it "returns a Svelte Renderer when called with no arguments" do
renderer = Celestite.initialize(
engine: Celestite::Engine::Svelte,
Expand All @@ -27,54 +17,24 @@ describe Celestite do
describe "@@renderer" do
it "should store a renderer in the module/class var" do
renderer = Celestite.initialize(
engine: Celestite::Engine::Vue,
routes_file: "#{__DIR__}/scripts/vue/routes.js",
component_dir: "#{__DIR__}/scripts/vue"
engine: Celestite::Engine::Svelte,
component_dir: "#{__DIR__}/scripts/svelte"
)
Celestite.renderer.should be_a(Celestite::Renderer)
ensure
renderer.kill_server if renderer
end
it "both returns & stores an init'd renderer in a class/module variable" do
renderer = Celestite.initialize(
engine: Celestite::Engine::Vue,
routes_file: "#{__DIR__}/scripts/vue/routes.js",
component_dir: "#{__DIR__}/scripts/vue"
engine: Celestite::Engine::Svelte,
component_dir: "#{__DIR__}/scripts/svelte"
)
renderer.should eq(Celestite.renderer)
ensure
renderer.kill_server if renderer
end
end
describe "self.render" do
describe "Vue" do
it "renders a template (called from the module-level)" do
renderer = Celestite.initialize(
engine: Celestite::Engine::Vue,
routes_file: "#{__DIR__}/scripts/vue/routes.js",
component_dir: "#{__DIR__}/scripts/vue"
)
sleep 5
response = Celestite.render("/")
response.should eq("<div id=\"celestite-app\" data-server-rendered=\"true\"><div>Test!</div></div>")
ensure
renderer.kill_server if renderer
end
it "renders a template (called from the module level) with a default template" do
renderer = Celestite.initialize(
engine: Celestite::Engine::Vue,
routes_file: "#{__DIR__}/scripts/vue/routes.js",
component_dir: "#{__DIR__}/scripts/vue",
template_dir: "#{__DIR__}/scripts/vue",
default_template: "test.html"
)
sleep 5
response = Celestite.render("/")
response.should contain("<html>\n\n") if response
ensure
renderer.kill_server if renderer
end
end
describe "Svelte" do
it "renders a template (called from the module-level)" do
renderer = Celestite.initialize(
Expand Down
100 changes: 4 additions & 96 deletions spec/renderer/renderer_spec.cr
Original file line number Diff line number Diff line change
@@ -1,74 +1,27 @@
require "../spec_helper"

test_logger = get_logger

describe Celestite do
describe Celestite::Renderer do
describe "#initialize" do
it "logs its initialization" do
IO.pipe do |r, w|
logger = Logger.new(w)
logger.progname = "Celestite"
Celestite::Renderer::Generic.new(logger: logger)
io_log_backend = Log::IOBackend.new(w)
Log.setup(:debug, io_log_backend)
Celestite::Renderer::Generic.new
r.gets.should match(/Renderer Initialized/)
Log.setup(:none)
end
end
it "can be initialized with no params" do
r = Celestite::Renderer::Generic.new
r.should be_a(Celestite::Renderer)
end
it "can initialize a Vue renderer" do
r = Celestite::Renderer::Vue.new
r.should be_a(Celestite::Renderer::Vue)
end
it "can initialize a Svelte renderer" do
r = Celestite::Renderer::Svelte.new
r.should be_a(Celestite::Renderer::Svelte)
end
end
describe "#start_server" do
describe "Vue" do
it "raises an exception if no routes_file set" do
expect_raises(Exception, "Error - you must define routes_file to launch the node process") do
proc = Celestite::Renderer::Vue.new.start_server
end
end
it "raises an exception if no component_dir set" do
expect_raises(Exception, "Error - you must define component_dir to launch the node process") do
r = Celestite::Renderer::Vue.new(routes_file: "test.js")
proc = r.start_server
end
end
it "spawns a node process (whether it's valid or not)" do
r = Celestite::Renderer::Vue.new(component_dir: "../../spec/scripts/vue", routes_file: "../../spec/scripts/vue/routes.js")
proc = r.start_server
proc.should be_a(Process)
ensure
proc.kill if proc
end
it "raises an exception if the server doesn't start within a specified timeout" do
r = Celestite::Renderer::Vue.new(
routes_file: "#{__DIR__}/../../spec/scripts/vue/routes.js",
component_dir: "#{__DIR__}/../../spec/scripts/vue"
)
expect_raises(Exception, "Node server failed to start within timeout") do
run_spec_server(r, timeout: 0.001.seconds) do
res = r.render("/")
end
end
end
it "raises an exception if the server is started with an invalid routes file" do
r = Celestite::Renderer::Vue.new(
routes_file: "foo.js",
component_dir: "#{__DIR__}/../../spec/scripts/vue"
)
expect_raises(Exception, "Node server failed") do
run_spec_server(r) do
res = r.render("/")
end
end
end
end
describe "Svelte" do
it "raises an exception if no component_dir set" do
expect_raises(Exception, "Error - you must define component_dir to launch the node process") do
Expand Down Expand Up @@ -108,51 +61,6 @@ describe Celestite do
end
end
describe "#render" do
describe "Vue" do
it "Renders a vue component (no context) and returns the raw HTML" do
r = Celestite::Renderer::Vue.new(
routes_file: "#{__DIR__}/../scripts/vue/routes.js",
component_dir: "#{__DIR__}/../scripts/vue"
)
run_spec_server(r) do
res = r.render("/")
res.should eq("<div id=\"celestite-app\" data-server-rendered=\"true\"><div>Test!</div></div>")
end
end
it "Renders a vue component (w/ context) and returns the raw HTML" do
r = Celestite::Renderer::Vue.new(
routes_file: "#{__DIR__}/../scripts/vue/routes.js",
component_dir: "#{__DIR__}/../scripts/vue"
)
run_spec_server(r) do
res = r.render("/context", Celestite::Context{:foo => "bar"})
res.should eq("<div id=\"celestite-app\" data-server-rendered=\"true\"><div>Test context: bar</div></div>")
end
end
it "Renders a vue component w/ a template specified" do
r = Celestite::Renderer::Vue.new(
routes_file: "#{__DIR__}/../scripts/vue/routes.js",
component_dir: "#{__DIR__}/../scripts/vue",
template_dir: "#{__DIR__}/../scripts/vue",
)
run_spec_server(r) do
res = r.render("/", template: "test.html")
res.should contain("<html>\n\n")
end
end
it "Renders a vue component w/ a default template specified" do
r = Celestite::Renderer::Vue.new(
routes_file: "#{__DIR__}/../scripts/vue/routes.js",
component_dir: "#{__DIR__}/../scripts/vue",
template_dir: "#{__DIR__}/../scripts/vue",
default_template: "test.html"
)
run_spec_server(r) do
res = r.render("/")
res.should contain("<html>\n\n")
end
end
end
describe "Svelte" do
it "Renders a svelte component (no context) and returns the raw HTML" do
r = Celestite::Renderer::Svelte.new(
Expand Down
19 changes: 0 additions & 19 deletions spec/scripts/vue/Context.vue

This file was deleted.

9 changes: 0 additions & 9 deletions spec/scripts/vue/Test.vue

This file was deleted.

Loading

0 comments on commit 63969a8

Please sign in to comment.