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: {
|
selfTest: {
|
||||||
options: {
|
options: {
|
||||||
specs: ['test/selfTest/*.js'],
|
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*
|
*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
|
#### options.outfile
|
||||||
Type: `String`
|
Type: `String`
|
||||||
Default: `_SpecRunner.html`
|
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
|
Please see the [grunt-template-jasmine-requirejs](https://github.com/jsoverson/grunt-template-jasmine-requirejs) documentation
|
||||||
for more information on the RequireJS template.
|
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
|
## Release History
|
||||||
|
|
||||||
@ -329,4 +357,4 @@ for more information on the RequireJS template.
|
|||||||
|
|
||||||
Task submitted by [Jarrod Overson](http://jarrodoverson.com)
|
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
|
Please see the [grunt-template-jasmine-requirejs](https://github.com/jsoverson/grunt-template-jasmine-requirejs) documentation
|
||||||
for more information on the RequireJS template.
|
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*
|
*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
|
## options.outfile
|
||||||
Type: `String`
|
Type: `String`
|
||||||
Default: `_SpecRunner.html`
|
Default: `_SpecRunner.html`
|
||||||
|
@ -79,6 +79,7 @@ module.exports = function(grunt) {
|
|||||||
vendor: [],
|
vendor: [],
|
||||||
polyfills: [],
|
polyfills: [],
|
||||||
customBootFile: null,
|
customBootFile: null,
|
||||||
|
tempDir: '.grunt/grunt-contrib-jasmine',
|
||||||
outfile: '_SpecRunner.html',
|
outfile: '_SpecRunner.html',
|
||||||
host: '',
|
host: '',
|
||||||
template: path.join(__dirname, '/jasmine/templates/DefaultRunner.tmpl'),
|
template: path.join(__dirname, '/jasmine/templates/DefaultRunner.tmpl'),
|
||||||
@ -156,7 +157,7 @@ module.exports = function(grunt) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!options.keepRunner) {
|
if (!options.keepRunner) {
|
||||||
jasmine.cleanTemp(cb);
|
jasmine.cleanTemp(options.tempDir, cb);
|
||||||
} else {
|
} else {
|
||||||
cb();
|
cb();
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<title>Jasmine Spec Runner</title>
|
<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){ %>
|
<% css.forEach(function(style){ %>
|
||||||
<link rel="stylesheet" type="text/css" href="<%= style %>">
|
<link rel="stylesheet" type="text/css" href="<%= style %>">
|
||||||
<% }) %>
|
<% }) %>
|
||||||
|
@ -10,30 +10,33 @@ exports.init = function(grunt, phantomjs) {
|
|||||||
_ = require('lodash'),
|
_ = require('lodash'),
|
||||||
jasmineRequire = require('jasmine-core');
|
jasmineRequire = require('jasmine-core');
|
||||||
|
|
||||||
var baseDir = '.',
|
var baseDir = '.';
|
||||||
tempDir = '.grunt/grunt-contrib-jasmine';
|
|
||||||
|
|
||||||
var exports = {};
|
var exports = {};
|
||||||
|
|
||||||
exports.writeTempFile = function(dest, contents) {
|
exports.writeTempFile = function(dest, contents) {
|
||||||
var file = path.join(tempDir, dest);
|
grunt.file.write(dest, contents);
|
||||||
grunt.file.write(file, contents);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.copyTempFile = function(src, dest) {
|
exports.copyTempFile = function(src, dest) {
|
||||||
var file = path.join(tempDir, dest);
|
grunt.file.copy(src, dest);
|
||||||
grunt.file.copy(src, file);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.cleanTemp = function(cb) {
|
exports.cleanTemp = function(tempDir, cb) {
|
||||||
rimraf(tempDir, function() {
|
rimraf(tempDir, function() {
|
||||||
// if this fails, then ./.grunt isn't empty and that's ok.
|
if(tempDir === '.grunt/grunt-contrib-jasmine') {
|
||||||
fs.rmdir('.grunt', cb);
|
// 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) {
|
exports.buildSpecrunner = function(src, options) {
|
||||||
var source = '',
|
var source = '',
|
||||||
|
tempDir = options.tempDir,
|
||||||
outfile = options.outfile,
|
outfile = options.outfile,
|
||||||
specrunner = path.join(baseDir, outfile),
|
specrunner = path.join(baseDir, outfile),
|
||||||
outdir = path.dirname(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) {
|
[].concat(jasmineRequire.files.cssFiles, jasmineRequire.files.jsFiles).forEach(function(name) {
|
||||||
var srcPath = path.join(jasmineRequire.files.path, 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) {
|
jasmineRequire.files.bootFiles.forEach(function(name) {
|
||||||
var srcPath = path.join(jasmineRequire.files.bootDir, 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 = [
|
var reporters = [
|
||||||
tempDir + '/reporter.js'
|
tempDir + '/reporter.js'
|
||||||
@ -90,6 +93,7 @@ exports.init = function(grunt, phantomjs) {
|
|||||||
var context = {
|
var context = {
|
||||||
temp: tempDir,
|
temp: tempDir,
|
||||||
outfile: outfile,
|
outfile: outfile,
|
||||||
|
favicon: path.join(tempDir, 'jasmine_favicon.png'),
|
||||||
css: exports.getRelativeFileList(outdir, jasmineCss, { nonull: true }),
|
css: exports.getRelativeFileList(outdir, jasmineCss, { nonull: true }),
|
||||||
scripts: {
|
scripts: {
|
||||||
polyfills: exports.getRelativeFileList(outdir, polyfills),
|
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']
|
boot: ['BOOT.js']
|
||||||
},
|
},
|
||||||
temp: 'path/to/temp/folder',
|
temp: 'path/to/temp/folder',
|
||||||
|
favicon: 'path/to/temp/folder/jasmine_favicon.png',
|
||||||
options: {}
|
options: {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user