Custom temp directory (#240)
* Add a tempDir option that defaults to the original value * Add favicon to context to join temp path in js * Add a test for the custom temp directory * Add tempDir to options docs and examples * Rebuild readme with doc changes
This commit is contained in:
parent
7f678cbbf9
commit
a3fd4866ce
@ -112,6 +112,13 @@ module.exports = function(grunt) {
|
||||
}
|
||||
}
|
||||
},
|
||||
customTempDir: {
|
||||
src: 'test/fixtures/custom-temp-dir/src/**/*.js',
|
||||
options: {
|
||||
specs: 'test/fixtures/custom-temp-dir/spec/**/*.js',
|
||||
tempDir: '.custom/'
|
||||
}
|
||||
},
|
||||
selfTest: {
|
||||
options: {
|
||||
specs: ['test/selfTest/*.js'],
|
||||
|
30
README.md
30
README.md
@ -87,6 +87,13 @@ This is the jasmine-version which will be used. currently available versions are
|
||||
|
||||
*Due to changes in Jasmine, pre-2.0 versions have been dropped and tracking will resume at 2.0.0*
|
||||
|
||||
#### options.tempDir
|
||||
Type: `String`
|
||||
Default: `.grunt/grunt-contrib-jasmine`
|
||||
|
||||
The temporary directory that runners use to load jasmine files.
|
||||
Automatically deleted upon normal runs.
|
||||
|
||||
#### options.outfile
|
||||
Type: `String`
|
||||
Default: `_SpecRunner.html`
|
||||
@ -292,6 +299,27 @@ NPM Templates are just node modules, so you can write and treat them as such.
|
||||
Please see the [grunt-template-jasmine-requirejs](https://github.com/jsoverson/grunt-template-jasmine-requirejs) documentation
|
||||
for more information on the RequireJS template.
|
||||
|
||||
#### Keeping temp files in an existing directory
|
||||
|
||||
Supplying a custom temp directory
|
||||
|
||||
```js
|
||||
// Example configuration
|
||||
grunt.initConfig({
|
||||
jasmine: {
|
||||
pivotal: {
|
||||
src: 'src/**/*.js',
|
||||
options: {
|
||||
keepRunner: true,
|
||||
tempDir: 'bin/jasmine/',
|
||||
specs: 'spec/*Spec.js',
|
||||
helpers: 'spec/*Helper.js'
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
|
||||
## Release History
|
||||
|
||||
@ -329,4 +357,4 @@ for more information on the RequireJS template.
|
||||
|
||||
Task submitted by [Jarrod Overson](http://jarrodoverson.com)
|
||||
|
||||
*This file was generated on Mon Apr 25 2016 01:03:39.*
|
||||
*This file was generated on Tue Jun 14 2016 11:02:35.*
|
||||
|
@ -87,3 +87,24 @@ NPM Templates are just node modules, so you can write and treat them as such.
|
||||
|
||||
Please see the [grunt-template-jasmine-requirejs](https://github.com/jsoverson/grunt-template-jasmine-requirejs) documentation
|
||||
for more information on the RequireJS template.
|
||||
|
||||
## Keeping temp files in an existing directory
|
||||
|
||||
Supplying a custom temp directory
|
||||
|
||||
```js
|
||||
// Example configuration
|
||||
grunt.initConfig({
|
||||
jasmine: {
|
||||
pivotal: {
|
||||
src: 'src/**/*.js',
|
||||
options: {
|
||||
keepRunner: true,
|
||||
tempDir: 'bin/jasmine/',
|
||||
specs: 'spec/*Spec.js',
|
||||
helpers: 'spec/*Helper.js'
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
```
|
||||
|
@ -37,6 +37,13 @@ This is the jasmine-version which will be used. currently available versions are
|
||||
|
||||
*Due to changes in Jasmine, pre-2.0 versions have been dropped and tracking will resume at 2.0.0*
|
||||
|
||||
## options.tempDir
|
||||
Type: `String`
|
||||
Default: `.grunt/grunt-contrib-jasmine`
|
||||
|
||||
The temporary directory that runners use to load jasmine files.
|
||||
Automatically deleted upon normal runs.
|
||||
|
||||
## options.outfile
|
||||
Type: `String`
|
||||
Default: `_SpecRunner.html`
|
||||
|
@ -79,6 +79,7 @@ module.exports = function(grunt) {
|
||||
vendor: [],
|
||||
polyfills: [],
|
||||
customBootFile: null,
|
||||
tempDir: '.grunt/grunt-contrib-jasmine',
|
||||
outfile: '_SpecRunner.html',
|
||||
host: '',
|
||||
template: path.join(__dirname, '/jasmine/templates/DefaultRunner.tmpl'),
|
||||
@ -156,7 +157,7 @@ module.exports = function(grunt) {
|
||||
}
|
||||
|
||||
if (!options.keepRunner) {
|
||||
jasmine.cleanTemp(cb);
|
||||
jasmine.cleanTemp(options.tempDir, cb);
|
||||
} else {
|
||||
cb();
|
||||
}
|
||||
|
@ -3,7 +3,7 @@
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Jasmine Spec Runner</title>
|
||||
<link rel="shortcut icon" type="image/png" href="<%= temp %>/jasmine_favicon.png">
|
||||
<link rel="shortcut icon" type="image/png" href="<%= favicon %>">
|
||||
<% css.forEach(function(style){ %>
|
||||
<link rel="stylesheet" type="text/css" href="<%= style %>">
|
||||
<% }) %>
|
||||
|
@ -10,30 +10,33 @@ exports.init = function(grunt, phantomjs) {
|
||||
_ = require('lodash'),
|
||||
jasmineRequire = require('jasmine-core');
|
||||
|
||||
var baseDir = '.',
|
||||
tempDir = '.grunt/grunt-contrib-jasmine';
|
||||
var baseDir = '.';
|
||||
|
||||
var exports = {};
|
||||
|
||||
exports.writeTempFile = function(dest, contents) {
|
||||
var file = path.join(tempDir, dest);
|
||||
grunt.file.write(file, contents);
|
||||
grunt.file.write(dest, contents);
|
||||
};
|
||||
|
||||
exports.copyTempFile = function(src, dest) {
|
||||
var file = path.join(tempDir, dest);
|
||||
grunt.file.copy(src, file);
|
||||
grunt.file.copy(src, dest);
|
||||
};
|
||||
|
||||
exports.cleanTemp = function(cb) {
|
||||
exports.cleanTemp = function(tempDir, cb) {
|
||||
rimraf(tempDir, function() {
|
||||
// if this fails, then ./.grunt isn't empty and that's ok.
|
||||
fs.rmdir('.grunt', cb);
|
||||
if(tempDir === '.grunt/grunt-contrib-jasmine') {
|
||||
// if this fails, then ./.grunt isn't empty and that's ok.
|
||||
fs.rmdir('.grunt', cb);
|
||||
} else {
|
||||
// don't delete parent directory of a custom directory.
|
||||
cb();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
exports.buildSpecrunner = function(src, options) {
|
||||
var source = '',
|
||||
tempDir = options.tempDir,
|
||||
outfile = options.outfile,
|
||||
specrunner = path.join(baseDir, outfile),
|
||||
outdir = path.dirname(outfile),
|
||||
@ -51,19 +54,19 @@ exports.init = function(grunt, phantomjs) {
|
||||
}
|
||||
}
|
||||
|
||||
exports.copyTempFile(path.join(__dirname, '/../jasmine/reporters/PhantomReporter.js'), 'reporter.js');
|
||||
exports.copyTempFile(path.join(__dirname, '/../jasmine/reporters/PhantomReporter.js'), path.join(tempDir, 'reporter.js'));
|
||||
|
||||
[].concat(jasmineRequire.files.cssFiles, jasmineRequire.files.jsFiles).forEach(function(name) {
|
||||
var srcPath = path.join(jasmineRequire.files.path, name);
|
||||
exports.copyTempFile(srcPath, name);
|
||||
exports.copyTempFile(srcPath, path.join(tempDir, name));
|
||||
});
|
||||
|
||||
jasmineRequire.files.bootFiles.forEach(function(name) {
|
||||
var srcPath = path.join(jasmineRequire.files.bootDir, name);
|
||||
exports.copyTempFile(srcPath, name);
|
||||
exports.copyTempFile(srcPath, path.join(tempDir, name));
|
||||
});
|
||||
|
||||
exports.copyTempFile(path.join(jasmineRequire.files.imagesDir, 'jasmine_favicon.png'), 'jasmine_favicon.png');
|
||||
exports.copyTempFile(path.join(jasmineRequire.files.imagesDir, 'jasmine_favicon.png'), path.join(tempDir, 'jasmine_favicon.png'));
|
||||
|
||||
var reporters = [
|
||||
tempDir + '/reporter.js'
|
||||
@ -90,6 +93,7 @@ exports.init = function(grunt, phantomjs) {
|
||||
var context = {
|
||||
temp: tempDir,
|
||||
outfile: outfile,
|
||||
favicon: path.join(tempDir, 'jasmine_favicon.png'),
|
||||
css: exports.getRelativeFileList(outdir, jasmineCss, { nonull: true }),
|
||||
scripts: {
|
||||
polyfills: exports.getRelativeFileList(outdir, polyfills),
|
||||
|
20
test/fixtures/custom-temp-dir/spec/test-spec.js
vendored
Normal file
20
test/fixtures/custom-temp-dir/spec/test-spec.js
vendored
Normal file
@ -0,0 +1,20 @@
|
||||
describe("custom temp directory test", function() {
|
||||
|
||||
it("should have loaded from a custom temp directory", function() {
|
||||
expect(working).toBeTruthy();
|
||||
|
||||
var links = document.getElementsByTagName('link');
|
||||
expect(links[0].href).toEqual(jasmine.stringMatching('.custom/jasmine_favicon.png'));
|
||||
expect(links[1].href).toEqual(jasmine.stringMatching('.custom/jasmine.css'));
|
||||
|
||||
var scripts = document.getElementsByTagName('script');
|
||||
expect(scripts[0].src).toEqual(jasmine.stringMatching('.custom/jasmine.js'));
|
||||
expect(scripts[1].src).toEqual(jasmine.stringMatching('.custom/jasmine-html.js'));
|
||||
expect(scripts[2].src).toEqual(jasmine.stringMatching('.custom/json2.js'));
|
||||
expect(scripts[3].src).toEqual(jasmine.stringMatching('.custom/boot.js'));
|
||||
expect(scripts[4].src).toEqual(jasmine.stringMatching('test/fixtures/custom-temp-dir/src/test.js'));
|
||||
expect(scripts[5].src).toEqual(jasmine.stringMatching('test/fixtures/custom-temp-dir/spec/test-spec.js'));
|
||||
expect(scripts[6].src).toEqual(jasmine.stringMatching('.custom/reporter.js'));
|
||||
});
|
||||
|
||||
});
|
1
test/fixtures/custom-temp-dir/src/test.js
vendored
Normal file
1
test/fixtures/custom-temp-dir/src/test.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
working = true
|
@ -35,6 +35,7 @@ exports.jasmine = {
|
||||
boot: ['BOOT.js']
|
||||
},
|
||||
temp: 'path/to/temp/folder',
|
||||
favicon: 'path/to/temp/folder/jasmine_favicon.png',
|
||||
options: {}
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user