Support multiple `before_tests` steps #97

Closed
robfletcher opened this Issue Nov 27, 2012 · 7 comments

Comments

Projects
None yet
7 participants

I'm compiling source and test coffeescript and processing handlebars templates before running tests. It would be great if I could specify this in my `testem.yml':

before_tests:
- coffee -c web-app/app/*.coffee
- coffee -c test/js/specs/*.coffee
- handlebars web-app/app/templates/ -f web-app/app/templates.js

But this causes an error as the 3 commands are concatenated using commas. I can do this

before_tests: coffee -c web-app/app/*.coffee && coffee -c test/js/specs/*.coffee && handlebars web-app/app/templates/ -f web-app/app/templates.js

Which is quite ugly.

Collaborator

airportyh commented Nov 27, 2012

That's reasonable.

airportyh was assigned Nov 27, 2012

+1, and please enable multiple on_start steps as well

uris77 commented Aug 31, 2013

You can accomplish this with grunt quite easily. Here is an example https://github.com/uris77/BBpicker/blob/master/Gruntfile.js :

'use strict';

module.exports = function(grunt) {
    //load plugins
    [
        "grunt-contrib-jasmine",
        "grunt-contrib-testem",
        "grunt-contrib-clean",
        "grunt-contrib-coffee",
        "grunt-contrib-handlebars",
        "grunt-contrib-concat",
        "grunt-watch-nospawn",
        "grunt-contrib-uglify"
    ].forEach(grunt.loadNpmTasks);

    grunt.initConfig({

        tmp: '.tmp/',
        dist: 'dist/',
        projectName: 'projectName',

        testem: {
            environment: {
                src: [
                    'vendor/js/lodash.js',
                    'vendor/js/jquery.js',
                    'vendor/js/handlebars.runtime.js',
                    'vendor/js/backbone.js',
                    'vendor/**/*.js',
                    "<%= tmp %>/handlebar_templates.js",
                    'src/**/*.coffee',
                    'spec/helpers/**/*.js',
                    'spec/**/*_spec.coffee'
                ],
                options: {
                    parallel: 8,
                    launch_in_ci: ['PhantomJS'],
                    launch_in_dev: ['PhantomJS', 'Chrome']
                }
            }
        },
        concat: {
            options: {
                separator: ';'
            },
            dist: {
                src: ['<%= tmp %>/handlebar_templates.js', '<%= tmp %><%= projectName %>.js'],
                dest: 'dist/<%= projectName %>.js'
            }
        },

        coffee: {
            compileJoined: {
                options: {
                    join: true
                },
                files: {
                    '<%= tmp %><%= projectName %>.js': ["src/*.coffee"]
                }
            }
        },
        handlebars: {
          compile: {
              options: {
                  namespace: "JST"
              },
              files: {
                  "<%= tmp %>/handlebar_templates.js": ["templates/**/*.hbs", "templates/**/*.handlebars", "templates/**/*.hb"]
              }
          }
        },
        uglify: {
            options: {
                mangle: false
            },
            build: {
                files: {
                    'dist/<%= projectName %>.min.js': ['.tmp/<%= projectName %>.js']
                }
            }
        },
        clean: ['<%= tmp %>', '<%= dist %>']
    });

    grunt.registerTask('coffee:compiledJoined','Compiles the Coffeescript source files', ['coffee:compileJoined']);
    grunt.registerTask('build', "Build Project", ['coffee:compileJoined', 'handlebars','concat', 'uglify'])
    grunt.registerTask('spec', 'Run the specs', ['handlebars', 'testem:run:environment'])

}
Contributor

inossidabile commented Sep 2, 2013

This can even be done with a bash script. I think the way before_test implemented is quite messy already. Don't do things worse for nothing. 👎

Collaborator

airportyh commented Sep 3, 2013

@inossidabile yeah, this is why I've been dragging my feet. Too much code in the config file makes testem the middle man. If you have a lot of code to run, if benefits you to put it into a separate script and be able to test it by itself.

Does the code submitted in pull request 191 provide the functionality being requested? If so might we renew consideration of pulling that request in?

airportyh closed this Mar 26, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment