Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: introduce theme config and add qunit-theme-ember as option #1166

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
7 changes: 7 additions & 0 deletions addon/README.md
Expand Up @@ -189,6 +189,13 @@ module.exports = function (defaults) {
* removes the CSS for the test-container (where the app and components are rendered to)
*/
disableContainerStyles: true,
/**
* default: 'ember'
* options: 'ember' | 'qunit-default'
*
* Sets the theme for the Web UI of the test runner. Use a different value to disable loading any theme, allowing you to provide your own external one.
*/
theme: 'ember',
},
},
},
Expand Down
3 changes: 2 additions & 1 deletion addon/package.json
Expand Up @@ -43,7 +43,8 @@
"dependencies": {
IgnaceMaes marked this conversation as resolved.
Show resolved Hide resolved
"@embroider/addon-shim": "^1.8.6",
"@embroider/macros": "^1.13.1",
"ember-cli-test-loader": "^3.1.0"
"ember-cli-test-loader": "^3.1.0",
"qunit-theme-ember": "^0.2.0"
},
"devDependencies": {
"@babel/core": "^7.23.2",
Expand Down
23 changes: 21 additions & 2 deletions addon/src/index.js
@@ -1,12 +1,31 @@
/* globals Testem */
import 'qunit/qunit/qunit.css';

import { macroCondition, getOwnConfig, importSync } from '@embroider/macros';

/**
* Load qunit-theme-ember by default, if no custom theme is specified.
*/
if (
macroCondition(
getOwnConfig()?.theme === undefined ||
getOwnConfig()?.theme === 'qunit-default' ||
getOwnConfig()?.theme === 'ember'
)
) {
importSync('qunit/qunit/qunit.css');
}

if (macroCondition(!getOwnConfig()?.disableContainerStyles)) {
importSync('./test-container-styles.css');
}

if (
macroCondition(
getOwnConfig()?.theme === undefined || getOwnConfig()?.theme === 'ember'
)
) {
importSync('qunit-theme-ember/qunit.css');
}

export { default as QUnitAdapter, nonTestDoneCallback } from './adapter';
export { loadTests } from './test-loader';

Expand Down
7 changes: 7 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions test-buildtime-options-app/ember-cli-build.js
Expand Up @@ -11,6 +11,7 @@ module.exports = function (defaults) {
setConfig: {
'ember-qunit': {
disableContainerStyles: true,
theme: 'qunit-default',
},
},
},
Expand Down
17 changes: 17 additions & 0 deletions test-buildtime-options-app/tests/unit/theme-test.js
@@ -0,0 +1,17 @@
import { module, test } from 'qunit';
import { assert as debugAssert } from '@ember/debug';

module('theme', function () {
function style(element) {
return window.getComputedStyle(element);
}

test('the qunit-default themes are present when used', async function (assert) {
let qunitHeader = document.getElementById('qunit-header');

debugAssert(`#qunit-header must exist`, qunitHeader);

// Defaults
assert.strictEqual(style(qunitHeader).backgroundColor, 'rgb(13, 51, 73)');
});
});