Skip to content

Commit

Permalink
Add Coveralls (#23)
Browse files Browse the repository at this point in the history
Update to 3.4.1 (see the CHANGELOG for details)
  • Loading branch information
yoriiis committed Dec 23, 2019
1 parent b87aeb4 commit 806bd0a
Show file tree
Hide file tree
Showing 9 changed files with 168 additions and 32 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Expand Up @@ -22,3 +22,5 @@ jobs:
- npm run test
- npm run build
- npm run build:example
- after_success:
- npm run coverage
11 changes: 11 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,14 @@
# 3.4.1

#### New features

* Add Coveralls

#### Updates

* Up code covrage to 100%


# 3.4.0

#### New features
Expand Down
5 changes: 4 additions & 1 deletion README.md
@@ -1,8 +1,11 @@
<p>
<img alt="TravisCI" src="https://img.shields.io/badge/chunks--webpack--plugin-v3.4.0-546e7a.svg?style=for-the-badge">
<img alt="TravisCI" src="https://img.shields.io/badge/chunks--webpack--plugin-v3.4.1-546e7a.svg?style=for-the-badge">
<a href="https://travis-ci.com/yoriiis/chunks-webpack-plugin">
<img alt="TravisCI" src="https://img.shields.io/travis/com/yoriiis/chunks-webpack-plugin/master?style=for-the-badge">
</a>
<a href="https://coveralls.io/github/yoriiis/chunks-webpack-plugin?branch=master">
<img src="https://img.shields.io/coveralls/github/yoriiis/chunks-webpack-plugin?style=for-the-badge" alt="Coverage Status" />
</a>
<img alt="Node.js" src="https://img.shields.io/node/v/chunks-webpack-plugin?style=for-the-badge">
<a href="https://bundlephobia.com/result?p=fela@latest">
<img alt="Bundlephobia" src="https://img.shields.io/bundlephobia/minzip/chunks-webpack-plugin?style=for-the-badge">
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js
Expand Up @@ -3,7 +3,7 @@
/**
* @license MIT
* @name ChunksWebpackPlugin
* @version 3.4.0
* @version 3.4.1
* @author: Yoriiis aka Joris DANIEL <joris.daniel@gmail.com>
* @description: Easily create HTML files with all chunks by entrypoint (based on Webpack chunkGroups)
* {@link https://github.com/yoriiis/chunks-webpack-plugins}
Expand Down
27 changes: 26 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "chunks-webpack-plugin",
"version": "3.4.0",
"version": "3.4.1",
"description": "Easily create HTML files with all chunks by entrypoint (based on Webpack chunkGroups)",
"keywords": [
"chunks",
Expand All @@ -19,6 +19,7 @@
"analyze:bundle": "webpack --mode=production --profile --json > webpack-stats.json && webpack-bundle-analyzer ./webpack-stats.json ./ -p 1664",
"build": "rm -rf ./dist && babel ./src/ --out-dir ./dist/ --ignore './src/__tests__'",
"build:example": "rm -rf ./example/dist/ && webpack --config=./example/webpack.config.js --mode=production",
"coverage": "npm run test:coverage && cat ./coverage/lcov.info | coveralls",
"inspect:example": "rm -rf ./example/dist/ && node --inspect node_modules/webpack/bin/webpack.js --mode=development --hidden=node_modules/",
"start:example": "rm -rf ./dist/ && webpack --config=./example/webpack.config.js --mode=development",
"test": "jest --verbose --coverage",
Expand All @@ -36,6 +37,7 @@
"babel-eslint": "10.0.3",
"babel-loader": "8.0.6",
"babel-plugin-dynamic-import-node": "2.3.0",
"coveralls": "3.0.9",
"css-loader": "1.0.0",
"eslint": "4.19.1",
"eslint-config-standard": "11.0.0",
Expand Down
118 changes: 102 additions & 16 deletions src/__tests__/index.test.js
Expand Up @@ -8,7 +8,7 @@ let chunksSorted
let compilationWebpack
let compilerWebpack

const getInstance = () => new ChunksWebpackPlugin({
const options = {
outputPath: '/dist/templates',
fileExtension: '.html',
generateChunksManifest: true,
Expand All @@ -26,7 +26,9 @@ const getInstance = () => new ChunksWebpackPlugin({

return { styles, scripts }
}
})
}

const getInstance = () => new ChunksWebpackPlugin(options)

const getChunksSorted = () => {
return chunksWebpackPlugin.sortsChunksByType({
Expand Down Expand Up @@ -77,7 +79,7 @@ beforeEach(() => {
})

describe('ChunksWebpackPlugin', () => {
it('should init the constructor function', () => {
it('Initialize the constructor', () => {
expect(chunksWebpackPlugin.options).toMatchObject({
outputPath: '/dist/templates',
fileExtension: '.html',
Expand All @@ -89,7 +91,20 @@ describe('ChunksWebpackPlugin', () => {
})
})

it('should init the apply function', () => {
it('Initialize the constructor without options', () => {
const instance = new ChunksWebpackPlugin()
expect(instance.options).toMatchObject({
outputPath: 'default',
fileExtension: '.html',
templateStyle: '<link rel="stylesheet" href="{{chunk}}" />',
templateScript: '<script src="{{chunk}}"></script>',
generateChunksManifest: false,
generateChunksFiles: true,
customFormatTags: false
})
})

it('Initialize the apply function', () => {
compilerWebpack.hooks.emit.tap = jest.fn()

chunksWebpackPlugin.apply(compilerWebpack)
Expand All @@ -98,15 +113,43 @@ describe('ChunksWebpackPlugin', () => {
expect(compilerWebpack.hooks.emit.tap).toHaveBeenCalled()
})

it('should init the hookEmit function', () => {
it('Initialize the hookEmit function', () => {
chunksWebpackPlugin.createHtmlChunksFiles = jest.fn()

chunksWebpackPlugin.hookEmit(compilationWebpack)

expect(chunksWebpackPlugin.createHtmlChunksFiles).toHaveBeenCalled()
})

it('should init the hookEmit function with wrong returns of customFormatTags', () => {
it('Initialize the hookEmit function without chunks', () => {
chunksWebpackPlugin.sortsChunksByType = jest.fn()

compilationWebpack.chunkGroups[0].chunks = []
chunksWebpackPlugin.hookEmit(compilationWebpack)

expect(chunksWebpackPlugin.sortsChunksByType).not.toHaveBeenCalled()
})

it('Initialize the hookEmit function without generating chunk files', () => {
chunksWebpackPlugin.createHtmlChunksFiles = jest.fn()

chunksWebpackPlugin.options.generateChunksFiles = false
chunksWebpackPlugin.hookEmit(compilationWebpack)

expect(chunksWebpackPlugin.createHtmlChunksFiles).not.toHaveBeenCalled()
})

it('Initialize the hookEmit function without generating chunk manifest', () => {
chunksWebpackPlugin.createHtmlChunksFiles = jest.fn()
chunksWebpackPlugin.updateManifest = jest.fn()

chunksWebpackPlugin.options.generateChunksManifest = false
chunksWebpackPlugin.hookEmit(compilationWebpack)

expect(chunksWebpackPlugin.updateManifest).not.toHaveBeenCalled()
})

it('Initialize the hookEmit function with wrong returns of customFormatTags', () => {
chunksWebpackPlugin.createHtmlChunksFiles = jest.fn()
utils.setError = jest.fn()

Expand All @@ -117,7 +160,7 @@ describe('ChunksWebpackPlugin', () => {
expect(chunksWebpackPlugin.createHtmlChunksFiles).toHaveBeenCalled()
})

it('should init the hookEmit function with wrong declaration of customFormatTags', () => {
it('Initialize the hookEmit function with wrong declaration of customFormatTags', () => {
chunksWebpackPlugin.createHtmlChunksFiles = jest.fn()
chunksWebpackPlugin.generateTags = jest.fn()

Expand All @@ -127,7 +170,7 @@ describe('ChunksWebpackPlugin', () => {
expect(chunksWebpackPlugin.generateTags).toHaveBeenCalled()
})

it('should init the updateManifest function', () => {
it('Initialize the updateManifest function', () => {
updateManifest()

expect(chunksWebpackPlugin.manifest).toMatchObject({
Expand All @@ -138,26 +181,41 @@ describe('ChunksWebpackPlugin', () => {
})
})

it('should init the getPublicPath function', () => {
it('Initialize the getPublicPath function', () => {
const publicPath = chunksWebpackPlugin.getPublicPath(compilationWebpack)

expect(publicPath).toBe('/dist/')
})

it('should init the getOutputPath function', () => {
it('Initialize the getPublicPath function with empty value', () => {
compilationWebpack.options.output.publicPath = false
const publicPath = chunksWebpackPlugin.getPublicPath(compilationWebpack)

expect(publicPath).toBe('')
})

it('Initialize the getOutputPath function', () => {
const outputPath = chunksWebpackPlugin.getOutputPath(compilationWebpack)

expect(outputPath).toBe('/dist/templates')
})

it('should init the getOutputPath function with default outputPath', () => {
it('Initialize the getOutputPath function with default outputPath', () => {
chunksWebpackPlugin.options.outputPath = 'default'
const outputPath = chunksWebpackPlugin.getOutputPath(compilationWebpack)

expect(outputPath).toBe('/dist/')
})

it('should init the getOutputPath function with wrong outputPath', () => {
it('Initialize the getOutputPath function with default outputPath and without value', () => {
compilationWebpack.options.output.path = false
chunksWebpackPlugin.options.outputPath = 'default'
const outputPath = chunksWebpackPlugin.getOutputPath(compilationWebpack)

expect(outputPath).toBe('')
})

it('Initialize the getOutputPath function with wrong outputPath', () => {
utils.setError = jest.fn()

chunksWebpackPlugin.options.outputPath = ''
Expand All @@ -166,14 +224,27 @@ describe('ChunksWebpackPlugin', () => {
expect(utils.setError).toHaveBeenCalled()
})

it('should init the sortsChunksByType function', () => {
it('Initialize the sortsChunksByType function', () => {
expect(chunksSorted).toMatchObject({
styles: ['/dist/css/vendors~app-a~app-b.css'],
scripts: ['/dist/js/vendors~app-a~app-b.js']
})
})

it('should init the generateTags function', () => {
it('Initialize the sortsChunksByType function with scripts only', () => {
let chunksSorted = chunksWebpackPlugin.sortsChunksByType({
chunks: [{
files: [
'css/vendors~app-a~app-b.css'
]
}],
publicPath: chunksWebpackPlugin.getPublicPath(compilationWebpack)
})

expect(chunksSorted.scripts.length).toEqual(0)
})

it('Initialize the generateTags function', () => {
const tags = chunksWebpackPlugin.generateTags(chunksSorted)

expect(tags).toMatchObject({
Expand All @@ -182,7 +253,7 @@ describe('ChunksWebpackPlugin', () => {
})
})

it('should init the createHtmlChunksFiles function', () => {
it('Initialize the createHtmlChunksFiles function', () => {
utils.writeFile = jest.fn()

chunksWebpackPlugin.createHtmlChunksFiles({
Expand All @@ -197,7 +268,22 @@ describe('ChunksWebpackPlugin', () => {
expect(utils.writeFile).toHaveBeenCalled()
})

it('should init the createChunksManifestFile function', () => {
it('Initialize the createHtmlChunksFiles function without styles and scripts', () => {
utils.writeFile = jest.fn()

chunksWebpackPlugin.createHtmlChunksFiles({
entry: 'app-a',
tagsHTML: {
styles: '',
scripts: ''
},
outputPath: '/dist/'
})

expect(utils.writeFile).not.toHaveBeenCalled()
})

it('Initialize the createChunksManifestFile function', () => {
updateManifest()

chunksWebpackPlugin.createChunksManifestFile({
Expand Down
12 changes: 10 additions & 2 deletions src/__tests__/utils.test.js
Expand Up @@ -4,13 +4,21 @@ import utils from '../utils'
import fse from 'fs-extra'

describe('Utils', () => {
it('should init the setError function', () => {
it('Initialize the setError function', () => {
expect(() => {
utils.setError('message')
}).toThrow(new Error('message'))
})

it('should init the writeFile function', () => {
it('Initialize the isAbsolutePath function', () => {
expect(utils.isAbsolutePath('dist/')).toBe(false)
})

it('Initialize the getFileExtension function', () => {
expect(utils.getFileExtension('css/vendors~app-a~app-b.css')).toBe('css')
})

it('Initialize the writeFile function', () => {
fse.outputFileSync = jest.fn()

utils.writeFile({
Expand Down

0 comments on commit 806bd0a

Please sign in to comment.