Deploy Foundation for Apps on Heroku - heroku

I am trying to deploy an app created with "Foundation for Apps" on Heroku with no success.
Package.json:
{
"name": "foundation-apps-template",
"version": "1.0.3",
"scripts": {
"start": "gulp",
"postinstall": "bower install"
},
"dependencies": {
"bower": "^1.3.12",
"connect-modrewrite": "^0.7.9",
"front-matter": "^0.2.0",
"gulp": "^3.8.10",
"gulp-autoprefixer": "^1.0.1",
"gulp-concat": "^2.4.2",
"gulp-connect": "^2.2.0",
"gulp-load-plugins": "^0.8.0",
"gulp-ruby-sass": "^0.7.1",
"gulp-uglify": "^1.0.2",
"gulp-util": "^3.0.1",
"rimraf": "^2.2.8",
"run-sequence": "^1.0.2",
"through2": "^0.6.3"
},
"devDependencies": {
"connect-modrewrite": "^0.7.9",
"front-matter": "^0.2.0",
"gulp": "^3.8.10",
"gulp-autoprefixer": "^1.0.1",
"gulp-concat": "^2.4.2",
"gulp-connect": "^2.2.0",
"gulp-load-plugins": "^0.8.0",
"gulp-ruby-sass": "^0.7.1",
"gulp-uglify": "^1.0.2",
"gulp-util": "^3.0.1",
"rimraf": "^2.2.8",
"run-sequence": "^1.0.2",
"through2": "^0.6.3"
},
"private": true
}
gulpfile.js
// FOUNDATION FOR APPS TEMPLATE GULPFILE
// -------------------------------------
// This file processes all of the assets in the "client" folder, combines them with the Foundation
// for Apps assets, and outputs the finished files in the "build" folder as a finished app.
// 1. LIBRARIES
// - - - - - - - - - - - - - - -
var gulp = require('gulp'),
$ = require('gulp-load-plugins')(),
rimraf = require('rimraf'),
sequence = require('run-sequence'),
path = require('path'),
modRewrite = require('connect-modrewrite'),
router = require('./bower_components/foundation-apps/bin/gulp-dynamic-routing');
// 2. SETTINGS VARIABLES
// - - - - - - - - - - - - - - -
// Sass will check these folders for files when you use #import.
var sassPaths = [
'client/assets/scss',
'bower_components/foundation-apps/scss'
];
// These files include Foundation for Apps and its dependencies
var foundationJS = [
'bower_components/fastclick/lib/fastclick.js',
'bower_components/viewport-units-buggyfill/viewport-units-buggyfill.js',
'bower_components/tether/tether.js',
'bower_components/angular/angular.js',
'bower_components/angular-animate/angular-animate.js',
'bower_components/angular-ui-router/release/angular-ui-router.js',
'bower_components/foundation-apps/js/vendor/**/*.js',
'bower_components/foundation-apps/js/angular/**/*.js',
'!bower_components/foundation-apps/js/angular/app.js'
];
// These files are for your app's JavaScript
var appJS = [
'client/assets/js/app.js'
];
// 3. TASKS
// - - - - - - - - - - - - - - -
// Cleans the build directory
gulp.task('clean', function(cb) {
rimraf('./build', cb);
});
// Copies user-created files and Foundation assets
gulp.task('copy', function() {
var dirs = [
'./client/**/*.*',
'!./client/templates/**/*.*',
'!./client/assets/{scss,js}/**/*.*'
];
// Everything in the client folder except templates, Sass, and JS
gulp.src(dirs, {
base: './client/'
})
.pipe(gulp.dest('./build'));
// Iconic SVG icons
gulp.src('./bower_components/foundation-apps/iconic/**/*')
.pipe(gulp.dest('./build/assets/img/iconic/'));
// Foundation's Angular partials
return gulp.src(['./bower_components/foundation-apps/js/angular/components/**/*.html'])
.pipe(gulp.dest('./build/components/'));
});
// Compiles Sass
gulp.task('sass', function() {
return gulp.src('client/assets/scss/app.scss')
.pipe($.rubySass({
loadPath: sassPaths,
style: 'nested',
bundleExec: true
})).on('error', function(e) {
console.log(e);
})
.pipe($.autoprefixer({
browsers: ['last 2 versions', 'ie 10']
}))
.pipe(gulp.dest('./build/assets/css/'));
});
// Compiles and copies the Foundation for Apps JavaScript, as well as your app's custom JS
gulp.task('uglify', function() {
// Foundation JavaScript
gulp.src(foundationJS)
.pipe($.uglify({
beautify: true,
mangle: false
}).on('error', function(e) {
console.log(e);
}))
.pipe($.concat('foundation.js'))
.pipe(gulp.dest('./build/assets/js/'))
;
// App JavaScript
return gulp.src(appJS)
.pipe($.uglify({
beautify: true,
mangle: false
}).on('error', function(e) {
console.log(e);
}))
.pipe($.concat('app.js'))
.pipe(gulp.dest('./build/assets/js/'))
;
});
// Copies your app's page templates and generates URLs for them
gulp.task('copy-templates', ['copy'], function() {
return gulp.src('./client/templates/**/*.html')
.pipe(router({
path: 'build/assets/js/routes.js',
root: 'client'
}))
.pipe(gulp.dest('./build/templates'))
;
});
// Starts a test server, which you can view at http://localhost:8080
gulp.task('server:start', function() {
$.connect.server({
root: './build',
port: process.env.PORT || 5000,
livereload: false
});
});
// Builds your entire app once, without starting a server
gulp.task('build', function() {
sequence('clean', ['copy', 'sass', 'uglify'], 'copy-templates', function() {
console.log("Successfully built.");
})
});
// Default task: builds your app, starts a server, and recompiles assets when they change
gulp.task('default', ['build', 'server:start'], function() {
// Watch Sass
gulp.watch(['./client/assets/scss/**/*', './scss/**/*'], ['sass']);
// Watch JavaScript
gulp.watch(['./client/assets/js/**/*', './js/**/*'], ['uglify']);
// Watch static files
gulp.watch(['./client/**/*.*', '!./client/templates/**/*.*', '!./client/assets/{scss,js}/**/*.*'], ['copy']);
// Watch app templates
gulp.watch(['./client/templates/**/*.html'], ['copy-templates']);
});
When I deploy, the app successfully build with one exception:
> gulp
> foundation-apps-template#1.0.3 start /app
[22:41:04] Using gulpfile ~/gulpfile.js
[22:41:04] Starting 'clean'...
[22:41:04] Starting 'build'...
[22:41:04] Starting 'server:start'...
[22:41:04] Starting 'default'...
[22:41:04] Finished 'server:start' after 323 ms
[22:41:04] Server started http://localhost:23921
[22:41:04] Finished 'build' after 343 ms
[22:41:04] Finished 'default' after 40 ms
[22:41:04] Starting 'sass'...
[22:41:04] Finished 'clean' after 386 ms
[22:41:04] Starting 'copy'...
State changed from starting to up
[22:41:05] Starting 'uglify'...
{ [Error: spawn bundle ENOENT]
showProperties: true,
errno: 'ENOENT',
message: 'spawn bundle ENOENT',
code: 'ENOENT',
syscall: 'spawn bundle',
path: 'bundle',
plugin: 'gulp-ruby-sass' }
name: 'Error',
stack: 'Error: spawn bundle ENOENT\n at exports._errnoException (util.js:746:11)\n at Process.ChildProcess._handle.onexit (child_process.js:1046:32)\n at child_process.js:1137:20\n at process._tickCallback (node.js:355:11)',
showStack: false,
[22:41:08] Finished 'sass' after 3.64 s
[22:41:08] Finished 'uglify' after 3.28 s
Successfully built.
After that, when I open the browser, I see the website, without CSS styles.
https://fierce-escarpment-9048.herokuapp.com/assets/css/app.css
404 Not Found
I suspect that - because of that exception with sass - the CSS file was not generated and - therefore - is not reachable to the server.
Any suggestion how I can fix it?

The specific errors you have posted actually relate to JavaScript, and most likely server-side JavaScript in the form of Node.js. The "ENOENT" is specific to errors reported from Node.js' libuv component ( https://github.com/joyent/node/blob/master/deps/uv/include/uv.h ), and as you can see from the provided link relates to "no such file or directory".
So, your problem from the error logs/gulpfile.js is that the 'default' action initiates the task comprising of concurrent actions 'build' and 'server-start' (gulpfile.js, line 144). The 'build' task itself is a function (line 137) that initiates a sequence starting with 'clean' (line 138) to which we should return. But first, 'server-start'... your server does start: "Starting 'server:start'... Finished 'server:start' after 323 ms... Server started http://localhost:23921...State changed from starting to up." So, you can see the matching output of "Starting [x]... Finished [x]" pairs captured in the logs. This is significant.
Returning to the 'build' task. That causes 'clean', followed by the concurrent actions of 'copy', 'sass' and 'uglify'; it is within this latter group that your problem occurred. Firstly, note we have "Starting 'clean'... Finished 'clean' after 386 ms" - again, we have the matched pair - and clean must occur before copy/sass/uglify. These are concurrent actions, and your problem is that the logged output is written apparently haphazardly as these tasks occur (thats true of the original overlapping build and start-server tasks too). So, we can see all of 'copy', 'sass' and 'uglify' start... but only 'sass' and 'uglify' finish! And, we have 'copy' start, and an otherwise unmatched/disassociated error message. Your error has arisen from the failure to 'copy', not from 'sass'! You failed to copy, and the (Node.js-based) server was raising "no such file or directory".
Sorry, I couldn't interpret what its failed to copy (perhaps content from the 'client' directory), but its concerning absent content - perhaps even a simple misspelt filename, or something very similar. You should probably examine closely the file content in your directory.

Found this guide where explains how to deploy a Foundation for apps to heroku, I already tried it and works like a charm. Hope it helps.

Related

Custom Node server causes Nextjs to fail to load 'No `pages` directory found'

I'm trying to bootstrap a new Nextjs app, and for integrating with Auth0 I need my localhost to be running HTTPS. I followed the guide here (https://medium.com/responsetap-engineering/nextjs-https-for-a-local-dev-server-98bb441eabd7), and generated a local certificate which is in more trusted certificate store.
To use HTTPS for localhost, you apparently need to create a custom server (this seems an odd oversight on the Nextjs side), so here's my custom server:
const { createServer } = require('https');
const { parse } = require('url');
const next = require('next');
const fs = require('fs');
const dev = process.env.NODE_ENV !== 'production';
const app = next({ dev, dir: __dirname });
const handle = app.getRequestHandler();
const httpsOptions = {
key: fs.readFileSync('./certificates/ReactDevCertificate.key'),
cert: fs.readFileSync('./certificates/ReactDevCertificate.cer'),
};
app.prepare().then(() => {
createServer(httpsOptions, (req, res) => {
const parsedUrl = parse(req.url, true);
handle(req, res, parsedUrl);
}).listen(3000, (err) => {
if (err) throw err;
console.log('> Server started on https://localhost:3000');
});
});
Now, previous without the custom server, the app loads fine. But, with the custom server, it fails to load:
➜ yarn run dev
yarn run v1.22.15
$ next dev ./server.js
ready - started server on 0.0.0.0:3000, url: http://localhost:3000
Error: > No `pages` directory found. Did you mean to run `next` in the parent (`../`) directory?
at Object.findPagesDir (C:\Clients\ING\Framework\samples\fictionist-ui\node_modules\next\dist\lib\find-pages-dir.js:31:15)
at new DevServer (C:\Clients\ING\Framework\samples\fictionist-ui\node_modules\next\dist\server\dev\next-dev-server.js:110:44)
at NextServer.createServer (C:\Clients\ING\Framework\samples\fictionist-ui\node_modules\next\dist\server\next.js:102:20)
at C:\Clients\ING\Framework\samples\fictionist-ui\node_modules\next\dist\server\next.js:117:42
at async NextServer.prepare (C:\Clients\ING\Framework\samples\fictionist-ui\node_modules\next\dist\server\next.js:92:24)
at async C:\Clients\ING\Framework\samples\fictionist-ui\node_modules\next\dist\cli\next-dev.js:126:9
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
It feels like somewhere the app has navigated to a child folder, as there is code in the function find-pages-dir.js (https://github.com/vercel/next.js/blob/canary/packages/next/lib/find-pages-dir.ts#L22) that looks specifically to the parent directory for the pages folder.
For reference, here is my package.json:
{
"name": "fictionist-ui",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev ./server.js",
"build": "next build",
"start": "next start",
"lint": "next lint"
},
"dependencies": {
"next": "12.0.1",
"react": "17.0.2",
"react-dom": "17.0.2",
"semantic-ui-css": "^2.4.1",
"semantic-ui-react": "^2.0.4"
},
"devDependencies": {
"#types/node": "16.11.6",
"#types/react": "17.0.33",
"eslint": "7.32.0",
"eslint-config-next": "12.0.1",
"typescript": "4.4.4"
}
}
OS: Windows 11
NPM: 16.9.0
Yarn: 1.22.15
My mistake was that I didn't get the command right:
"scripts": {
"dev": "node server.js" // was "next dev ./server.js"
}

using ES2015 with mocha, karma and headless chrome for testing

I have a problem with setting up a test environment for a single page application. I am able to run my tests with headless chrome via karma and mocha but I can´t write tests with ES6 Syntax.
My current start command is
karma start --browsers ChromeHeadless karma.config.js --single-run
my karma.config.js
module.exports = function(config) {
config.set({
frameworks: ['mocha', 'chai'],
files: ['test/**/*spec.js'],
reporters: ['nyan'],
port: 9876, // karma web server port
colors: true,
logLevel: config.LOG_INFO,
browsers: ['ChromeHeadless'],
autoWatch: true,
singleRun: false, // Karma captures browsers, runs the tests and exits
concurrency: Infinity,
})
}
I am able to write normal tests but cant use ES6 Syntax here. When I try to import some react components I get this error:
HeadlessChrome 0.0.0 (Linux 0.0.0)
Uncaught SyntaxError: Unexpected token import
at http://localhost:9876/base/test/components.spec.js?b89d2ba6de494310860a60ad2e9e25aea5eb3657:2
So I have to setup babel somehow to compile my test files first. When I try to use compilers: ['js:babel-core/register'] in my karma config its not gonna work.
I also have seen that compilers seems to be deprecated soon so I also tried require: ['babel-core/register'] but it still won´t compile to use ES6 for my test files.
Any idea how to configurate my karma file to write my tests with ES6 ?
Just in case its important. This is my webpack.config.js
const path = require('path');
const ServiceWorkerWebpackPlugin = require('serviceworker-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const HtmlWebpackPluginConfig = new HtmlWebpackPlugin({
template: './src/index.html',
filename: 'index.html',
inject: 'body'
});
module.exports = {
entry: './src/index.js',
output: {
path: path.resolve('dist'),
filename: 'index_bundle.js'
},
module: {
loaders: [
{test: /\.js$/, loader: 'babel-loader', exclude: /node_modules/},
{test: /\.jsx$/, loader: 'babel-loader', exclude: /node_modules/}
]
},
plugins: [
new ServiceWorkerWebpackPlugin({
entry: path.join(__dirname, 'src/sw.js'),
}),
HtmlWebpackPluginConfig
],
devServer: {
hot: false,
inline: false,
historyApiFallback: true
}
};
To make things more clear here is a sample project (it's fully runnable, you can fill out files and play around). Just two things to mention: I used jamsine instead of mocha and real 'Chrome' browser instead of headless. Runnable via npm run test command.
files structure
/
karma.conf.js
package.json
sample.js
sampleTest.js
webpack.test.config.js
karma.conf.js:
// Karma configuration
module.exports = function(config) {
config.set({
// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '',
// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['jasmine'],
// list of files / patterns to load in the browser
files: ['*Test.js'],
// list of files to exclude
exclude: [],
// preprocess matching files before serving them to the browser
preprocessors: {
'*Test.js': [ 'webpack'] //preprocess with webpack
},
// test results reporter to use
reporters: ['progress'],
// setting up webpack configuration
webpack: require('./webpack.test.config'),
// web server port
port: 9876,
// enable / disable colors in the output (reporters and logs)
colors: true,
// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_INFO,
// enable / disable watching file and executing tests whenever any file changes
autoWatch: true,
// start these browsers
browsers: ['Chrome'],
// if true, Karma captures browsers, runs the tests and exits
singleRun: true,
// Concurrency level how many browser should be started simultaneous
concurrency: Infinity
})
}
package.json (only relevant stuff):
{
"scripts": {
"test": "node_modules/karma/bin/karma start karma.conf.js"
},
"devDependencies": {
"babel-core": "^6.26.0",
"babel-loader": "^7.1.2",
"babel-preset-env": "^1.6.1",
"jasmine-core": "^2.8.0",
"karma": "^2.0.0",
"karma-chrome-launcher": "^2.2.0",
"karma-jasmine": "^1.1.1",
"karma-webpack": "^2.0.9",
"webpack": "^3.10.0"
}
}
sample.js:
export default function(data){
return data;
}
sampleTest.js:
import sample from 'sample';
describe('Sample', function(){
it('is defined', function(){
expect(sample).toBeDefined();
});
it('returns argument', function(){
expect(sample(0)).toBe(0);
})
});
webpack.test.config.js:
module.exports = {
module: {
rules: [
{
test: /tests\/.*\.js$/,
exclude: /(node_modules)/,
use: {
loader: 'babel-loader',
options: {
presets: ['babel-preset-env']
}
}
}
]
},
resolve: {
modules: ["node_modules", './'],
extensions: [".js"]
}
};
Karma's webpack plugin is used to inform karma that it should prepare files using webpack and specific webpack configuration before sending them to the browser.
Please note key points:
test files pattern in karma.conf.js
pattern to preprocess files (should match the pattern above)
webpack entry in karma.conf.js file
module entry in webpack.test.config.js
p.s. personally I don't use separate patterns for files, I use a separate file (named, say, tests.webpack.js) to have a single place where the way to find test files is defined:
//make sure you have your directory and regex test set correctly
var context = require.context('.', true, /.*Test\.js$/i);
context.keys().forEach(context);
and have in karma.conf.js (paths are irrelevant to sample project above):
files: [
'tests/tests.webpack.js',
],
preprocessors: {
'./tests/tests.webpack.js': [ 'webpack'] //preprocess with webpack
}
You need to convert ESModule in commonjs module with the babel-plugin-transform-es2015-modules-commonjs plugin
In your .babelrc file :
{
"plugins": [
"transform-es2015-modules-commonjs"
]
}
Update :
You can set the plugin in your webpack configuration :
{
loader: 'babel-loader',
options: {
presets: ['#babel/preset-env'],
plugins: [require('#babel/plugin-transform-es2015-modules-commonjs')]
}
}

"it()" seems to get stuck in jasmine test

I am using karma & jasmine to do unit tests, and I am trying to do my first test. I am using the first example here:
https://jasmine.github.io/1.3/introduction.html#section-Matchers
and it didn't seem to do anything, so I added some logging and tried to make it catch an error:
console.log('a');
describe("A suite", function() {
console.log('b', typeof(it));
it("contains spec with an expectation", function() {
console.log('c');
expect(true).toBe(false);
});
});
And this is what my output comes out with:
Chrome 43.0.2357 (Mac OS X 10.10.3) LOG: 'a'
Chrome 43.0.2357 (Mac OS X 10.10.3) LOG: 'b', 'function'
so it looks like nothing internal to the "it" function gets executed since 'c' is never outputted. Am I missing something?
Update
So this is the grunt task I am running:
module.exports = function (grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
karma: {
unit: {
configFile: 'karma.conf.js'
}
}
});
grunt.loadNpmTasks('grunt-karma');
grunt.registerTask('default', ['karma']);
};
And this is my package.json with the list of installed npm packages:
{
"name": "abc.com",
"version": "0.0.1",
"private": true,
"dependencies": {
"bcrypt": "^0.8.3",
"body-parser": "^1.0.2",
"bower": "^1.4.1",
"ejs": "^2.3.1",
"email-templates": "^2.0.0-beta.1",
"error-handler": "^0.1.4",
"errorhandler": "^1.3.6",
"express": "~4.1.1",
"express-session": "^1.11.2",
"grunt": "^0.4.5",
"jade": "~0.31.2",
"jasmine": "^2.3.1",
"jasmine-runner": "^0.2.9",
"karma": "^0.12.37",
"karma-chrome-launcher": "^0.2.0",
"karma-jasmine": "^0.3.5",
"karma-junit-reporter": "^0.2.2",
"method-override": "^1.0.0",
"morgan": "^1.0.0",
"mysql": "^2.6.2",
"nodemailer": "^1.3.4",
"protractor": "^1.1.1",
"shelljs": "^0.2.6",
"xoauth2": "^1.0.0"
},
"scripts": {
"prestart": "npm install",
"postinstall": "bower install --allow-root",
"start": "supervisor -n error app.js",
"pretest": "npm install",
"test": "karma start karma.conf.js",
"test-single-run": "karma start karma.conf.js --single-run",
"preupdate-webdriver": "npm install",
"update-webdriver": "webdriver-manager update",
"preprotractor": "npm run update-webdriver",
"protractor": "protractor e2e-tests/protractor.conf.js",
"update-index-async": "node -e \"require('shelljs/global'); sed('-i', /\\/\\/##NG_LOADER_START##[\\s\\S]*\\/\\/##NG_LOADER_END##/, '//##NG_LOADER_START##\\n' + sed(/sourceMappingURL=angular-loader.min.js.map/,'sourceMappingURL=bower_components/angular-loader/angular-loader.min.js.map','app/bower_components/angular-loader/angular-loader.min.js') + '\\n//##NG_LOADER_END##', 'app/index-async.html');\""
},
"configs": {
"client_javascript_paths": [
"public/components/common/helpers.js",
"public/libs/bower_components/html5-boilerplate/js/vendor/modernizr-2.6.2.min.js",
"public/libs/bower_components/jquery/dist/jquery.min.js",
"public/libs/bower_components/angular/angular.js",
"public/libs/bower_components/angular-route/angular-route.js",
"public/libs/bower_components/angular-resource/angular-resource.js",
"public/libs/bower_components/d3/d3.js",
"public/libs/bower_components/c3/c3.js",
"public/libs/bower_components/angular-chart/angular-chart.js",
"public/libs/bower_components/moment/moment.js",
"public/components/common/filters.js",
"public/components/notify/notify.js",
"public/components/static/static.js",
"public/components/account/account.js",
"public/components/auth/auth.js",
"public/components/formatted-table/formatted-table.js",
"public/app.js",
"public/libs/underscore.js"
]
},
"devDependencies": {
"jasmine": "^2.3.1",
"jasmine-core": "^2.3.4",
"karma": "^0.12.37",
"karma-chrome-launcher": "^0.2.0",
"karma-jasmine": "^0.3.5",
"karma-phantomjs-launcher": "^0.2.0",
"phantomjs": "^1.9.17"
}
}
And finally, this is my karma.conf.js
module.exports = function(config) {
var package = require('./package.json')
console.log(package.configs.client_javascript_paths);
config.set({
// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '',
// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['jasmine', 'requirejs'],
// list of files / patterns to load in the browser
files: package.configs.client_javascript_paths.concat([
'public/components/**/*.tests.js'
]),
// list of files to exclude
exclude: [
],
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
},
// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['progress'],
// web server port
port: 9876,
// enable / disable colors in the output (reporters and logs)
colors: true,
// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_INFO,
// enable / disable watching file and executing tests whenever any file changes
autoWatch: true,
// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: ['Chrome'],
// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: false
});
};
and I just run
grunt
to start it to get the output at the top of this.
It is happening because of requirejs framework you use with karma. If you don't need it, then you could just remove it from karma.conf.js and test will work just fine. But if you actually need it, then I would suggest to look at this documentation page, explaining how to configure requirejs for karma, it actually requires an extra file.
Using the files you've presented in the question I was able to execute the tests after the following steps:
first create a backup of karma.conf.js
use CLI command karma init to reinitiate creation of karma config
on the step Do you want to use Require.js ? selected Yes
on the step Do you wanna generate a bootstrap file for RequireJS? selected Yes
copied everything from a backup and added a file that was generated by karma init, it should be called test-main.js, to the list of watched files:
module.exports = function(config) {
var package = require('./package.json');
config.set({
// ...
files: package.configs.client_javascript_paths.concat([
'public/components/**/*.tests.js',
'test-main.js', // here it is
])
// ...
});
};

grunt-sass, no errors log when 'watching'

I'm using the following grunt tasks
grunt-sass
grunt-contrib-watch
grunt-autoprefix
node-bourbon
(there are a few other tasks, such as uglify, spritesmith, and haml, which i have left out of this example)
My grunt file looks like this:
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
sass: {
options: {
sourceMap: true,
outputStyle: 'compressed',
imagePath: 'assets/css/img',
includePaths: require('node-bourbon').includePaths
},
dist: {
files: {
'assets/css/app.css': 'assets/sass/app.scss'
}
}
},
autoprefixer: {
options: {
browsers: ['last 2 version', 'ie 8', 'ie 9'],
silent : false
},
dev: {
src: 'assets/css/app.css',
dest: 'assets/css/post.css'
},
},
watch: {
options: {
livereload: true
},
sass: {
files: ['assets/sass/**/*.scss', 'assets/sass/*.scss'],
tasks: ['sass:dist', 'autoprefixer:dev']
}
}
});
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-sass');
grunt.loadNpmTasks('grunt-autoprefixer');
grunt.registerTask('default', ['watch', 'sass']);
};
This is working. However, if there is an error in my sass file nothing is reported. For instance if I try and use an $variable that doesn't exist, no errors are reported in my terminal
Here are two subsequent logs, the first compiles successfully with no errors. The second doesn't compile (as there is an undefined variable in the scss file)
Completed in 1.712s at Sun Sep 28 2014 15:23:17 GMT+0100 (GMT Daylight Time) - Waiting...
>> File "assets\sass\app.scss" changed.
Running "sass:dist" (sass) task
File assets/css/app.css created.
File assets/css/app.css.map created.
Running "autoprefixer:dev" (autoprefixer) task
File assets/css/post.css created.
Done, without errors.
C:\wamp\www\_bp2>grunt
Running "watch" task
Waiting...
>> File "assets\sass\app.scss" changed.
Running "sass:dist" (sass) task
Completed in 1.656s at Sun Sep 28 2014 15:29:25 GMT+0100 (GMT Daylight Time) - Waiting...
Does anyone know why no errors are being logged?
I'm in the process of rebuilding my sass boilerplate to use libsass and bourbon instead of compass. So I'm expecting to come across loads of errors during the process, so I really need to know what these errors are.
Thanks

Get Compass to compile css into specific directory when using Grunt

I want to get a basic pre-processing workflow in place. I've set up a directory structure like this:
- website-root
- - index.html
- - css
- - pre-processing
- - - Gruntfile.js
- - - package.json
- - - sass
- - - - test.scss
I'm using Grunt, as I'd like some advanced build actions in future. I'm also using Compass as I'd like to use its mixins etc.
What I want to do for now is simply set up a watch task to compile 'test.scss' into a 'test.css' file inside the css folder in the website root. However, no matter what I try, when I type 'compass watch' into the console and then change the contents of the 'test.scss' file, the result is that the 'test.css' file is always compiled into a new folder called 'stylesheets' in the 'pre-processing' folder.
The Gruntfile.js contents are:
module.exports = function (grunt) {
'use strict';
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
compass: {
dev: {
options: {
sassDir: 'scss/',
cssDir: '/css/',
relativeAssets: true
}
}
},
watch: {
sass: {
files: ['scss/{,*/}*.{scss,sass}'],
tasks: ['compass:dev']
}
}
});
grunt.loadNpmTasks('grunt-contrib-compass');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.registerTask('default', ['compass:dev']);
}
The package.json file contains this:
{
"name": "Test",
"version": "0.0.1",
"devDependencies": {
"grunt": "^0.4.5",
"grunt-contrib-compass": "^1.0.1"
}
}
So the cssDir option in Gruntfile.js seems to have no impact.
Can anyone suggest why this is happening? I'm a total pre-processing newby so could be missing something obvious!
Thanks.
When you type 'compass watch', you're running compass directly. You're trying to get this working using grunt. You need to type 'grunt watch'.

Resources