Skip to content

Commit

Permalink
Fix: make file path tests more portable
Browse files Browse the repository at this point in the history
Comparison of files paths using a regular expression fails on non-Posix systems (e.g. Windows), where path separator is a backward-slash and not a forward-slash.
  • Loading branch information
macedigital committed Jun 26, 2017
1 parent 6064dc5 commit ead6130
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,15 +163,23 @@ describe('gulp-sri-hash', function () {
.pipe(plugin({algo: algo, relative: true}))
.pipe(streamAssert.length(2))
.pipe(streamAssert.first(function (vinyl) {
var expectedPath = ['nested', 'folder', 'index.html'];
var actualPath = vinyl.path.split(path.sep).slice(-3);

assertCount(vinyl.contents, 'link[integrity="' + styleHash +'"][crossorigin=anonymous]', 3);
assertCount(vinyl.contents, 'script[integrity="' + scriptHash + '"][crossorigin=anonymous]', 2);
assertCount(vinyl.contents, 'script[integrity="' + scriptHash + '"][crossorigin=use-credentials]', 1);
assert.ok(vinyl.path.match(/nested\/folder\/index\.html$/))

assert.deepStrictEqual(actualPath, expectedPath);
}))
.pipe(streamAssert.second(function (vinyl) {
var expectedPath = ['nested', 'folder', 'html', 'index.html'];
var actualPath = vinyl.path.split(path.sep).slice(-4);

assertCount(vinyl.contents, 'link[integrity="' + styleHash + '"][crossorigin=anonymous]', 1);
assertCount(vinyl.contents, 'script[integrity="' + scriptHash + '"][crossorigin=anonymous]', 1);
assert.ok(vinyl.path.match(/nested\/folder\/html\/index\.html$/))

assert.deepStrictEqual(actualPath, expectedPath);
}))
.pipe(streamAssert.end(done));
});
Expand Down

0 comments on commit ead6130

Please sign in to comment.