A platform for community discussion. Free, open, simple.
DEV: Future-proof ThemeJavascriptCompiler spec (#17393)
David Taylor8e0b1ee74dbe
diff --git a/spec/lib/theme_javascript_compiler_spec.rb b/spec/lib/theme_javascript_compiler_spec.rbindex 335b649307b..e3fcdda1362 100644--- a/spec/lib/theme_javascript_compiler_spec.rb+++ b/spec/lib/theme_javascript_compiler_spec.rb@@ -70,41 +70,62 @@ describe ThemeJavascriptCompiler dodescribe ThemeJavascriptCompiler::EmberTemplatePrecompiler do# For the Ember (Glimmer) templates, serverside rendering is not trivial,- # so check the compiled JSON against known working output- let(:compiler) { described_class.new(theme_id) }- let(:helper_opcode) do- append = statement("{{dummy-helper 1}}")[0]- helper = append[1]- helper[0]+ # so we compile the expected result with the standard compiler and compare to the theme compiler+ let(:standard_compiler) { Barber::Ember::Precompiler.new }+ let(:theme_compiler) { described_class.new(theme_id) }++ def theme_compile(template)+ compiled = theme_compiler.compile(template)+ data = JSON.parse(compiled)+ JSON.parse(data["block"])end- def statement(template)- compiled = compiler.compile(template)+ def standard_compile(template)+ compiled = standard_compiler.compile(template)data = JSON.parse(compiled)- block = JSON.parse(data["block"])- block["statements"]+ JSON.parse(data["block"])endit 'adds the theme id to the helpers' do- expect(statement("{{theme-prefix 'translation_key'}}")).- to eq([[1, [helper_opcode, "theme-prefix", [22, "translation_key"], nil], false]])- expect(statement("{{theme-i18n 'translation_key'}}")).- to eq([[1, [helper_opcode, "theme-i18n", [22, "translation_key"], nil], false]])- expect(statement("{{theme-setting 'setting_key'}}")).- to eq([[1, [helper_opcode, "theme-setting", [22, "setting_key"], nil], false]])-- # Works when used inside other statements- expect(statement("{{dummy-helper (theme-prefix 'translation_key')}}")).- to eq([[1, [helper_opcode, "dummy-helper", [[helper_opcode, "theme-prefix", [22, "translation_key"], nil]], nil], false]])+ expect(+ theme_compile "{{theme-prefix 'translation_key'}}"+ ).to eq(+ standard_compile "{{theme-prefix #{theme_id} 'translation_key'}}"+ )++ expect(+ theme_compile "{{theme-i18n 'translation_key'}}"+ ).to eq(+ standard_compile "{{theme-i18n #{theme_id} 'translation_key'}}"+ )++ expect(+ theme_compile "{{theme-setting 'setting_key'}}"+ ).to eq(+ standard_compile "{{theme-setting #{theme_id} 'setting_key'}}"+ )++ # # Works when used inside other statements+ expect(+ theme_compile "{{dummy-helper (theme-prefix 'translation_key')}}"+ ).to eq(+ standard_compile "{{dummy-helper (theme-prefix #{theme_id} 'translation_key')}}"+ )endit 'works with the old settings syntax' do- expect(statement("{{themeSettings.setting_key}}")).- to eq([[1, [helper_opcode, "theme-setting", [22, "setting_key"], [["deprecated"], [true]]], false]])+ expect(+ theme_compile "{{themeSettings.setting_key}}"+ ).to eq(+ standard_compile "{{theme-setting #{theme_id} 'setting_key' deprecated=true}}"+ )# Works when used inside other statements- expect(statement("{{dummy-helper themeSettings.setting_key}}")).- to eq([[1, [helper_opcode, "dummy-helper", [[helper_opcode, "theme-setting", [22, "setting_key"], [["deprecated"], [true]]]], nil], false]])+ expect(+ theme_compile "{{dummy-helper themeSettings.setting_key}}"+ ).to eq(+ standard_compile "{{dummy-helper (theme-setting #{theme_id} 'setting_key' deprecated=true)}}"+ )endend