Skip to content

Commit

Permalink
move to require.extensions ava approach
Browse files Browse the repository at this point in the history
  • Loading branch information
lunelson committed Mar 5, 2019
1 parent 8955e55 commit 15d31f4
Show file tree
Hide file tree
Showing 11 changed files with 254 additions and 7 deletions.
30 changes: 30 additions & 0 deletions package-lock.json

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

14 changes: 12 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
},
"scripts": {
"test": "ava",
"start": "ava --watch --serial",
"start": "ava --watch",
"beforeStage": "npx auto-changelog"
},
"devDependencies": {
Expand All @@ -34,6 +34,7 @@
"ava": "^1.0.1",
"del": "^3.0.0",
"node-sass": "^4.11.0",
"require-extension-hooks": "^0.3.3",
"sass": "^1.15.2",
"write": "^1.0.3"
},
Expand All @@ -46,8 +47,17 @@
},
"ava": {
"verbose": true,
"extensions": [
"scss"
],
"compileEnhancements": false,
"require": [
"./tests/helpers/setup.js"
],
"files": [
"tests/*{.js,.scss}"
"tests/*.scss",
"!**/_*/**",
"!**/_*"
],
"sources": [
"_index.scss",
Expand Down
38 changes: 38 additions & 0 deletions tests/_holding/renders/scratch.dartsass.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
.private {
result: 1.5;
result: 0.15;
/* NB ref units will always be px or rem */
result: 0.8333333333;
result: 1.2;
}

.bad-args {
/* domain units must be em, %, or one of vw, vh, vmin, vmax */
result: "ERROR: lerp($table, $domain: 100vw, $rem-px: 16): $domain [1rem] invalid; unit must be one of the following: vw, vh, vmin, vmax, %, em";
/* table key units must be px or rem */
result: "ERROR: lerp($table, $domain: 100vw, $rem-px: 16): $table key [50%] invalid; unit must be rem or px";
/* domain v* allows only px and rem table vals */
/* domain % allows only px, rem and % table vals */
result: "ERROR: lerp($table, $domain: 100vw, $rem-px: 16): $table $val [0.5em] invalid for $domain 100%; unit must be one of the following: px rem %";
/* domain em allows px, rem, % and em table vals */
}

.viewport-relative {
result: calc(75vw - 100px);
result: calc(8vw + 16px);
}

.parent-relative {
/* following should be equal */
result: calc(0.8333333333em + 13.3333333333px);
result: calc(0.8333333333em + 13.3333333333px);
result: calc(0.8333333333em + 13.3333333333px);
/* the following will mean the same, if applied to a font-size relative property e.g line-height */
result: calc(110% - 60px);
result: calc(1.1em - 60px);
/* container related */
result: calc(110% - 60px);
result: calc(30% + 20px);
result: calc(13.3333333333% - 1.6666666667rem);
result: calc(100% - 10rem);
}
38 changes: 38 additions & 0 deletions tests/_holding/renders/scratch.libsass.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
.private {
result: 1.5;
result: 0.15;
/* NB ref units will always be px or rem */
result: 0.83333;
result: 1.2;
}

.bad-args {
/* domain units must be em, %, or one of vw, vh, vmin, vmax */
result: "ERROR: lerp($table, $domain: 100vw, $rem-px: 16): $domain [1rem] invalid; unit must be one of the following: vw, vh, vmin, vmax, %, em";
/* table key units must be px or rem */
result: "ERROR: lerp($table, $domain: 100vw, $rem-px: 16): $table key [50%] invalid; unit must be rem or px";
/* domain v* allows only px and rem table vals */
/* domain % allows only px, rem and % table vals */
result: "ERROR: lerp($table, $domain: 100vw, $rem-px: 16): $table $val [0.5em] invalid for $domain 100%; unit must be one of the following: px rem %";
/* domain em allows px, rem, % and em table vals */
}

.viewport-relative {
result: calc(75vw - 100px);
result: calc(8vw + 16px);
}

.parent-relative {
/* following should be equal */
result: calc(0.83333em + 13.33333px);
result: calc(0.83333em + 13.33333px);
result: calc(0.83333em + 13.33333px);
/* the following will mean the same, if applied to a font-size relative property e.g line-height */
result: calc(110% - 60px);
result: calc(1.1em - 60px);
/* container related */
result: calc(110% - 60px);
result: calc(30% + 20px);
result: calc(13.33333% - 1.66667rem);
result: calc(100% - 10rem);
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
39 changes: 39 additions & 0 deletions tests/helpers/setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// @ts-nocheck

var hooks = require('require-extension-hooks');

hooks('.scss').push(() => {
return `
const path = require('path');
const writeFile = require('write');
const test = require('ava');
const compilers = {
dartsass: require('sass'),
libsass: require('node-sass'),
};
function render(compiler, file) {
return new Promise((resolve, reject) => {
compiler.render({
file,
includePaths: [__dirname, path.resolve(__dirname, '../node_modules')],
outputStyle: 'expanded',
precision: 10
}, (err, data) => {
if (err) reject(err.formatted);
else resolve(data.css.toString());
});
});
}
Object.keys(compilers).forEach(compiler => {
const outFile = path.join(__dirname, 'renders', path.relative(__dirname, __filename)).replace(/\.scss$/, '.'+compiler+'.css');
test(path.basename(__filename, path.extname(__filename))+'['+compiler+']', t => {
return render(compilers[compiler], __filename).then(css => {
writeFile.sync(outFile, css);
t.snapshot(css);
});
});
});
`;
});
10 changes: 5 additions & 5 deletions tests/renders/scratch.libsass.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
result: 1.5;
result: 0.15;
/* NB ref units will always be px or rem */
result: 0.83333;
result: 0.8333333333;
result: 1.2;
}

Expand All @@ -24,15 +24,15 @@

.parent-relative {
/* following should be equal */
result: calc(0.83333em + 13.33333px);
result: calc(0.83333em + 13.33333px);
result: calc(0.83333em + 13.33333px);
result: calc(0.8333333333em + 13.3333333333px);
result: calc(0.8333333333em + 13.3333333333px);
result: calc(0.8333333333em + 13.3333333333px);
/* the following will mean the same, if applied to a font-size relative property e.g line-height */
result: calc(110% - 60px);
result: calc(1.1em - 60px);
/* container related */
result: calc(110% - 60px);
result: calc(30% + 20px);
result: calc(13.33333% - 1.66667rem);
result: calc(13.3333333333% - 1.6666666667rem);
result: calc(100% - 10rem);
}
92 changes: 92 additions & 0 deletions tests/snapshots/scratch.scss.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# Snapshot report for `tests/scratch.scss`

The actual snapshot is saved in `scratch.scss.snap`.

Generated by [AVA](https://ava.li).

## scratch[dartsass]

> Snapshot 1
`.private {␊
result: 1.5;␊
result: 0.15;␊
/* NB ref units will always be px or rem */␊
result: 0.8333333333;␊
result: 1.2;␊
}␊
.bad-args {␊
/* domain units must be em, %, or one of vw, vh, vmin, vmax */␊
result: "ERROR: lerp($table, $domain: 100vw, $rem-px: 16): $domain [1rem] invalid; unit must be one of the following: vw, vh, vmin, vmax, %, em";␊
/* table key units must be px or rem */␊
result: "ERROR: lerp($table, $domain: 100vw, $rem-px: 16): $table key [50%] invalid; unit must be rem or px";␊
/* domain v* allows only px and rem table vals */␊
/* domain % allows only px, rem and % table vals */␊
result: "ERROR: lerp($table, $domain: 100vw, $rem-px: 16): $table $val [0.5em] invalid for $domain 100%; unit must be one of the following: px rem %";␊
/* domain em allows px, rem, % and em table vals */␊
}␊
.viewport-relative {␊
result: calc(75vw - 100px);␊
result: calc(8vw + 16px);␊
}␊
.parent-relative {␊
/* following should be equal */␊
result: calc(0.8333333333em + 13.3333333333px);␊
result: calc(0.8333333333em + 13.3333333333px);␊
result: calc(0.8333333333em + 13.3333333333px);␊
/* the following will mean the same, if applied to a font-size relative property e.g line-height */␊
result: calc(110% - 60px);␊
result: calc(1.1em - 60px);␊
/* container related */␊
result: calc(110% - 60px);␊
result: calc(30% + 20px);␊
result: calc(13.3333333333% - 1.6666666667rem);␊
result: calc(100% - 10rem);␊
}`

## scratch[libsass]

> Snapshot 1
`.private {␊
result: 1.5;␊
result: 0.15;␊
/* NB ref units will always be px or rem */␊
result: 0.8333333333;␊
result: 1.2;␊
}␊
.bad-args {␊
/* domain units must be em, %, or one of vw, vh, vmin, vmax */␊
result: "ERROR: lerp($table, $domain: 100vw, $rem-px: 16): $domain [1rem] invalid; unit must be one of the following: vw, vh, vmin, vmax, %, em";␊
/* table key units must be px or rem */␊
result: "ERROR: lerp($table, $domain: 100vw, $rem-px: 16): $table key [50%] invalid; unit must be rem or px";␊
/* domain v* allows only px and rem table vals */␊
/* domain % allows only px, rem and % table vals */␊
result: "ERROR: lerp($table, $domain: 100vw, $rem-px: 16): $table $val [0.5em] invalid for $domain 100%; unit must be one of the following: px rem %";␊
/* domain em allows px, rem, % and em table vals */␊
}␊
.viewport-relative {␊
result: calc(75vw - 100px);␊
result: calc(8vw + 16px);␊
}␊
.parent-relative {␊
/* following should be equal */␊
result: calc(0.8333333333em + 13.3333333333px);␊
result: calc(0.8333333333em + 13.3333333333px);␊
result: calc(0.8333333333em + 13.3333333333px);␊
/* the following will mean the same, if applied to a font-size relative property e.g line-height */␊
result: calc(110% - 60px);␊
result: calc(1.1em - 60px);␊
/* container related */␊
result: calc(110% - 60px);␊
result: calc(30% + 20px);␊
result: calc(13.3333333333% - 1.6666666667rem);␊
result: calc(100% - 10rem);␊
}␊
`
Binary file added tests/snapshots/scratch.scss.snap
Binary file not shown.

0 comments on commit 15d31f4

Please sign in to comment.