DEV: Adds an integrity spec for JS constants

DEV: Adds an integrity spec for JS constants

diff --git a/spec/integrity/js_constants_spec.rb b/spec/integrity/js_constants_spec.rb
new file mode 100644
index 0000000..c0c52d6
--- /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

GitHub sha: 033644ea

1 Like

Instead of having an integrity spec, could we set the constant by using the erb extension?

export const IMAGE_VERSION = <%= Emoji::EMOJI_VERSION %>;

@tgxworld this entire thing happened because we are removing the erb extension. We can’t run Ruby in Ember CLI.

@eviltrout Got it :slight_smile: Does ember-cli use webpack?

@tgxworld not exactly. For most of the app it will not, but we can import directly from npm using webpack using the included GitHub - ef4/ember-auto-import: Zero config import from npm packages library.

Is there a feature from webpack you wanted to use?

1 Like

No particular feature I need :slight_smile: Was trying to understand what we’ll be using for assets management so we know what tools we have at our disposal in the future.

1 Like