Skip to content

Commit

Permalink
Merge pull request #4 from dflynn15/feat-2
Browse files Browse the repository at this point in the history
feat(unit - keepRunner): unit test keepRunner
  • Loading branch information
dflynn15 committed Sep 30, 2014
2 parents 129430d + 81746bb commit a8eb92a
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 40 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ Run your tests with `phantomjs`
Type: `boolean | string`
Default: false

**Only used while `integration` is true
Keep the `specRunner.html` file after build. If given a string, it will keep the runner at the string path.

Technologies Used
Expand Down
8 changes: 8 additions & 0 deletions example/gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ gulp.task('default', function () {
return gulp.src('specs/unit/**.js').pipe(jasmine());
});

gulp.task('test-unit-path', function() {
return gulp.src('specs/unit/**.js')
.pipe(jasmine({
keepRunner: './'
}));
});

// Passing options in specifying integration tests
gulp.task('test-integration', function() {
return gulp.src('specs/integration/integration.js')
Expand All @@ -28,6 +35,7 @@ gulp.task('test-path', function() {
}));
});


gulp.task('dev', function() {
gulp.watch('./*.js', ['test-integration']);
});
76 changes: 37 additions & 39 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ var path = require('path'),
handlebar = require('handlebars'),
fs = require('fs'),
execFile = require('child_process').execFile,
filePaths = [],
jasmineCss = path.join(__dirname, '/vendor/jasmine-2.0/jasmine.css'),
jasmineJs = [
path.join(__dirname, '/vendor/jasmine-2.0/jasmine.js'),
Expand Down Expand Up @@ -48,16 +49,38 @@ module.exports = function (options) {
};

// Write out the spec runner file
var createRunner = function(specPath, specCompiled) {
fs.writeFile(specPath, specCompiled ,function(error) {
var createRunner = function(newSpecPath, specCompiled, runFile) {
fs.writeFile(newSpecPath, specCompiled ,function(error) {
if (error) throw error;

if(runFile) {
var childArgs = [
path.join(__dirname, '/lib/jasmine-runner.js'),
newSpecPath
];
runPhantom(childArgs);
}
});
};

var compileRunner = function(integrationTest) {
fs.readFile(path.join(__dirname, '/lib/specRunner.handlebars'), 'utf8', function(error, data) {
if (error) throw error;

var childArgs = [
path.join(__dirname, '/lib/jasmine-runner.js'),
path.join(__dirname, '/lib/specRunner.html')
];
// Create the compile version of the specRunner from Handlebars
var specData = handlebar.compile(data),
specCompiled = specData({
files: filePaths,
jasmine_css: jasmineCss,
jasmine_js: jasmineJs,
spec_runner: specRunner
});

runPhantom(childArgs);
if(options.keepRunner !== undefined && typeof options.keepRunner === 'string') {
specPath = path.join(path.resolve(options.keepRunner), '/specRunner.html');
}

createRunner(specPath, specCompiled, integrationTest);
});
};

Expand All @@ -67,7 +90,6 @@ module.exports = function (options) {
if(!!options.integration) {

// Reference to the file paths piped in
var filePaths = [];
gutil.log('Running Jasmine with PhantomJS');

return through.obj(
Expand All @@ -86,37 +108,7 @@ module.exports = function (options) {
filePaths.push(file.path);
callback(null, file);
}, function (callback) {

// Create the specRunner.html file from the template
fs.readFile(path.join(__dirname, '/lib/specRunner.handlebars'), 'utf8', function(error, data) {
if (error) throw error;

// Create the compile version of the specRunner from Handlebars
var specData = handlebar.compile(data),
specCompiled = specData({
files: filePaths,
jasmine_css: jasmineCss,
jasmine_js: jasmineJs,
spec_runner: specRunner
});

if(options.keepRunner !== undefined && typeof options.keepRunner === 'string') {
specPath = path.join(path.resolve(options.keepRunner), '/specRunner.html');
}

fs.writeFile(specPath, specCompiled ,function(error) {
if (error) throw error;

var childArgs = [
path.join(__dirname, '/lib/jasmine-runner.js'),
specPath
];

runPhantom(childArgs);
});

});

compileRunner(true);
}
);
}
Expand All @@ -138,6 +130,7 @@ module.exports = function (options) {
}

miniJasmineLib.addSpecs(file.path);
filePaths.push(file.path);
callback(null, file);
},
function(callback) {
Expand All @@ -154,6 +147,11 @@ module.exports = function (options) {
}
}
});

if(options.keepRunner) {
compileRunner();
}

} catch(error) {
callback(new gutil.PluginError('gulp-jasmine-phantom', error));
}
Expand Down

0 comments on commit a8eb92a

Please sign in to comment.