Skip to content

Commit

Permalink
Fix vite-ruby integration tests on GHA (#3)
Browse files Browse the repository at this point in the history
* GitHub actions is capricious again

* Use the same bundler isolation trick we do for rails bundling integration tests

* Remove debug output
  • Loading branch information
yaroslav authored Dec 21, 2024
1 parent edbf2b2 commit 43bbeeb
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 53 deletions.
11 changes: 0 additions & 11 deletions spec/integration/bundlebun/integrations/rails_bundling_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,4 @@
end
end
end

def capture(cmd)
env = {
'BUNDLE_GEMFILE' => File.join(tmp_dir, 'Gemfile'),
'BUNDLE_PATH' => File.join(tmp_dir, 'vendor/bundle'),
'BUNDLE_APP_CONFIG' => File.join(tmp_dir, '.bundle'),
'BUNDLE_DISABLE_SHARED_GEMS' => 'true',
'PATH' => "#{File.join(tmp_dir, "bin")}:#{File.join(tmp_dir, "vendor/bundle/bin")}:#{ENV["PATH"]}"
}
Open3.capture2e(env, cmd)
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -12,55 +12,57 @@

it 'executes vite build through bun' do
Dir.chdir(tmp_dir) do
File.write('Gemfile', <<~RUBY)
source 'https://rubygems.org'
gem 'rake'
gem 'vite_ruby'
gem 'bundlebun', path: '#{gem_root}'
RUBY
Bundler.with_unbundled_env do
File.write('Gemfile', <<~RUBY)
source 'https://rubygems.org'
gem 'rake'
gem 'vite_ruby'
gem 'bundlebun', path: '#{gem_root}'
RUBY

File.write('Rakefile', <<~RUBY)
require 'vite_ruby'
require 'bundlebun'
RUBY
File.write('Rakefile', <<~RUBY)
require 'vite_ruby'
require 'bundlebun'
RUBY

_install_output, install_status = Open3.capture2e("cd #{tmp_dir} && bundle install && bundle exec vite install && bundle exec rake bun:install && bundle exec rake bun:install:vite && bundle exec ./bin/bun install")
expect(install_status).to be_success
_install_output, install_status = capture("cd #{tmp_dir} && bundle install && bundle exec vite install && bundle exec rake bun:install && bundle exec rake bun:install:vite && bundle exec ./bin/bun install")
expect(install_status).to be_success

FileUtils.mkdir_p('src')
File.write('index.html', <<~HTML)
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Vite Test</title>
</head>
<body>
<script type="module" src="/src/main.js"></script>
</body>
</html>
HTML
File.write('vite.config.js', <<~JS)
export default {
plugins: [{
name: 'check-bun',
buildStart() {
if (typeof Bun === 'undefined') {
throw new Error('Not running in Bun environment');
FileUtils.mkdir_p('src')
File.write('index.html', <<~HTML)
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Vite Test</title>
</head>
<body>
<script type="module" src="/src/main.js"></script>
</body>
</html>
HTML
File.write('vite.config.js', <<~JS)
export default {
plugins: [{
name: 'check-bun',
buildStart() {
if (typeof Bun === 'undefined') {
throw new Error('Not running in Bun environment');
}
console.log('Bun version:', Bun.version);
}
console.log('Bun version:', Bun.version);
}],
build: {
outDir: 'dist'
}
}],
build: {
outDir: 'dist'
}
}
JS
File.write('src/main.js', "console.log('Hi.')")
JS
File.write('src/main.js', "console.log('Hi.')")

output, status = Open3.capture2e("cd #{tmp_dir} && bin/vite build")
expect(status).to be_success
expect(output.to_s).to match(/Bun version: \d+\.\d+\.\d+/)
output, status = capture("cd #{tmp_dir} && bundle exec bin/vite build")
expect(status).to be_success
expect(output.to_s).to match(/Bun version: \d+\.\d+\.\d+/)
end
end
end
end
11 changes: 11 additions & 0 deletions spec/support/integration_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,14 @@
end
end
end

def capture(cmd)
env = {
'BUNDLE_GEMFILE' => File.join(tmp_dir, 'Gemfile'),
'BUNDLE_PATH' => File.join(tmp_dir, 'vendor/bundle'),
'BUNDLE_APP_CONFIG' => File.join(tmp_dir, '.bundle'),
'BUNDLE_DISABLE_SHARED_GEMS' => 'true',
'PATH' => "#{File.join(tmp_dir, "bin")}:#{File.join(tmp_dir, "vendor/bundle/bin")}:#{ENV["PATH"]}"
}
Open3.capture2e(env, cmd)
end

0 comments on commit 43bbeeb

Please sign in to comment.