From 033644ea823fb908a6c55692cafa3fbae8e947e3 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Tue, 12 May 2020 12:23:12 -0400 Subject: [PATCH] DEV: Adds an integrity spec for JS constants --- spec/integrity/js_constants_spec.rb | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 spec/integrity/js_constants_spec.rb diff --git a/spec/integrity/js_constants_spec.rb b/spec/integrity/js_constants_spec.rb new file mode 100644 index 00000000000..c0c52d6f79a --- /dev/null +++ b/spec/integrity/js_constants_spec.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +require "rails_helper" + +describe "constants match ruby" do + + let(:ctx) { MiniRacer::Context.new } + + def parse(file) + # mini racer doesn't handle JS modules so we'll do this hack + source = File.read("#{Rails.root}/app/assets/javascripts/#{file}") + source.gsub!(/^export */, '') + ctx.eval(source) + end + + it "has the correct values" do + parse("discourse/app/lib/constants.js") + parse("pretty-text/addon/emoji/version.js") + + priorities = ctx.eval("SEARCH_PRIORITIES") + Searchable::PRIORITIES.each do |key, value| + expect(priorities[key.to_s]).to eq(value) + end + + expect(ctx.eval("SEARCH_PHRASE_REGEXP")).to eq(Search::PHRASE_MATCH_REGEXP_PATTERN) + expect(ctx.eval("IMAGE_VERSION")).to eq(Emoji::EMOJI_VERSION) + end + +end