-
Notifications
You must be signed in to change notification settings - Fork 131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add integration tests for add-on #2108
Open
andyw8
wants to merge
2
commits into
main
Choose a base branch
from
andyw8/add-test-app
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
|
@@ -4,6 +4,8 @@ | |
/coverage/ | ||
/doc/ | ||
/pkg/ | ||
/spec/dummy/log/ | ||
/spec/dummy/tmp/ | ||
/spec/examples.txt | ||
/spec/reports/ | ||
/tmp/ | ||
|
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,41 @@ | ||
# typed: true | ||
# frozen_string_literal: true | ||
|
||
require "spec_helper" | ||
|
||
require "language_server-protocol" | ||
require "ruby_lsp/utils" | ||
|
||
module ActiveSupport | ||
class TestCase | ||
# These methods can be removed once https://github.com/Shopify/ruby-lsp/pull/2991 ships | ||
|
||
def pop_result(server) | ||
result = server.pop_response | ||
result = server.pop_response until result.is_a?(RubyLsp::Result) || result.is_a?(RubyLsp::Error) | ||
|
||
refute_instance_of( | ||
RubyLsp::Error, | ||
result, | ||
-> { "Failed to execute request #{T.cast(result, RubyLsp::Error).message}" }, | ||
) | ||
T.cast(result, RubyLsp::Result) | ||
end | ||
|
||
def pop_log_notification(message_queue, type) | ||
log = message_queue.pop | ||
return log if log.params.type == type | ||
|
||
log = message_queue.pop until log.params.type == type | ||
log | ||
end | ||
|
||
def pop_message(outgoing_queue, &block) | ||
message = outgoing_queue.pop | ||
return message if block.call(message) | ||
|
||
message = outgoing_queue.pop until block.call(message) | ||
message | ||
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,6 @@ | ||
# frozen_string_literal: true | ||
|
||
class NotifyUserJob < ActiveJob::Base | ||
def perform(user) | ||
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,14 @@ | ||
#!/usr/bin/env ruby | ||
# frozen_string_literal: true | ||
|
||
# This command will automatically be run when you run "rails" with Rails gems | ||
# installed from the root of your application. | ||
|
||
ENGINE_ROOT = File.expand_path("..", __dir__) | ||
APP_PATH = File.expand_path("../config/application", __dir__) | ||
|
||
# Set up gems listed in the Gemfile. | ||
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__) | ||
require "bundler/setup" if File.exist?(ENV["BUNDLE_GEMFILE"]) | ||
|
||
require "rails/engine/commands" |
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,7 @@ | ||
# typed: strict | ||
# frozen_string_literal: true | ||
|
||
require_relative "config/environment" | ||
|
||
run Rails.application | ||
Rails.application.load_server |
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,16 @@ | ||
# frozen_string_literal: true | ||
|
||
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../../Gemfile", __dir__) | ||
|
||
require "bundler/setup" if File.exist?(ENV["BUNDLE_GEMFILE"]) | ||
$LOAD_PATH.unshift(File.expand_path("../../../lib", __dir__)) | ||
|
||
require "rails" # minimal, instead of "rails/all" | ||
require "active_job/railtie" | ||
|
||
Bundler.require(*Rails.groups) | ||
|
||
module Dummy | ||
class Application < Rails::Application | ||
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,5 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative "application" | ||
|
||
Rails.application.initialize! |
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,59 @@ | ||
# typed: true | ||
# frozen_string_literal: true | ||
|
||
require "addon_spec_helper" | ||
require "ruby_lsp/ruby_lsp_rails/runner_client" | ||
require "minitest/hooks" | ||
|
||
module RubyLsp | ||
module Tapioca | ||
class AddonSpec < Minitest::HooksSpec | ||
# The approach here is based on tests within the Ruby LSP Rails gem | ||
|
||
# TODO: Replace by `before(:all)` once Sorbet understands it | ||
def initialize(*args) | ||
super(*T.unsafe(args)) | ||
FileUtils.cp("spec/dummy/bin/rails", "bin/rails") | ||
@outgoing_queue = Thread::Queue.new | ||
@client = T.let(nil, T.nilable(RubyLsp::Rails::RunnerClient)) | ||
FileUtils.chdir("spec/dummy") do | ||
@client = RubyLsp::Rails::RunnerClient.new(@outgoing_queue) | ||
end | ||
end | ||
|
||
after(:all) do | ||
# TODO: Remove `bind` once Sorbet understands `after(:all)` | ||
T.bind(self, AddonSpec) | ||
|
||
T.must(@client).shutdown | ||
|
||
assert_predicate(@client, :stopped?) | ||
@outgoing_queue.close | ||
FileUtils.rm("bin/rails") | ||
end | ||
|
||
EXPECTED_RBI_PATH = "spec/dummy/sorbet/rbi/dsl/notify_user_job.rbi" | ||
it "generates DSL RBIs for a given constant" do | ||
addon_path = File.expand_path("lib/ruby_lsp/tapioca/server_addon.rb") | ||
T.must(@client).register_server_addon(File.expand_path(addon_path)) | ||
T.must(@client).delegate_notification( | ||
server_addon_name: "Tapioca", | ||
request_name: "dsl", | ||
constants: ["NotifyUserJob"], | ||
) | ||
|
||
begin | ||
Timeout.timeout(10) do | ||
sleep(1) | ||
until File.exist?(EXPECTED_RBI_PATH) | ||
andyw8 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
end | ||
end | ||
rescue Timeout::Error | ||
flunk("RBI file was not generated") | ||
end | ||
ensure | ||
FileUtils.rm_rf("spec/dummy/sorbet/rbi") | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copied from ruby-lsp-rail's test suite, but we may be able to remove: Shopify/ruby-lsp-rails#548
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That'd be nice.