DEV: Allow running theme-qunit tests via testem (#16540)

This allows `QUNIT_EMBER_CLI=1 bin/rake theme:qunit[...]` to test themes using `testem` with Ember-CLI-generated assets
This commit is contained in:
David Taylor 2022-04-22 15:04:01 +01:00 committed by GitHub
parent 3010c5fd74
commit 127ba698a7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 4 deletions

View File

@ -68,8 +68,20 @@ module.exports = {
reporter: Reporter,
};
if (shouldLoadPluginTestJs()) {
const target = `http://localhost:${process.env.UNICORN_PORT || "3000"}`;
const target = `http://localhost:${process.env.UNICORN_PORT || "3000"}`;
if (process.argv.includes("-t")) {
// Running testem without ember cli. Probably for theme-qunit
const testPage = process.argv[process.argv.indexOf("-t") + 1];
module.exports.proxies = {};
module.exports.proxies[`/*/theme-qunit`] = {
target: `${target}${testPage}`,
ignorePath: true,
};
module.exports.proxies["/*/*"] = { target };
} else if (shouldLoadPluginTestJs()) {
// Running with ember cli, but we want to pass through plugin request to Rails
module.exports.proxies = {
"/assets/discourse/tests/active-plugins.js": {
target,

View File

@ -28,6 +28,9 @@
}
</style>
<%- end %>
<%- if params['testem'] %>
<script src="/testem.js"></script>
<%- end %>
</head>
<body>
<%- if !@suggested_themes %>

View File

@ -106,8 +106,16 @@ task "qunit:test", [:timeout, :qunit_path] do |_, args|
puts "Rails server is warmed up"
if ember_cli
cmd = ["env", "UNICORN_PORT=#{unicorn_port}", "yarn", "ember", "test", "--query", query]
cmd += ["--test-page", qunit_path.delete_prefix("/")] if qunit_path
cmd = ["env", "UNICORN_PORT=#{unicorn_port}"]
if qunit_path
# Bypass `ember test` - it only works properly for the `/tests` path.
# We have to trigger a `build` manually so that JS is available for rails to serve.
system("yarn", "ember", "build", chdir: "#{Rails.root}/app/assets/javascripts/discourse")
test_page = "#{qunit_path}?#{query}&testem=1"
cmd += ["yarn", "testem", "ci", "-f", "testem.js", "-t", test_page]
else
cmd += ["yarn", "ember", "test", "--query", query]
end
system(*cmd, chdir: "#{Rails.root}/app/assets/javascripts/discourse")
else
cmd = "node #{test_path}/run-qunit.js http://localhost:#{port}#{qunit_path}"