Skip to content

Commit

Permalink
Test for relative paths
Browse files Browse the repository at this point in the history
  • Loading branch information
richardhinkamp authored and benhoIIand committed Jan 3, 2017
1 parent 1930069 commit ff443e9
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 0 deletions.
13 changes: 13 additions & 0 deletions config/relativepath.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = {
options: {
assets: ['assets/**'],
baseDir: 'tmp/relativepath',
deleteOriginals: true,
hash: '123456789'
},
files: [{
expand: true,
cwd: 'tmp/relativepath',
src: ['assets/css/*.css', '*.html']
}]
};
13 changes: 13 additions & 0 deletions tests/relativepath/assets/css/application.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
@charset "UTF-8";

body {
background-image: url(../images/testbg.png);
}

div.test {
background-image: url(../../assets/images/testbg.png);
}

div.test2 {
background-image: url(/assets/images/testbg.png);
}
Binary file added tests/relativepath/assets/images/testbg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions tests/relativepath/relativepath.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<link rel="stylesheet" href="/assets/css/application.css">
<title>Test</title>
</head>
<body>
Test
</body>
</html>
18 changes: 18 additions & 0 deletions tests/relativepath/relativepath_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
'use strict';

var grunt = require('grunt');

module.exports = {

relativepath: function(test) {
var html = grunt.file.read('tmp/relativepath/relativepath.html');
test.ok(html.match(/"\/assets\/css\/application\.123456789\.css"/), 'testing /assets/css/application.css replaced in HTML');

var css = grunt.file.read('tmp/relativepath/assets/css/application.123456789.css');
test.ok(css.match(/url\(\.\.\/images\/testbg\.123456789\.png\)/), 'testing ../images/testbg.png replaced in busted CSS');
test.ok(css.match(/url\(\.\.\/\.\.\/assets\/images\/testbg\.123456789\.png\)/), 'testing ../../assets/images/testbg.png replaced in busted CSS');

test.done();
}

};

0 comments on commit ff443e9

Please sign in to comment.