Skip to content
This repository has been archived by the owner on Jan 22, 2021. It is now read-only.

Commit

Permalink
Added support for scss in unit-test mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Henning committed Oct 27, 2016
1 parent 7aa35bf commit be673de
Showing 1 changed file with 39 additions and 12 deletions.
51 changes: 39 additions & 12 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,21 @@ const sass = (function() {
return null;
})();

/**
* Check if file exists
* @param {String} filePath
* @return {Boolean}
*/
const fileExists = function (filePath) {
try {
return fs.statSync(filePath).isFile();
}
catch (err)
{
return false;
}
}

const TAG = 'mailer-utils';

// This package assumes that assets (templates, SCSS, CSS ..) are
Expand All @@ -37,7 +52,6 @@ const TAG = 'mailer-utils';
// /var/www/app/bundle
//
// For Modulus, you need to use the `APP_DIR` variable, which you do NOT need to set.

const developmentPrivateDir = () => {
if (!isDevEnv) {
return '';
Expand Down Expand Up @@ -164,7 +178,7 @@ Utils = {
// background-info: we had NO luck with "Assets.absoluteFilePath(relativePathFromApp)",
// so lets build the path ourselves.
// see discussion https://github.com/lookback/meteor-emails/issues/76
file = Path.join(process.cwd(), 'assets', 'app', relativePathFromApp)
file = Path.join(process.cwd(), 'assets', 'app', relativePathFromApp);
} else {
// = standard mode (development || production)
file = Path.join(ROOT, relativePathFromApp);
Expand Down Expand Up @@ -192,17 +206,30 @@ ${packageToRecommend}`, TAG);
return Utils.readFile(scss);
}

const file = Path.join(ROOT, scss);
let file
if (Meteor.isAppTest
|| Meteor.isTest) {
// note:
// * this DOES WORK with Meteor.isTest (=unit test mode)
// * Meteor.isAppTest is NOT TESTED yet (=in-app test mode)
file = Path.join(process.cwd(), 'assets', 'app', scss);
} else {
// = standard mode (development || production)
file = Path.join(ROOT, scss);
}

try {
return sass.renderSync({
file: file,
sourceMap: false
}).css.toString();
} catch (ex) {
console.error(`Sass failed to compile: ${ex.message}`);
console.error(`In ${ex.file || scss} at line ${ex.line}, column ${ex.column}`);
return '';
if (fileExists(file)) {
console.log('SCSS EXISTS')
try {
return sass.renderSync({
file: file,
sourceMap: false
}).css.toString();
} catch (ex) {
console.error(`Sass failed to compile: ${ex.message}`);
console.error(`In ${ex.file || scss} at line ${ex.line}, column ${ex.column}`);
}
}
return ''; // fallback: on error, or if file does NOT exist
}
};

0 comments on commit be673de

Please sign in to comment.