UNPKG

3.17 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})
66test('paren-exports', function (t) {
67 runTest(t, 'paren-exports')
68})
69
70test('external', function (t) {
71 var b = browserify({
72 entries: path.join(__dirname, 'external/app.js')
73 })
74
75 b.external('xyz')
76
77 b.bundle(function (err, bundle) {
78 t.ifError(err)
79 t.end()
80 })
81})
82
83test('source maps', function (t) {
84 var b = browserify({
85 entries: path.join(__dirname, 'source-map/app.js'),
86 debug: true,
87 preludePath: 'node_modules/browser-pack/_prelude.js'
88 })
89 b.transform('babelify', {
90 plugins: [
91 'transform-es2015-modules-commonjs'
92 ]
93 })
94 b.plugin(commonShake)
95
96 var bundle = b.bundle()
97 bundle.on('error', t.fail)
98
99 // Write actual output to a file for easier inspection
100 bundle.pipe(fs.createWriteStream(
101 path.join(__dirname, 'source-map/actual.js')
102 ))
103
104 bundle.pipe(concat(function (result) {
105 t.is(
106 result.toString('utf8'),
107 fs.readFileSync(path.join(__dirname, 'source-map/expected.js'), 'utf8'),
108 'source maps'
109 )
110 t.end()
111 }))
112})
113
114test('dash-r', function (t) {
115 var b = browserify({
116 entries: path.join(__dirname, 'dash-r/app.js')
117 })
118 b.require(path.join(__dirname, 'dash-r/expose.js'), { expose: 'whatever' })
119 b.plugin(commonShake)
120
121 var bundle = b.bundle()
122 bundle.on('error', t.fail)
123
124 bundle.pipe(fs.createWriteStream(
125 path.join(__dirname, 'dash-r/actual.js')
126 ))
127
128 bundle.pipe(concat(function (result) {
129 t.is(
130 result.toString('utf8'),
131 fs.readFileSync(path.join(__dirname, 'dash-r/expected.js'), 'utf8'),
132 'dash-r'
133 )
134 t.end()
135 }))
136})