-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
130d2ec
commit 443f8bc
Showing
9 changed files
with
185 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
|
||
<head> | ||
<meta charset="utf-8"> | ||
<meta http-equiv="x-ua-compatible" content="ie=edge"> | ||
<title>Inline SVG Tests index</title> | ||
</head> | ||
|
||
<body> | ||
<div> | ||
<p> | ||
<span>if below SVG is inlined correctly we can reference its content:</span> | ||
<svg class="icon mood-good"><use xlink:href="#icon-mood-good"></use></svg> | ||
</p> | ||
</div> | ||
|
||
<h2>Inline images</h2> | ||
|
||
<img id="replace-me" src="~img/moods.svg" inline> | ||
|
||
<img id="not-an-svg" inline src="images/not-an-svg.png"> | ||
|
||
<div id="do-not-decode"><?= $foo->bar; ?></div> | ||
|
||
should output broken tags</p> | ||
|
||
<p>should output unclosed tags | ||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
var path = require('path') | ||
var fs = require('fs') | ||
var cheerio = require('cheerio') | ||
var webpackConfig = require('./webpack.base.config') | ||
|
||
module.exports = [ | ||
|
||
{ | ||
label: 'It should inline SVG images following the custom SVGO config', | ||
func: function (done) { | ||
|
||
var htmlFile = path.resolve(webpackConfig.outputDir, 'index-svgo.html') | ||
|
||
fs.readFile(htmlFile, 'utf8', function (err, data) { | ||
expect(err).toBeFalsy() | ||
|
||
var $ = cheerio.load(data) | ||
|
||
// Assertions affecting any html-webpack-inline-svg-plugin use | ||
expect($('img#replace-me').length).toBe(0) | ||
expect($('svg#replace-me').length).toBe(1) | ||
expect($('img#not-an-svg').length).toBe(1) | ||
expect($('div#do-not-decode').length).toBe(1) | ||
|
||
// Assertions affecting only svgoConfig option | ||
// The configuration found on webpack.svgo.config.js is the opposite to SVGO defaults | ||
expect($('svg#replace-me').attr('xmlns')).toBe(undefined) | ||
expect($('svg#replace-me title#icon-mood-bad-title').length).toBe(1) | ||
expect($('svg#replace-me symbol#icon-mood-bad').contents()[0].data).toBe('Random comment') | ||
|
||
done() | ||
|
||
}) | ||
|
||
}, | ||
|
||
}, | ||
|
||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
const path = require('path') | ||
const webpackConfig = require('./webpack.base.config') | ||
const HtmlWebpackPlugin = require('html-webpack-plugin') | ||
const HtmlWebpackInlineSVGPlugin = require('../') | ||
|
||
module.exports = { | ||
|
||
resolve: { | ||
alias: { | ||
'img': path.join(__dirname, 'fixtures', 'images'), | ||
}, | ||
}, | ||
|
||
module: { | ||
rules: [ | ||
{ | ||
test: /\.(svg)(\?.*)?$/, | ||
use: [ | ||
{ | ||
loader: 'file-loader', | ||
options: { | ||
name: 'images/svgs/[name].[ext]', | ||
} | ||
} | ||
], | ||
}, | ||
{ | ||
test: /\.(png|jpe?g|gif)(\?.*)?$/, | ||
use: [ | ||
{ | ||
loader: 'file-loader', | ||
options: { | ||
name: 'images/[name].[ext]', | ||
} | ||
} | ||
], | ||
}, | ||
{ | ||
test: /\.(html)$/, | ||
use: [ | ||
{ | ||
loader: 'html-loader', | ||
options: {} | ||
} | ||
], | ||
}, | ||
] | ||
}, | ||
|
||
plugins: [ | ||
new HtmlWebpackPlugin({ | ||
filename: path.resolve(webpackConfig.outputDir, 'index-svgo.html'), | ||
template: path.join(__dirname, 'fixtures', 'index-svgo.html') | ||
}), | ||
new HtmlWebpackInlineSVGPlugin({ | ||
svgoConfig: [ | ||
{ | ||
removeXMLNS: true | ||
}, | ||
{ | ||
removeTitle: false | ||
}, | ||
{ | ||
removeComments: false | ||
} | ||
] | ||
}), | ||
], | ||
|
||
} |