diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-12-19 14:01:45 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-12-19 14:01:45 +0300 |
commit | 9297025d0b7ddf095eb618dfaaab2ff8f2018d8b (patch) | |
tree | 865198c01d1824a9b098127baa3ab980c9cd2c06 /spec/lib/vite_gdk_spec.rb | |
parent | 6372471f43ee03c05a7c1f8b0c6ac6b8a7431dbe (diff) |
Add latest changes from gitlab-org/gitlab@16-7-stable-eev16.7.0-rc42
Diffstat (limited to 'spec/lib/vite_gdk_spec.rb')
-rw-r--r-- | spec/lib/vite_gdk_spec.rb | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/spec/lib/vite_gdk_spec.rb b/spec/lib/vite_gdk_spec.rb new file mode 100644 index 00000000000..f54ede9d877 --- /dev/null +++ b/spec/lib/vite_gdk_spec.rb @@ -0,0 +1,63 @@ +# frozen_string_literal: true + +require 'spec_helper' + +VITE_GDK_CONFIG_FILEPATH = "config/vite.gdk.json" + +RSpec.describe ViteGdk, feature_category: :tooling do + before do + allow(ViteRuby).to receive(:configure) + allow(ViteRuby.env).to receive(:[]=) + allow(YAML).to receive(:safe_load_file) + end + + describe '#load_gdk_vite_config' do + context 'when not in production environment' do + before do + stub_env('RAILS_ENV', nil) + end + + context 'when it loads file successfully' do + it 'configures ViteRuby' do + expect(File).to receive(:exist?) do |file_path| + expect(file_path).to end_with(VITE_GDK_CONFIG_FILEPATH) + end.and_return(true) + expect(YAML).to receive(:safe_load_file) do |file_path| + expect(file_path).to end_with(VITE_GDK_CONFIG_FILEPATH) + end.and_return('enabled' => true, 'port' => 3038, 'host' => 'gdk.test') + expect(ViteRuby).to receive(:configure).with(host: 'gdk.test', port: 3038) + expect(ViteRuby.env).to receive(:[]=).with('VITE_ENABLED', 'true') + + described_class.load_gdk_vite_config + end + end + + context 'when config file is missing' do + it 'does nothing' do + expect(File).to receive(:exist?) do |file_path| + expect(file_path).to end_with(VITE_GDK_CONFIG_FILEPATH) + end.and_return(false) + expect(ViteRuby).not_to receive(:configure) + expect(ViteRuby.env).not_to receive(:[]=).with('VITE_ENABLED', 'false') + expect(ViteRuby.env).not_to receive(:[]=).with('VITE_ENABLED', 'true') + + described_class.load_gdk_vite_config + end + end + end + + context 'when in production environment' do + before do + stub_env('RAILS_ENV', 'production') + end + + it 'does not load and configure ViteRuby' do + expect(YAML).not_to receive(:safe_load_file) + expect(ViteRuby).not_to receive(:configure) + expect(ViteRuby.env).not_to receive(:[]=).with('VITE_ENABLED') + + described_class.load_gdk_vite_config + end + end + end +end |