-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #174 from brodienguyen/improve-framework-detection…
…-logic-and-add-test-coverage Improve framework detection logic and add test coverage
- Loading branch information
Showing
9 changed files
with
83 additions
and
7 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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"dependencies": {} | ||
} |
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 @@ | ||
{ | ||
"dependencies": { | ||
"@inertiajs/react": "1.0.0" | ||
} | ||
} |
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 @@ | ||
{ | ||
"dependencies": { | ||
"@inertiajs/svelte": "1.0.0", | ||
"svelte": "^4.0.0" | ||
} | ||
} |
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 @@ | ||
{ | ||
"dependencies": { | ||
"@inertiajs/svelte": "1.0.0", | ||
"svelte": "^5.0.0" | ||
} | ||
} |
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 @@ | ||
{ | ||
"dependencies": { | ||
"@inertiajs/svelte": "1.0.0", | ||
"svelte": "5.0.0" | ||
} | ||
} |
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 @@ | ||
{ | ||
"dependencies": { | ||
"@inertiajs/svelte": "1.0.0", | ||
"svelte": "~5.0.0" | ||
} | ||
} |
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 @@ | ||
{ | ||
"dependencies": { | ||
"@inertiajs/vue3": "1.0.0" | ||
} | ||
} |
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,37 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'thor' | ||
require_relative '../../lib/inertia_rails/generators/helper' | ||
|
||
RSpec.describe InertiaRails::Generators::Helper, type: :helper do | ||
describe '#guess_the_default_framework' do | ||
let(:package_json_path) { Pathname.new(File.expand_path("spec/fixtures/package_json_files/#{fixture_file_name}", Dir.pwd)) } | ||
|
||
shared_examples 'framework detection' do |file_name, expected_framework| | ||
let(:fixture_file_name) { file_name } | ||
|
||
it "returns #{expected_framework.inspect} when inspect \"#{file_name}\"" do | ||
expect(described_class.guess_the_default_framework(package_json_path)).to eq(expected_framework) | ||
end | ||
end | ||
|
||
it_behaves_like 'framework detection', 'react_package.json', 'react' | ||
it_behaves_like 'framework detection', 'svelte5_caret_package.json', 'svelte' | ||
it_behaves_like 'framework detection', 'svelte5_exact_package.json', 'svelte' | ||
it_behaves_like 'framework detection', 'svelte5_tilde_package.json', 'svelte' | ||
it_behaves_like 'framework detection', 'svelte4_package.json', 'svelte4' | ||
it_behaves_like 'framework detection', 'vue_package.json', 'vue' | ||
|
||
# Handle exception | ||
context 'when framework cannot be determined' do | ||
let(:fixture_file_name) { 'empty_package.json' } | ||
|
||
it 'raises an error' do | ||
allow(described_class).to receive(:exit) # Prevent `exit` from terminating the test | ||
expect(Thor::Shell::Basic).to receive_message_chain(:new, :say_error) | ||
.with('Could not determine the Inertia.js framework you are using.') | ||
described_class.guess_the_default_framework(package_json_path) | ||
end | ||
end | ||
end | ||
end |