UNPKG

3.1 kBJavaScriptView Raw
1var test = require('tape')
2var assert = require('assert')
3var fs = require('fs')
4var path = require('path')
5var browserify = require('browserify')
6var concat = require('concat-stream')
7var commonShake = require('../')
8
9function runTest (t, name) {
10 t.plan(1)
11 var basedir = path.join(__dirname, name)
12 var optionsPath = path.join(basedir, 'options.js')
13 var options = {}
14 try { options = require(optionsPath)(t) } catch (err) {}
15 var entry = path.join(basedir, 'app.js')
16 var expected = path.join(basedir, 'expected.js')
17 var actual = path.join(basedir, 'actual.js')
18 var bundle = browserify({ entries: entry })
19 .plugin(commonShake, options)
20 .bundle()
21 .on('error', t.fail)
22
23 // Write actual output to a file for easier inspection
24 bundle.pipe(fs.createWriteStream(actual))
25
26 bundle.pipe(concat(function (result) {
27 t.is(
28 result.toString('utf8'),
29 fs.readFileSync(expected, 'utf8'),
30 name
31 )
32 t.end()
33 }))
34}
35
36test('comment', function (t) {
37 runTest(t, 'comment')
38})
39test('dedupe', function (t) {
40 runTest(t, 'dedupe')
41})
42test('export-delete', function (t) {
43 runTest(t, 'export-delete')
44})
45test('funny-exports', function (t) {
46 runTest(t, 'funny-exports')
47})
48test('global-bailout', function (t) {
49 runTest(t, 'global-bailout')
50})
51test('module-bailout', function (t) {
52 runTest(t, 'module-bailout')
53})
54test('module-exports', function (t) {
55 runTest(t, 'module-exports')
56})
57test('multiple-assign', function (t) {
58 runTest(t, 'multiple-assign')
59})
60test('semi', function (t) {
61 runTest(t, 'semi')
62})
63test('simple', function (t) {
64 runTest(t, 'simple')
65})
66
67test('external', function (t) {
68 var b = browserify({
69 entries: path.join(__dirname, 'external/app.js')
70 })
71
72 b.external('xyz')
73
74 b.bundle(function (err, bundle) {
75 t.ifError(err)
76 t.end()
77 })
78})
79
80test('source maps', function (t) {
81 var b = browserify({
82 entries: path.join(__dirname, 'source-map/app.js'),
83 debug: true,
84 preludePath: 'node_modules/browser-pack/_prelude.js'
85 })
86 b.transform('babelify', {
87 plugins: [
88 'transform-es2015-modules-commonjs'
89 ]
90 })
91 b.plugin(commonShake)
92
93 var bundle = b.bundle()
94 bundle.on('error', t.fail)
95
96 // Write actual output to a file for easier inspection
97 bundle.pipe(fs.createWriteStream(
98 path.join(__dirname, 'source-map/actual.js')
99 ))
100
101 bundle.pipe(concat(function (result) {
102 t.is(
103 result.toString('utf8'),
104 fs.readFileSync(path.join(__dirname, 'source-map/expected.js'), 'utf8'),
105 'source maps'
106 )
107 t.end()
108 }))
109})
110
111test('dash-r', function (t) {
112 var b = browserify({
113 entries: path.join(__dirname, 'dash-r/app.js')
114 })
115 b.require(path.join(__dirname, 'dash-r/expose.js'), { expose: 'whatever' })
116 b.plugin(commonShake)
117
118 var bundle = b.bundle()
119 bundle.on('error', t.fail)
120
121 bundle.pipe(fs.createWriteStream(
122 path.join(__dirname, 'dash-r/actual.js')
123 ))
124
125 bundle.pipe(concat(function (result) {
126 t.is(
127 result.toString('utf8'),
128 fs.readFileSync(path.join(__dirname, 'dash-r/expected.js'), 'utf8'),
129 'dash-r'
130 )
131 t.end()
132 }))
133})