Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: add angular test for JS minification #6138

Merged
merged 2 commits into from Sep 29, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 12 additions & 0 deletions lighthouse-core/test/lib/minification-estimator-test.js
Expand Up @@ -5,9 +5,15 @@
*/
'use strict';

const fs = require('fs');
const path = require('path');
const assert = require('assert');
const {computeCSSTokenLength, computeJSTokenLength} = require('../../lib/minification-estimator');


const nodeModulesPath = path.join(__dirname, '../../../node_modules');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

require.resolve can handle all sorts of funky path issues this'll hit.

const angularJSPath = path.join(require.resolve('angular'), 'angular.js');
const angularFullScript = fs.readFileSync(angularJSPath, 'utf8');

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good call. I'll do ya one better, require.resolve('angular/angular.js') ;)

const angularFullScript = fs.readFileSync(path.join(nodeModulesPath, 'angular/angular.js'), 'utf8');

/* eslint-env jest */

describe('minification estimator', () => {
Expand Down Expand Up @@ -184,5 +190,11 @@ describe('minification estimator', () => {

assert.equal(computeJSTokenLength(js), 9);
});

it('should handle large, real javscript files', () => {
assert.equal(angularFullScript.length, 1364217);
// 1 - 405199 / 1364217 = estimated 70% smaller minified
assert.equal(computeJSTokenLength(angularFullScript), 405199);
});
});
});
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -81,6 +81,7 @@
"@types/update-notifier": "^1.0.2",
"@types/ws": "^4.0.1",
"@types/yargs": "^8.0.2",
"angular": "^1.7.4",
"babel-core": "^6.26.0",
"bundlesize": "^0.14.4",
"chalk": "^2.4.1",
Expand Down
4 changes: 4 additions & 0 deletions yarn.lock
Expand Up @@ -316,6 +316,10 @@ amdefine@>=0.0.4:
version "1.0.0"
resolved "https://registry.yarnpkg.com/amdefine/-/amdefine-1.0.0.tgz#fd17474700cb5cc9c2b709f0be9d23ce3c198c33"

angular@^1.7.4:
version "1.7.4"
resolved "https://registry.yarnpkg.com/angular/-/angular-1.7.4.tgz#c1bf4884c2d470c06907737a1bf0835a9f646f31"

ansi-align@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/ansi-align/-/ansi-align-1.1.0.tgz#2f0c1658829739add5ebb15e6b0c6e3423f016ba"
Expand Down