Skip to content
This repository was archived by the owner on Dec 3, 2023. It is now read-only.

Commit f661c0f

Browse files
committed
use uglify to normalise source for comparisons
1 parent 389861e commit f661c0f

File tree

7 files changed

+83
-85
lines changed

7 files changed

+83
-85
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@
3838
"grunt-karma": "~0.8.2",
3939
"karma-jasmine": "~0.2.2",
4040
"karma-phantomjs-launcher": "~0.1.2",
41-
"exports-loader": "^0.6.2"
41+
"exports-loader": "^0.6.2",
42+
"uglify-js": "~2.4.12"
4243
},
4344
"scripts": {
4445
"test": "grunt webpackScenario"

tasks/webpack-scenario.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ var webpack = require('webpack');
66
var async = require('async');
77
var _ = require('lodash');
88
_.str = require('underscore.string');
9+
var UglifyJS = require("uglify-js");
910

1011
function MockFileSystemPlugin() {
1112
this.files = {};
@@ -29,9 +30,16 @@ MockFileSystemPlugin.prototype.apply = function(compiler){
2930
});
3031
};
3132

32-
var IGNORE_BEFORE = "/******/ ([";
33-
var IGNORE_AFTER = "/******/ ])";
33+
var IGNORE_BEFORE = //"/******/ ([";
34+
"/************************************************************************/";
3435

36+
function normalise(content){
37+
return UglifyJS.minify(content, {
38+
fromString: true,
39+
//mangle: false,
40+
compress: false
41+
}).code;
42+
}
3543

3644
module.exports = function(grunt){
3745

@@ -72,9 +80,10 @@ module.exports = function(grunt){
7280
if( _.has(mockFs.files, p) ){
7381
var actual = mockFs.files[p];
7482
actual = _.str.strRight(actual, IGNORE_BEFORE);
75-
actual = _.str.strLeftBack(actual, IGNORE_AFTER);
7683
var expected = grunt.file.read(abspath);
77-
if( _.str.clean(expected) !== _.str.clean(actual)){
84+
var actualZ = normalise(actual);
85+
var expectedZ = normalise(expected);
86+
if( expectedZ !== actualZ){
7887
errors.push(p + " didn't match expected content");
7988
if( grunt.option('debug') ){
8089
grunt.log.debug("Expected:");
Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
1-
/* 0 */
2-
/***/ function(module, exports, require) {
1+
([
2+
function(module, exports, require) {
33
var __WEBPACK_LOCAL_MODULE_0__;
4-
/* WEBPACK VAR INJECTION */(function(require, angular) {// 1 dep
4+
(function(require, angular) {
55
(__WEBPACK_LOCAL_MODULE_0__ = module.exports = angular.module('myModule', [require(1).name]));
6-
/* WEBPACK VAR INJECTION */}.call(exports, require, require(2)))
6+
}.call(exports, require, require(2)))
77

8-
/***/ },
9-
/* 1 */
10-
/***/ function(module, exports, require) {
8+
},
9+
function(module, exports, require) {
1110
var __WEBPACK_LOCAL_MODULE_0__;
12-
/* WEBPACK VAR INJECTION */(function(require, angular) {
13-
(__WEBPACK_LOCAL_MODULE_0__ = module.exports = angular.module('dependency', []));
14-
/* WEBPACK VAR INJECTION */}.call(exports, require, require(2)))
15-
16-
/***/ },
17-
/* 2 */
18-
/***/ function(module, exports, require) {
19-
// stub for angular module
20-
/***/ }
11+
(function(require, angular) {
12+
(__WEBPACK_LOCAL_MODULE_0__ = module.exports = angular.module('dependency', []));
13+
}.call(exports, require, require(2)))
14+
},
15+
function(module, exports, require) {
16+
}
17+
])
Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
/* 0 */
2-
/***/ function(module, exports, require) {
1+
([
2+
function(module, exports, require) {
33
var __WEBPACK_LOCAL_MODULE_0__;
4-
/* WEBPACK VAR INJECTION */(function(require, angular) {// Simplest test
4+
(function(require, angular) {
55
(__WEBPACK_LOCAL_MODULE_0__ = module.exports = angular.module('myModule', []));
6-
/* WEBPACK VAR INJECTION */}.call(exports, require, require(1)))
7-
8-
/***/ },
9-
/* 1 */
10-
/***/ function(module, exports, require) {
11-
// stub for angular module
12-
/***/ }
6+
}.call(exports, require, require(1)))
7+
},
8+
function(module, exports, require) {
9+
}
10+
])
Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,23 @@
1-
/* 0 */
2-
/***/ function(module, exports, require) {
1+
([
2+
function(module, exports, require) {
33
var __WEBPACK_LOCAL_MODULE_0__;
4-
/* WEBPACK VAR INJECTION */(function(require, angular) {// deps with dots
5-
(__WEBPACK_LOCAL_MODULE_0__ = module.exports = angular.module('myModule', [require(2).name, require(3).name]));
6-
/* WEBPACK VAR INJECTION */}.call(exports, require, require(1)))
7-
/***/ },
8-
/* 1 */
9-
/***/ function(module, exports, require) {
10-
// stub for angular module
11-
/***/ },
12-
/* 2 */
13-
/***/ function(module, exports, require) {
4+
(function(require, angular) {
5+
(__WEBPACK_LOCAL_MODULE_0__ = module.exports = angular.module('myModule', [require(2).name, require(3).name]));
6+
}.call(exports, require, require(1)))
7+
},
8+
function(module, exports, require) {
9+
},
10+
function(module, exports, require) {
1411
var __WEBPACK_LOCAL_MODULE_0__;
15-
/* WEBPACK VAR INJECTION */(function(require, angular) {
16-
(__WEBPACK_LOCAL_MODULE_0__ = module.exports = angular.module('component/one', []));
17-
/* WEBPACK VAR INJECTION */}.call(exports, require, require(1)))
18-
/***/ },
19-
/* 3 */
20-
/***/ function(module, exports, require) {
12+
(function(require, angular) {
13+
(__WEBPACK_LOCAL_MODULE_0__ = module.exports = angular.module('component/one', []));
14+
}.call(exports, require, require(1)))
15+
},
16+
function(module, exports, require) {
2117
var __WEBPACK_LOCAL_MODULE_0__;
22-
/* WEBPACK VAR INJECTION */(function(require, angular) {
23-
(__WEBPACK_LOCAL_MODULE_0__ = module.exports = angular.module('component.two', []));
24-
/* WEBPACK VAR INJECTION */}.call(exports, require, require(1)))
25-
/***/ }
18+
(function(require, angular) {
19+
(__WEBPACK_LOCAL_MODULE_0__ = module.exports = angular.module('component.two', []));
20+
}.call(exports, require, require(1)))
21+
}
22+
])
23+
Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
/* 0 */
2-
/***/ function(module, exports, require) {
1+
([
2+
function(module, exports, require) {
33
var __WEBPACK_LOCAL_MODULE_0__;
4-
/* WEBPACK VAR INJECTION */(function(require, angular) {// Simplest test
4+
(function(require, angular) {
55
(__WEBPACK_LOCAL_MODULE_0__ = module.exports = angular.module('myModule', []));
66
__WEBPACK_LOCAL_MODULE_0__.config(function(){});
7-
/* WEBPACK VAR INJECTION */}.call(exports, require, require(1)))
8-
9-
/***/ },
10-
/* 1 */
11-
/***/ function(module, exports, require) {
12-
// stub for angular module
13-
/***/ }
7+
}.call(exports, require, require(1)))
8+
},
9+
function(module, exports, require) {
10+
}
11+
])
Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,22 @@
1-
/* 0 */
2-
/***/ function(module, exports, require) {
1+
([
2+
function(module, exports, require) {
33
var __WEBPACK_LOCAL_MODULE_0__;
4-
/* WEBPACK VAR INJECTION */(function(require, angular) {// deps with dots
5-
(__WEBPACK_LOCAL_MODULE_0__ = module.exports = angular.module('myModule', [require(1).name, require(2).name]));
6-
/* WEBPACK VAR INJECTION */}.call(exports, require, require(3)))
7-
/***/ },
8-
/* 1 */
9-
/***/ function(module, exports, require) {
4+
(function(require, angular) {
5+
(__WEBPACK_LOCAL_MODULE_0__ = module.exports = angular.module('myModule', [require(1).name, require(2).name]));
6+
}.call(exports, require, require(3)))
7+
},
8+
function(module, exports, require) {
109
var __WEBPACK_LOCAL_MODULE_0__;
11-
/* WEBPACK VAR INJECTION */(function(require, angular) {
12-
(__WEBPACK_LOCAL_MODULE_0__ = module.exports = angular.module('component', []));
13-
/* WEBPACK VAR INJECTION */}.call(exports, require, require(3)))
14-
/***/ },
15-
/* 2 */
16-
/***/ function(module, exports, require) {
10+
(function(require, angular) {
11+
(__WEBPACK_LOCAL_MODULE_0__ = module.exports = angular.module('component', []));
12+
}.call(exports, require, require(3)))
13+
},
14+
function(module, exports, require) {
1715
var __WEBPACK_LOCAL_MODULE_0__;
18-
/* WEBPACK VAR INJECTION */(function(require, angular) {
19-
(__WEBPACK_LOCAL_MODULE_0__ = module.exports = angular.module('component.two', []));
20-
/* WEBPACK VAR INJECTION */}.call(exports, require, require(3)))
21-
/***/ },
22-
/* 3 */
23-
/***/ function(module, exports, require) {
24-
// stub for angular module
25-
/***/ }
16+
(function(require, angular) {
17+
(__WEBPACK_LOCAL_MODULE_0__ = module.exports = angular.module('component.two', []));
18+
}.call(exports, require, require(3)))
19+
},
20+
function(module, exports, require) {
21+
}
22+
])

0 commit comments

Comments
 (0)