Skip to content
This repository has been archived by the owner on Dec 5, 2019. It is now read-only.

Unit tests #59

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 24 additions & 4 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,9 +1,29 @@
{
"presets": [
"es2015"
[
"env",
{
"useBuiltIns": true,
"targets": {
"node": "4.3"
},
"exclude": [
"transform-async-to-generator",
"transform-regenerator"
]
}
]
],
"plugins": [
"syntax-object-rest-spread",
"transform-object-rest-spread"
]
[
"transform-object-rest-spread",
{ "useBuiltIns": true }
]
],
"env": {
"test": {
"presets": ["env"],
"plugins": ["transform-object-rest-spread"]
}
}
}
10 changes: 7 additions & 3 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
# editorconfig.org

[*]
indent_style = tab
charset = utf-8
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
trim_trailing_whitespace = true

[.md]
insert_final_newline = false
trim_trailing_whitespace = false
6 changes: 6 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
*.snap
/node_modules
/dist
/examples/build
/coverage/
/__tests__/stubs
55 changes: 2 additions & 53 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,54 +1,3 @@
{
"root": true,
"plugins": ["node"],
"extends": ["eslint:recommended", "plugin:node/recommended"],
"env": {
"node": true,
"jasmine": true
},
"rules": {
"quotes": ["error", "double"],
"no-undef": "error",
"no-extra-semi": "error",
"semi": "error",
"no-template-curly-in-string": "error",
"no-caller": "error",
"yoda": "error",
"eqeqeq": "error",
"global-require": "off",
"brace-style": "error",
"eol-last": "error",
"indent": ["error", "tab", { "SwitchCase": 1 }],
"no-extra-bind": "warn",
"no-empty": "off",
"no-multiple-empty-lines": "error",
"no-multi-spaces": "error",
"no-process-exit": "warn",
"space-in-parens": "error",
"no-trailing-spaces": "error",
"no-use-before-define": "off",
"no-unused-vars": ["error", {"args": "none"}],
"key-spacing": "error",
"space-infix-ops": "error",
"no-unsafe-negation": "error",
"no-loop-func": "warn",
"space-before-function-paren": ["error", "never"],
"space-before-blocks": "error",
"object-curly-spacing": ["error", "always"],
"keyword-spacing": ["error", {
"after": false,
"overrides": {
"try": {"after": true},
"else": {"after": true},
"throw": {"after": true},
"case": {"after": true},
"return": {"after": true},
"finally": {"after": true},
"do": {"after": true}
}
}],
"node/no-unpublished-require": 0,
"no-console": "off",
"valid-jsdoc": "error"
}
}
"extends": "webpack"
}
4 changes: 4 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
yarn.lock -diff
* text=auto
bin/* eol=lf
package-lock.json -diff
7 changes: 7 additions & 0 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<!--
1. Check the version of package you are using. If it's not the newest version, update and try again (see changelog while updating!).
2. If the issue is still there, write a minimal project showing the problem and expected output.
3. Link to the project and mention Node version and OS in your report.

**IMPORTANT! You should use [Stack Overflow](https://stackoverflow.com/) for support related questions.**
-->
5 changes: 5 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<!--
1. [Read and sign the CLA](https://cla.js.foundation/webpack/webpack.js.org). This needs to be done only once. PRs that haven't signed it won't be accepted.
2. Check out the [development guide](https://webpack.js.org/development/) for the API and development guidelines.
3. Read through the PR diff carefully as sometimes this can reveal issues. The work will be reviewed, but this can save some effort.
-->
15 changes: 15 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,18 @@ coverage/
*.log
.eslintcache


logs
npm-debug.log*
yarn-debug.log*
/coverage
/dist
/local
/reports
/node_modules
.DS_Store
Thumbs.db
.idea
.vscode
*.sublime-project
*.sublime-workspace
52 changes: 45 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,48 @@
sudo: false
dist: trusty
language: node_js
node_js:
- "4"
- "5"
- "6"
branches:
only:
- master
jobs:
fast_finish: true
allow_failures:
- env: WEBPACK_VERSION=canary
include:
- &test-latest
stage: Webpack latest
nodejs: 6
env: WEBPACK_VERSION=latest JOB_PART=test
script: npm run travis:$JOB_PART
- <<: *test-latest
nodejs: 4.3
env: WEBPACK_VERSION=latest JOB_PART=test
script: npm run travis:$JOB_PART
- <<: *test-latest
node_js: 8
env: WEBPACK_VERSION=latest JOB_PART=lint
script: npm run travis:$JOB_PART
- <<: *test-latest
node_js: 8
env: WEBPACK_VERSION=latest JOB_PART=coverage
script: npm run travis:$JOB_PART
after_success: 'bash <(curl -s https://codecov.io/bash)'
- stage: Webpack canary
before_script: npm i --no-save git://github.com/webpack/webpack.git#master
script: npm run travis:$JOB_PART
node_js: 8
env: WEBPACK_VERSION=canary JOB_PART=test
before_install:
- 'if [[ `npm -v` != 5* ]]; then npm i -g npm@^5.0.0; fi'
- nvm --version
- node --version
- npm --version
before_script:
- |-
if [ "$WEBPACK_VERSION" ]; then
npm i --no-save webpack@$WEBPACK_VERSION
fi
script:
- npm run build
- npm run test:all
- 'npm run travis:$JOB_PART'
after_success:
- bash <(curl -s https://codecov.io/bash)
- 'bash <(curl -s https://codecov.io/bash)'
8 changes: 8 additions & 0 deletions __tests__/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"plugins": [
"jest"
],
"env": {
"jest/globals": true
}
}
7 changes: 7 additions & 0 deletions __tests__/UglifyJsPlugin.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import UglifyJsPlugin from '../src/index';

describe('UglifyJsPlugin', () => {
it('has apply function', () => {
expect(typeof new UglifyJsPlugin().apply).toBe('function');
});
});
86 changes: 86 additions & 0 deletions __tests__/__snapshots__/all-options.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`errors 1`] = `Array []`;

exports[`main.js 1`] = `
"webpackJsonp([ 0 ], [ function(module, exports) {
module.exports = function() {
console.log(7);
};
} ], [ 0 ]);"
`;

exports[`manifest.js 1`] = `
"!function(modules) {
function __webpack_require__(moduleId) {
if (installedModules[moduleId]) return installedModules[moduleId].exports;
var module = installedModules[moduleId] = {
i: moduleId,
l: !1,
exports: {}
};
return modules[moduleId].call(module.exports, module, module.exports, __webpack_require__),
module.l = !0, module.exports;
}
var parentJsonpFunction = window.webpackJsonp;
window.webpackJsonp = function(chunkIds, moreModules, executeModules) {
for (var moduleId, chunkId, result, i = 0, resolves = []; i < chunkIds.length; i++) chunkId = chunkIds[i],
installedChunks[chunkId] && resolves.push(installedChunks[chunkId][0]), installedChunks[chunkId] = 0;
for (moduleId in moreModules) Object.prototype.hasOwnProperty.call(moreModules, moduleId) && (modules[moduleId] = moreModules[moduleId]);
for (parentJsonpFunction && parentJsonpFunction(chunkIds, moreModules, executeModules); resolves.length; ) resolves.shift()();
if (executeModules) for (i = 0; i < executeModules.length; i++) result = __webpack_require__(__webpack_require__.s = executeModules[i]);
return result;
};
var installedModules = {}, installedChunks = {
1: 0
};
__webpack_require__.e = function(chunkId) {
function onScriptComplete() {
script.onerror = script.onload = null, clearTimeout(timeout);
var chunk = installedChunks[chunkId];
0 !== chunk && (chunk && chunk[1](new Error(\\"Loading chunk \\" + chunkId + \\" failed.\\")),
installedChunks[chunkId] = void 0);
}
var installedChunkData = installedChunks[chunkId];
if (0 === installedChunkData) return new Promise(function(resolve) {
resolve();
});
if (installedChunkData) return installedChunkData[2];
var promise = new Promise(function(resolve, reject) {
installedChunkData = installedChunks[chunkId] = [ resolve, reject ];
});
installedChunkData[2] = promise;
var head = document.getElementsByTagName(\\"head\\")[0], script = document.createElement(\\"script\\");
script.type = \\"text/javascript\\", script.charset = \\"utf-8\\", script.async = !0, script.timeout = 12e4,
__webpack_require__.nc && script.setAttribute(\\"nonce\\", __webpack_require__.nc),
script.src = __webpack_require__.p + \\"\\" + chunkId + \\".js\\";
var timeout = setTimeout(onScriptComplete, 12e4);
return script.onerror = script.onload = onScriptComplete, head.appendChild(script),
promise;
}, __webpack_require__.m = modules, __webpack_require__.c = installedModules, __webpack_require__.d = function(exports, name, getter) {
__webpack_require__.o(exports, name) || Object.defineProperty(exports, name, {
configurable: !1,
enumerable: !0,
get: getter
});
}, __webpack_require__.n = function(module) {
var getter = module && module.__esModule ? function() {
return module.default;
} : function() {
return module;
};
return __webpack_require__.d(getter, \\"a\\", getter), getter;
}, __webpack_require__.o = function(object, property) {
return Object.prototype.hasOwnProperty.call(object, property);
}, __webpack_require__.p = \\"\\", __webpack_require__.oe = function(err) {
throw console.error(err), err;
};
}([]);"
`;

exports[`warnings 1`] = `
Array [
"Error: main.js from UglifyJs
Dropping unused variable a [./__tests__/stubs/entry.js:4,0]",
]
`;
9 changes: 9 additions & 0 deletions __tests__/__snapshots__/empty-options.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`errors 1`] = `Array []`;

exports[`main.js 1`] = `"webpackJsonp([0],[function(o,n){o.exports=function(){console.log(7)}}],[0]);"`;

exports[`manifest.js 1`] = `"!function(e){function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}var r=window.webpackJsonp;window.webpackJsonp=function(t,c,u){for(var i,a,f,l=0,s=[];l<t.length;l++)a=t[l],o[a]&&s.push(o[a][0]),o[a]=0;for(i in c)Object.prototype.hasOwnProperty.call(c,i)&&(e[i]=c[i]);for(r&&r(t,c,u);s.length;)s.shift()();if(u)for(l=0;l<u.length;l++)f=n(n.s=u[l]);return f};var t={},o={1:0};n.e=function(e){function r(){i.onerror=i.onload=null,clearTimeout(a);var n=o[e];0!==n&&(n&&n[1](new Error(\\"Loading chunk \\"+e+\\" failed.\\")),o[e]=void 0)}var t=o[e];if(0===t)return new Promise(function(e){e()});if(t)return t[2];var c=new Promise(function(n,r){t=o[e]=[n,r]});t[2]=c;var u=document.getElementsByTagName(\\"head\\")[0],i=document.createElement(\\"script\\");i.type=\\"text/javascript\\",i.charset=\\"utf-8\\",i.async=!0,i.timeout=12e4,n.nc&&i.setAttribute(\\"nonce\\",n.nc),i.src=n.p+\\"\\"+e+\\".js\\";var a=setTimeout(r,12e4);return i.onerror=i.onload=r,u.appendChild(i),c},n.m=e,n.c=t,n.d=function(e,r,t){n.o(e,r)||Object.defineProperty(e,r,{configurable:!1,enumerable:!0,get:t})},n.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(r,\\"a\\",r),r},n.o=function(e,n){return Object.prototype.hasOwnProperty.call(e,n)},n.p=\\"\\",n.oe=function(e){throw console.error(e),e}}([]);"`;

exports[`warnings 1`] = `Array []`;
Loading