UNPKG

1.96 kBJavaScriptView Raw
1var browserify = require('../');
2var test = require('tap').test;
3var vm = require('vm');
4var path = require('path');
5
6test('ignore', function (t) {
7 t.plan(1);
8
9 var b = browserify();
10 b.add(__dirname + '/ignore/main.js');
11 b.ignore(path.join(__dirname, 'ignore/skip.js'));
12
13 b.bundle(function (err, src) {
14 if (err) t.fail(err);
15 vm.runInNewContext(src, { t: t });
16 });
17});
18
19test('ignore array', function(t) {
20 t.plan(2);
21
22 var b = browserify();
23 b.add(__dirname + '/ignore/array.js');
24 b.ignore([
25 path.join(__dirname, 'ignore/skip.js'),
26 path.join(__dirname, 'ignore/skip2.js')
27 ]);
28
29 b.bundle(function (err, src) {
30 if (err) {
31 t.fail(err);
32 }
33 vm.runInNewContext(src, { t: t });
34 });
35});
36
37test('ignore by package or id', function (t) {
38 t.plan(3);
39
40 var b = browserify();
41 b.add(__dirname + '/ignore/by-id.js');
42 b.ignore('events');
43 b.ignore('beep');
44 b.ignore('bad id');
45
46 b.bundle(function (err, src) {
47 if (err) t.fail(err);
48 vm.runInNewContext(src, { t: t });
49 });
50});
51
52test('ignore files referenced by relative path', function (t) {
53 // Change the current working directory relative to this file
54 var cwd = process.cwd();
55 process.chdir(__dirname);
56
57 t.plan(1);
58
59 var b = browserify();
60 b.add(__dirname + '/ignore/by-relative.js');
61 b.ignore('./ignore/ignored/skip.js');
62
63 b.bundle(function (err, src) {
64 if (err) t.fail(err);
65 vm.runInNewContext(src, { t: t });
66 });
67
68 // Revert CWD
69 process.chdir(cwd);
70});
71
72test('do not ignore files with relative paths that do not resolve', function (t) {
73 // Change the current working directory to the ignore folder
74 var cwd = process.cwd();
75 process.chdir(__dirname + '/ignore');
76
77 t.plan(2);
78
79 var b = browserify();
80 b.add(__dirname + '/ignore/double-skip.js');
81
82 b.ignore('./skip.js');
83
84 b.bundle(function (err, src) {
85 if (err) t.fail(err);
86 vm.runInNewContext(src, { t: t });
87 });
88
89 // Revert CWD
90 process.chdir(cwd);
91});