discourse/spec/system/theme_qunit_spec.rb
David Taylor 9667485951
DEV: Stop building test assets in production under Embroider ()
Until now, we have allowed testing themes in production environments via `/theme-qunit`. This was made possible by hacking the ember-cli build so that it would create the `tests.js` bundle in production. However, this is fundamentally problematic because a number of test-specific things are still optimized out of the Ember build in production mode. It also makes asset compilation significantly slower, and makes it more difficult for us to update our build pipeline (e.g. to introduce Embroider).

This commit removes the ability to run qunit tests in production builds of the JS app when the Embdroider flag is enabled. If a production instance of Discourse exists exclusively for the development of themes (e.g. discourse.theme-creator.io) then they can add `EMBER_ENV: development` to their `app.yml` file. This will build the entire app in development mode, and has a significant performance impact. This must not be used for real production sites.

This commit also refactors many of the request specs into system specs. This means that the tests are guaranteed to have Ember assets built, and is also a better end-to-end test than simply checking for the presence of certain `<script>` tags in the HTML.
2023-09-11 09:12:37 +01:00

40 lines
1.3 KiB
Ruby

# frozen_string_literal: true
describe "Theme qunit testing", type: :system do
let!(:theme_without_tests) { Fabricate(:theme, name: "no-tests-guy") }
let!(:theme_with_test) do
t = Fabricate(:theme, name: "Theme With Tests")
t.set_field(target: :tests_js, type: :js, name: "acceptance/some-test.js", value: <<~JS)
import { module, test } from "qunit";
module("theme test", function () {
test("it works", function (assert) {
assert.true(true)
});
});
JS
t.build_remote_theme(remote_url: "https://example.com/mytheme")
t.save!
t
end
it "lists themes and can run tests by id, name and url" do
visit "/theme-qunit"
expect(page).to have_css("a[href^='/theme-qunit?id=']", count: 1)
find("a[href=\"/theme-qunit?id=#{theme_with_test.id}\"]").click
success_count = find("#qunit-testresult-display .passed").text
expect(success_count).to eq("1")
visit "/theme-qunit?name=#{theme_with_test.name}"
success_count = find("#qunit-testresult-display .passed").text
expect(success_count).to eq("1")
visit "/theme-qunit?url=#{theme_with_test.remote_theme.remote_url}"
success_count = find("#qunit-testresult-display .passed").text
expect(success_count).to eq("1")
end
end