summaryrefslogtreecommitdiff
path: root/test/astro-styles-ssr.test.js
diff options
context:
space:
mode:
authorGravatar Drew Powers <1369770+drwpow@users.noreply.github.com> 2021-03-30 10:11:21 -0600
committerGravatar GitHub <noreply@github.com> 2021-03-30 10:11:21 -0600
commitee6ef81cf38acc357141143319addf39a99d3e19 (patch)
tree1fd6032709f74253dcb5a30630da70d2e4373a40 /test/astro-styles-ssr.test.js
parentd267fa461b73586118437e190b92b9956f9add73 (diff)
downloadastro-ee6ef81cf38acc357141143319addf39a99d3e19.tar.gz
astro-ee6ef81cf38acc357141143319addf39a99d3e19.tar.zst
astro-ee6ef81cf38acc357141143319addf39a99d3e19.zip
Convert CSS Modules to scoped styles (#38)
* Convert CSS Modules to scoped styles * Update README * Move class scoping into HTML walker * Fix SSR styles test * Fix mustache tags * Update PostCSS plugin name * Add JSDoc comment * Update test
Diffstat (limited to 'test/astro-styles-ssr.test.js')
-rw-r--r--test/astro-styles-ssr.test.js20
1 files changed, 20 insertions, 0 deletions
diff --git a/test/astro-styles-ssr.test.js b/test/astro-styles-ssr.test.js
index 9145e65a9..9ee67f69b 100644
--- a/test/astro-styles-ssr.test.js
+++ b/test/astro-styles-ssr.test.js
@@ -47,4 +47,24 @@ StylesSSR('Has correct CSS classes', async () => {
}
});
+StylesSSR('CSS Module support in .astro', async () => {
+ const result = await runtime.load('/');
+ const $ = doc(result.contents);
+
+ let scopedClass;
+
+ // test 1: <style> tag in <head> is transformed
+ const css = $('style')
+ .html()
+ .replace(/\.astro-[A-Za-z0-9-]+/, (match) => {
+ scopedClass = match;
+ return match;
+ }); // remove class hash (should be deterministic / the same every time, but even still don‘t cause this test to flake)
+ assert.equal(css, `.wrapper${scopedClass}{margin-left:auto;margin-right:auto;max-width:1200px}`);
+
+ // test 2: element received .astro-XXXXXX class (this selector will succeed if transformed correctly)
+ const wrapper = $(`.wrapper${scopedClass}`);
+ assert.equal(wrapper.length, 1);
+});
+
StylesSSR.run();