-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
/
Copy pathtreeshake.js
49 lines (45 loc) · 1.85 KB
/
treeshake.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
(function() {
// Tests in this module only work in the node.js environment.
if (typeof require !== 'function') return;
var fixturePrefix = __dirname + '/../test-treeshake/';
var moduleName = __dirname + '/../underscore-umd.js';
var fs = require('fs');
QUnit.module('Tree-shaking');
QUnit.test('should have an effect', function(assert) {
var done = assert.async();
var fixtureName = fixturePrefix + 'map-umd.js';
fs.stat(moduleName, function(error, moduleStats) {
assert.equal(error, null);
if (error) return done();
fs.stat(fixtureName, function(error, fixtureStats) {
assert.equal(error, null);
if (error) return done();
// _.template depends on the entire underscore object, so all of the
// source code should be included.
assert.ok(fixtureStats.size < moduleStats.size);
done();
});
});
});
QUnit.test('should not be overzealous', function(assert) {
var done = assert.async();
var fixtureName = fixturePrefix + 'template-umd.js';
fs.readFile(moduleName, {encoding: 'utf8'}, function(error, moduleData) {
assert.equal(error, null);
if (error) return done();
fs.readFile(fixtureName, {encoding: 'utf8'}, function(error, fixtureData) {
assert.equal(error, null);
if (error) return done();
var moduleLines = moduleData.split('\n').length,
fixtureLines = fixtureData.split('\n').length;
// _.template depends on the entire underscore object, so all of the
// source code should be included. Allowing for up to 9 lines of
// difference; this is the size of the noConflict logic plus the
// copyright intro, both of which are present in the official module but
// not in the fixture.
assert.ok(moduleLines - fixtureLines <= 9);
done();
});
});
});
}());