|
35 | 35 | end |
36 | 36 | end |
37 | 37 |
|
| 38 | + shared_context 'assert application.js entrypoint renaming' do |
| 39 | + let(:typescript_enabled?) { args.include?('--typescript') } |
| 40 | + |
| 41 | + it 'renames application.js to application.ts if TypeScript flag is enabled' do |
| 42 | + expect { generator }.not_to raise_error |
| 43 | + |
| 44 | + if typescript_enabled? |
| 45 | + expect(File.exist?(File.join(destination_root, 'app/frontend/entrypoints/application.ts'))).to be true |
| 46 | + expect(File.exist?(File.join(destination_root, 'app/frontend/entrypoints/application.js'))).to be false |
| 47 | + else |
| 48 | + expect(File.exist?(File.join(destination_root, 'app/frontend/entrypoints/application.js'))).to be true |
| 49 | + expect(File.exist?(File.join(destination_root, 'app/frontend/entrypoints/application.ts'))).to be false |
| 50 | + end |
| 51 | + end |
| 52 | + end |
| 53 | + |
38 | 54 | context 'without vite' do |
39 | 55 | before do |
40 | 56 | prepare_application(with_vite: false) |
|
57 | 73 | end |
58 | 74 | end) |
59 | 75 | end |
| 76 | + |
| 77 | + include_context 'assert application.js entrypoint renaming' |
| 78 | + |
| 79 | + context 'with --typescript' do |
| 80 | + let(:args) { super() + %w[--typescript] } |
| 81 | + |
| 82 | + include_context 'assert application.js entrypoint renaming' |
| 83 | + end |
60 | 84 | end |
61 | 85 | end |
62 | 86 |
|
@@ -172,7 +196,7 @@ def expect_packages_for(framework, ext: 'js') |
172 | 196 | end) |
173 | 197 | end |
174 | 198 |
|
175 | | - def expect_inertia_prepared_for(framework, ext: 'js') |
| 199 | + def expect_inertia_prepared_for(framework, ext: 'js', application_js_exists: false) |
176 | 200 | expect(destination_root).to(have_structure do |
177 | 201 | case framework |
178 | 202 | when :react |
@@ -206,10 +230,15 @@ def expect_inertia_prepared_for(framework, ext: 'js') |
206 | 230 | end |
207 | 231 | end |
208 | 232 | file('app/views/layouts/application.html.erb') do |
209 | | - if ext == 'ts' |
| 233 | + if ext == 'ts' && application_js_exists |
| 234 | + contains("<%= vite_typescript_tag \"inertia#{'.tsx' if framework == :react}\" %>") |
| 235 | + contains("<%= vite_typescript_tag 'application' %>") |
| 236 | + elsif ext == 'ts' && !application_js_exists |
210 | 237 | contains("<%= vite_typescript_tag \"inertia#{'.tsx' if framework == :react}\" %>") |
| 238 | + contains("<%= vite_javascript_tag 'application' %>") |
211 | 239 | else |
212 | 240 | contains("<%= vite_javascript_tag \"inertia#{'.jsx' if framework == :react}\" %>") |
| 241 | + contains("<%= vite_javascript_tag 'application' %>") |
213 | 242 | end |
214 | 243 | if framework == :react |
215 | 244 | contains('<%= vite_react_refresh_tag %>') |
|
0 commit comments