Skip to content

Commit

Permalink
test: integration test for SriPlugin
Browse files Browse the repository at this point in the history
To allow further refactoring/fixing of ztoben#327 since current solution breaks ztoben#404 and symfony/webpack-encore#969

Resolves: ztoben#392 ztoben#327
  • Loading branch information
Den-dp committed May 17, 2021
1 parent 29aa549 commit 996a9a6
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
"snazzy": "9.0.0",
"standard": "16.0.3",
"style-loader": "2.0.0",
"webpack": "5.37.0"
"webpack": "5.37.0",
"webpack-subresource-integrity": "^1.5.2"
},
"dependencies": {
"camelcase": "^6.0.0",
Expand Down
42 changes: 42 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const Plugin = require('../index.js')
const OUTPUT_DIR = path.join(__dirname, '../tmp')
const expectOutput = require('./utils/expectOutput')(OUTPUT_DIR)
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const SriPlugin = require('webpack-subresource-integrity')

describe('Plugin', function () {
beforeEach(function (done) {
Expand Down Expand Up @@ -252,6 +253,47 @@ describe('Plugin', function () {
expectOutput(args, done)
})

it('works with SriPlugin for multiple entries', function (done) {
const webpackConfig = {
entry: {
one: path.join(__dirname, 'fixtures/one.js'),
two: path.join(__dirname, 'fixtures/two.js')
},
output: {
path: OUTPUT_DIR,
filename: '[name]-bundle.js'
},
plugins: [
new Plugin({
path: 'tmp',
integrity: true
}),
new SriPlugin({
hashFuncNames: ['sha384'],
enabled: true
})
]
}

const expected = {
one: {
js: 'auto/one-bundle.js',
jsIntegrity: 'sha384-H3yxFmZeX9gwVyZXCuJBsMt5QGQTfjsWlVuRz533CIBFZKEFGd2x/jUgwfr2W03p'
},
two: {
js: 'auto/two-bundle.js',
jsIntegrity: 'sha384-fysNJb6C9uG1mOr57+Zm2SevQgQPrLqgzjWUHO5n9N+yjpsWQcwgjYatT15wxFoD'
}
}

const args = {
config: webpackConfig,
expected: expected
}

expectOutput(args, done)
})

it('includes full publicPath', function (done) {
const webpackConfig = {
entry: path.join(__dirname, 'fixtures/one.js'),
Expand Down

0 comments on commit 996a9a6

Please sign in to comment.