Add support for files in parent directories
Closed this issue · 3 comments
Consider this layout:
- node_modules/**/*.js <= files in parent directory (currently not supported)
- client/app/**/*.js <= files in subdirectory
spec/fixtures/*.json <= files in subdirectory
gulpfile.js
client/gulpfile.js is responsible for listing all files (from client/app and node_modules directories) and run jasmineBrowser:
var files = [
'../node_modules/**/*.js',
'app/**/*.js',
'spec/fixtures/*.json'
];
gulp.src(
files,
{ base: '.' } // See Fail with files with the same name gulp-jasmine-browser/issues/8
)
.pipe($.watch(files, { base: '.' }))
.pipe($.jasmineBrowser.specRunner())
.pipe($.jasmineBrowser.server());
exec('open http://localhost:8888');
Generated specRunner.html:
<script src="../node_modules/underscore/underscore.js"></script>
<script src="app/app.js"></script>
Of course it will fail: the browser does not know about ..
.
To support this kind of pattern, BrowserSync provides a baseDir
option: http://www.browsersync.io/docs/options/#option-server
Would be nice to have this feature for gulp-jasmine-browser:
var files = [
'../node_modules/**/*.js',
'app/**/*.js'
];
gulp.src(
files,
{ base: '.' } // See Fail with files with the same name gulp-jasmine-browser/issues/8
)
.pipe($.watch(files, { base: '.' }))
.pipe($.jasmineBrowser.specRunner({ baseDir: ['..', '.'] }))
.pipe($.jasmineBrowser.server({ baseDir: ['..', '.'] }));
exec('open http://localhost:8888');
Generated specRunner.html:
<script src="node_modules/underscore/underscore.js"></script>
<script src="app/app.js"></script>
To overcome the parent directory thing (../node_modules/**/*.js
) this is what I currently do:
var files = [
'../node_modules/**/*.js',
'app/**/*.js',
'spec/fixtures/*.json'
];
gulp.src(
files,
{ base: '..' } // <= instead of '.'
)
.pipe($.watch(files, { base: '..' }))
.pipe($.jasmineBrowser.specRunner())
.pipe($.jasmineBrowser.server());
exec('open http://localhost:8888');
Generated specRunner.html:
<script src="node_modules/underscore/underscore.js"></script>
<script src="client/app/app.js"></script> // <= instead of "app/app.js"
Then all my AJAX requests for spec/fixtures/*.json
have to be prefixed with client
subdirectory: GET client/test/fixtures/somedata.json
instead of simply GET test/fixtures/somedata.json
We could certainly add some kind of support for this, couldn't you also use gulp rename to change the path of those fixtures instead of trying to change the base directory?
using an existing gulp plugin to aid in the rename should really take care of this, i'd be willing to take a pull request but rename should really do the trick with a basename.