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

Add SCSS testing of the utilities API #36029

Merged
merged 15 commits into from
Dec 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/css.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,8 @@ jobs:
- name: Install npm dependencies
run: npm ci

- name: Run CSS tests
run: npm run css-test

- name: Build CSS
run: npm run css
11 changes: 10 additions & 1 deletion .stylelintrc
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,14 @@
}
],
"scss/selector-no-union-class-name": true
}
},
"overrides": [
{
"files": "scss/**/*.{test,spec}.scss",
"rules": {
"scss/dollar-variable-default": null,
"declaration-no-important": null
}
}
]
}
3,855 changes: 2,051 additions & 1,804 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"css-prefix-main": "postcss --config build/postcss.config.js --replace \"dist/css/*.css\" \"!dist/css/*.rtl*.css\" \"!dist/css/*.min.css\"",
"css-prefix-examples": "postcss --config build/postcss.config.js --replace \"site/content/**/*.css\"",
"css-prefix-examples-rtl": "cross-env-shell NODE_ENV=RTL postcss --config build/postcss.config.js --dir \"site/content/docs/$npm_package_config_version_short/examples/\" --ext \".rtl.css\" --base \"site/content/docs/$npm_package_config_version_short/examples/\" \"site/content/docs/$npm_package_config_version_short/examples/{blog,carousel,dashboard,cheatsheet}/*.css\" \"!site/content/docs/$npm_package_config_version_short/examples/{blog,carousel,dashboard,cheatsheet}/*.rtl.css\"",
"css-test": "jasmine --config=scss/tests/jasmine.js",
"js": "npm-run-all js-compile js-minify",
"js-compile": "npm-run-all --aggregate-output --parallel js-compile-*",
"js-compile-standalone": "rollup --environment BUNDLE:false --config build/rollup.config.js --sourcemap",
Expand Down Expand Up @@ -94,6 +95,7 @@
"watch-css-main": "nodemon --watch scss/ --ext scss --exec \"npm-run-all css-lint css-compile css-prefix\"",
"watch-css-dist": "nodemon --watch dist/css/ --ext css --ignore \"dist/css/*.rtl.*\" --exec \"npm run css-rtl\"",
"watch-css-docs": "nodemon --watch site/assets/scss/ --ext scss --exec \"npm run css-lint\"",
"watch-css-test": "nodemon --watch scss/ --ext scss,js --exec \"npm run css-test\"",
"watch-js-main": "nodemon --watch js/src/ --ext js --exec \"npm-run-all js-lint js-compile\"",
"watch-js-docs": "nodemon --watch site/assets/js/ --ext js --exec \"npm run js-lint\""
},
Expand Down Expand Up @@ -124,6 +126,7 @@
"hammer-simulator": "0.0.1",
"hugo-bin": "^0.96.0",
"ip": "^2.0.0",
"jasmine": "^4.0.2",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about using the latest jasmine 3.x so that we don't use duplicate packages? We can update to 4.x when karma-jasmine is updated too.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Damn, I'm very confused as to which packages get pulled now. I had originally found a 3.x (3.6 I think), then this morning I looked in the node-modules before adding Jasmine and jasmine-core was 4.0.1. I'll double check on the main branch after clearing node-modules 😄

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, so on main, there's two jasmine-core pulled:

  • one inside karma-jasmine, which is 3.99.1 (brought from it requiring ^3.6.0)
  • one at the root of node-modules, which is 4.0.1 (this one I'm not sure of the origin, but I'd guess karma-jasmine-html-reporter with >=3.8)

I'll try and align if I can 😄

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should stick to 3.x which is what we specify. The v4.x is a dependency of a dependency, not a direct one.

"jquery": "^3.6.2",
"karma": "^6.4.1",
"karma-browserstack-launcher": "1.4.0",
Expand All @@ -143,6 +146,7 @@
"rollup-plugin-istanbul": "^4.0.0",
"rtlcss": "^4.0.0",
"sass": "^1.57.1",
"sass-true": "^6.1.0",
"shelljs": "^0.8.5",
"stylelint": "^14.16.0",
"stylelint-config-twbs-bootstrap": "^7.0.0",
Expand Down
2 changes: 1 addition & 1 deletion scss/mixins/_utilities.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Utility generator
// Used to generate utilities & print utilities
@mixin generate-utility($utility, $infix, $is-rfs-media-query: false) {
@mixin generate-utility($utility, $infix: "", $is-rfs-media-query: false) {
$values: map-get($utility, values);

// If the values are a list or string, convert it into a map
Expand Down
17 changes: 17 additions & 0 deletions scss/tests/jasmine.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/* eslint-env node */

const path = require('node:path')

module.exports = {
spec_dir: 'scss' /* eslint-disable-line camelcase */,

// Make Mocha look for `.test.scss` files
spec_files: ['**/*.{test,spec}.scss'] /* eslint-disable-line camelcase */,

// Compile them into JS scripts running `sass-true`
requires: [path.join(__dirname, 'sass-true/register')],

// Ensure we use `require` so that the require.extensions works
// as `import` completely bypasses it
jsLoader: 'require'
}
69 changes: 69 additions & 0 deletions scss/tests/mixins/_color-modes.test.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// stylelint-disable selector-attribute-quotes

@import "../../functions";
@import "../../variables";
@import "../../variables-dark";
@import "../../maps";
@import "../../mixins";

@include describe("global $color-mode-type: data") {
@include it("generates data attribute selectors for dark mode") {
@include assert() {
@include output() {
@include color-mode(dark) {
.element {
color: var(--bs-primary-text);
background-color: var(--bs-primary-bg-subtle);
}
}
@include color-mode(dark, true) {
--custom-color: #{mix($indigo, $blue, 50%)};
}
}
@include expect() {
[data-bs-theme=dark] .element {
color: var(--bs-primary-text);
background-color: var(--bs-primary-bg-subtle);
}
[data-bs-theme=dark] {
--custom-color: #3a3ff8;
}
}
}
}
}

@include describe("global $color-mode-type: media-query") {
@include it("generates media queries for dark mode") {
$color-mode-type: media-query !global;

@include assert() {
@include output() {
@include color-mode(dark) {
.element {
color: var(--bs-primary-text);
background-color: var(--bs-primary-bg-subtle);
}
}
@include color-mode(dark, true) {
--custom-color: #{mix($indigo, $blue, 50%)};
}
}
@include expect() {
@media (prefers-color-scheme: dark) {
.element {
color: var(--bs-primary-text);
background-color: var(--bs-primary-bg-subtle);
}
}
@media (prefers-color-scheme: dark) {
:root {
--custom-color: #3a3ff8;
}
}
}
}

$color-mode-type: data !global;
}
}
Loading