Skip to content

Commit

Permalink
Setup tests
Browse files Browse the repository at this point in the history
  • Loading branch information
skryukov committed Nov 20, 2024
1 parent f189ba5 commit f9fe330
Show file tree
Hide file tree
Showing 38 changed files with 194 additions and 38 deletions.
72 changes: 72 additions & 0 deletions .github/workflows/generators.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: Test Generators

on:
push:
branches:
- master
paths:
- 'lib/generators/**'
- '.github/workflows/generators.yml'
- 'lib/inertia_rails/generators/**'
pull_request:
paths:
- 'lib/generators/**'
- '.github/workflows/generators.yml'
- 'lib/inertia_rails/generators/**'

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
framework: [react, vue, svelte]
typescript: [true, false]
tailwind: [true, false]
ruby: ['3.3']
node: ['22']

name: ${{ matrix.framework }} (TS:${{ matrix.typescript }}, TW:${{ matrix.tailwind }})

steps:
- uses: actions/checkout@v4

- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true

- name: Set up Node
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
cache: 'npm'

- name: Cache dependencies
uses: actions/cache@v3
with:
path: |
tmp/bundle_cache
tmp/npm_cache
key: ${{ runner.os }}-deps-${{ matrix.framework }}-${{ hashFiles('**/Gemfile.lock', '**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-deps-${{ matrix.framework }}-
- name: Install Rails
run: gem install rails

- name: Run test script
run: |
ts_flag=${{ matrix.typescript && '--typescript' || '--no-typescript' }}
tw_flag=${{ matrix.tailwind && '--tailwind' || '--no-tailwind' }}
bin/generate_scaffold_example --framework=${{ matrix.framework }} $ts_flag $tw_flag
- name: Upload test artifacts
if: failure()
uses: actions/upload-artifact@v3
with:
name: test-output-${{ matrix.framework }}-ts${{ matrix.typescript }}-tw${{ matrix.tailwind }}
path: |
tmp/scaffold_example/log
tmp/scaffold_example/tmp/screenshots
if-no-files-found: ignore
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
/pkg/
/spec/reports/
/tmp/
/.cache/
/Gemfile.lock

/spec/dummy/db/*.sqlite3
Expand Down
83 changes: 83 additions & 0 deletions bin/generate_scaffold_example
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#!/usr/bin/env ruby

require 'fileutils'
require 'optparse'

# Parse command line options
options = {
framework: 'react',
typescript: true,
tailwind: true,
}

OptionParser.new do |opts|
opts.banner = "Usage: #{$0} [options]"

opts.on('--framework FRAMEWORK', %w[react vue svelte],
'Choose framework (react/vue/svelte)') do |f|
options[:framework] = f
end

opts.on('--[no-]typescript', 'Enable/disable TypeScript') do |t|
options[:typescript] = t
end

opts.on('--[no-]tailwind', 'Enable/disable Tailwind') do |t|
options[:tailwind] = t
end
end.parse!

# Build generator args string
generator_args = "--framework=#{options[:framework]}"
generator_args += ' --typescript' if options[:typescript]
generator_args += ' --install-vite'
generator_args += ' --install-tailwind' if options[:tailwind]

# Setup paths relative to project root
project_root = File.expand_path('../..', __FILE__)
working_dir = File.join(project_root, 'tmp')
gem_cache = File.join(working_dir, 'bundle_cache')
npm_cache = File.join(working_dir, 'npm_cache')

# Create cache directories if they don't exist
[gem_cache, npm_cache, working_dir].each do |dir|
FileUtils.mkdir_p(dir) unless File.directory?(dir)
end

# Clean working directory
FileUtils.rm_r(working_dir) if File.directory?(working_dir)
FileUtils.mkdir_p(working_dir)

# Generate a new Rails app
app_name = 'scaffold_example'
app_dir = File.join(working_dir, app_name)
system("rails new #{app_dir} -J")

# Install and configure with caching
Dir.chdir(app_dir) do
# Configure bundler to use cache in project root
system("bundle config set --local path '#{gem_cache}'")

# Configure npm to use cache in project root
system("npm config set cache '#{npm_cache}'")

# Install dependencies
system('bundle add inertia_rails --path ../../')
system('bundle add bcrypt')
system('bin/rails active_storage:install')

# Run install generator with configured options
system("bin/rails g inertia:install --no-interactive --force #{generator_args}")

# Generate a scaffold
system('bin/rails g inertia:scaffold post title:string content:text published:boolean')

# Run migrations
system('bin/rails db:migrate')

# Run tests
system('bin/rails test')

# Run system tests
system('bin/rails test:system')
end
2 changes: 1 addition & 1 deletion docs/cookbook/integrating-shadcn-ui.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ If you're starting fresh, create a new Rails application with Inertia (or skip t
rails new -JA shadcn-inertia-rails
cd shadcn-inertia-rails

rails generate inertia:install --framework=react --typescript --install-vite --install-tailwind --no-interactive
rails generate inertia:install `--framework=react --typescript --install-vite --install-tailwind --no-interactive`
Installing Inertia's Rails adapter
...
```
Expand Down
6 changes: 3 additions & 3 deletions docs/guide/server-side-setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ First, setup the root template that will be loaded on the first page visit. This
<meta name="viewport" content="width=device-width,initial-scale=1">
<%= csp_meta_tag %>
<%= inertia_headers %>
<%= inertia_ssr_head %>
<%# If you want to use React add `vite_react_refresh_tag` %>
<%= vite_client_tag %>
Expand All @@ -144,7 +144,7 @@ First, setup the root template that will be loaded on the first page visit. This
<meta name="viewport" content="width=device-width,initial-scale=1">
<%= csp_meta_tag %>
<%= inertia_headers %>
<%= inertia_ssr_head %>
<%= stylesheet_pack_tag 'application' %>
<%= javascript_pack_tag 'application', defer: true %>
Expand All @@ -157,7 +157,7 @@ First, setup the root template that will be loaded on the first page visit. This
:::
This template should include your assets, as well as the `yield` method to render the Inertia page. The `inertia_headers` method is used to include the Inertia headers in the response, it's required when [SSR](/guide/server-side-rendering.md) is enabled.
This template should include your assets, as well as the `yield` method to render the Inertia page. The `inertia_ssr_head` method is used to include the Inertia headers in the response, it's required when [SSR](/guide/server-side-rendering.md) is enabled.

Inertia's adapter will use standard Rails layout inheritance, with `view/layouts/application.html.erb` as a default layout. If you would like to use a different default layout, you can change it using the `InertiaRails.configure`.
Expand Down
4 changes: 2 additions & 2 deletions lib/generators/inertia/install/install_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def install_inertia
say "Adding #{inertia_entrypoint} script tag to the application layout"
headers = <<-ERB
<%= #{vite_tag} "inertia" %>
<%= inertia_headers %>
<%= inertia_ssr_head %>
ERB
insert_into_file application_layout.to_s, headers, after: "<%= vite_client_tag %>\n"

Expand All @@ -109,7 +109,7 @@ def install_inertia
say_error 'Could not find the application layout file. Please add the following tags manually:', :red
say_error '- <title>...</title>'
say_error '+ <title inertia>...</title>'
say_error '+ <%= inertia_headers %>'
say_error '+ <%= inertia_ssr_head %>'
say_error '+ <%= vite_react_refresh_tag %>' if framework == 'react'
say_error "+ <%= #{vite_tag} \"inertia\" %>"
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default function Edit({ <%= singular_table_name %> }) {
form.patch(`<%= js_resource_path %>`)
<% end -%>
}}
submitText="Update <%= human_name.downcase %>"
submitText="Update <%= human_name %>"
/>

<br />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default function Edit({ <%= singular_table_name %> }: EditProps) {
form.patch(`<%= js_resource_path %>`)
<% end -%>
}}
submitText="Update <%= human_name.downcase %>"
submitText="Update <%= human_name %>"
/>

<br />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default function New({ <%= singular_table_name %> }) {
form.transform((data) => ({ <%= singular_table_name %>: data }))
form.post('<%= js_resources_path %>')
}}
submitText="Create <%= human_name.downcase %>"
submitText="Create <%= human_name %>"
/>

<br />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default function New({ <%= singular_table_name %> }: NewProps) {
form.transform((data) => ({ <%= singular_table_name %>: data }))
form.post('<%= js_resources_path %>')
}}
submitText="Create <%= human_name.downcase %>"
submitText="Create <%= human_name %>"
/>

<br />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

<Form
{<%= singular_table_name %>}
submitText="Update <%= human_name.downcase %>"
submitText="Update <%= human_name %>"
onSubmit={handleSubmit}
/>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

<Form
{<%= singular_table_name %>}
submitText="Update <%= human_name.downcase %>"
submitText="Update <%= human_name %>"
onSubmit={handleSubmit}
/>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

<Form
{<%= singular_table_name %>}
submitText="Create <%= human_name.downcase %>"
submitText="Create <%= human_name %>"
onSubmit={handleSubmit}
/>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

<Form
{<%= singular_table_name %>}
submitText="Create <%= human_name.downcase %>"
submitText="Create <%= human_name %>"
onSubmit={handleSubmit}
/>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

<Form
{<%= singular_table_name %>}
submitText="Update <%= human_name.downcase %>"
submitText="Update <%= human_name %>"
on:submit={handleSubmit}
/>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

<Form
{<%= singular_table_name %>}
submitText="Update <%= human_name.downcase %>"
submitText="Update <%= human_name %>"
on:submit={handleSubmit}
/>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

<Form
{<%= singular_table_name %>}
submitText="Create <%= human_name.downcase %>"
submitText="Create <%= human_name %>"
on:submit={handleSubmit}
/>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

<Form
{<%= singular_table_name %>}
submitText="Create <%= human_name.downcase %>"
submitText="Create <%= human_name %>"
on:submit={handleSubmit}
/>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<Form
:<%= singular_table_name %>="<%= singular_table_name %>"
submitText="Update <%= human_name.downcase %>"
submitText="Update <%= human_name %>"
@onSubmit="handleSubmit"
/>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<Form
:<%= singular_table_name %>="<%= singular_table_name %>"
submitText="Update <%= human_name.downcase %>"
submitText="Update <%= human_name %>"
@onSubmit="handleSubmit"
/>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<Form
:<%= singular_table_name %>="<%= singular_table_name %>"
submitText="Create <%= human_name.downcase %>"
submitText="Create <%= human_name %>"
@onSubmit="handleSubmit"
/>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<Form
:<%= singular_table_name %>="<%= singular_table_name %>"
submitText="Create <%= human_name.downcase %>"
submitText="Create <%= human_name %>"
@onSubmit="handleSubmit"
/>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default function Edit({ <%= singular_table_name %> }) {
form.patch(`<%= js_resource_path %>`)
<% end -%>
}}
submitText="Update <%= human_name.downcase %>"
submitText="Update <%= human_name %>"
/>

<Link
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default function Edit({ <%= singular_table_name %> }: EditProps) {
form.patch(`<%= js_resource_path %>`)
<% end -%>
}}
submitText="Update <%= human_name.downcase %>"
submitText="Update <%= human_name %>"
/>

<Link
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default function New({ <%= singular_table_name %> }) {
form.transform((data) => ({ <%= singular_table_name %>: data }))
form.post('<%= js_resources_path %>')
}}
submitText="Create <%= human_name.downcase %>"
submitText="Create <%= human_name %>"
/>

<Link
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default function New({ <%= singular_table_name %> }: NewProps) {
form.transform((data) => ({ <%= singular_table_name %>: data }))
form.post('<%= js_resources_path %>')
}}
submitText="Create <%= human_name.downcase %>"
submitText="Create <%= human_name %>"
/>

<Link
Expand Down
Loading

0 comments on commit f9fe330

Please sign in to comment.