UNPKG

4.64 kBJavaScriptView Raw
1'use strict';
2/*jshint asi: true */
3
4var test = require('tap').test
5 , getPacks = require('./util/get-packs')
6 , reset = require('./util/reset')
7 , viralify = require('../')
8
9var original = __dirname + '/original'
10 , copy = __dirname + '/copy'
11
12function inspect(obj, depth) {
13 console.error(require('util').inspect(obj, false, depth || 5, true));
14}
15
16test('\nviralifying one transform synchronously in different situations', function (t) {
17 reset(original, copy, runTest);
18
19 function runTest(err) {
20 if (err) { t.fail(err); t.end(); }
21
22 viralify.sync(copy, 'browserify-swap');
23
24 getPacks(copy, function (err, packs) {
25 if (err) { t.fail(err); t.end(); }
26
27 t.deepEqual(
28 packs
29 , [ { name: 'sub-sub-dep1',
30 description: 'has one transform already',
31 main: 'index.js',
32 browserify: { transform: [ 'unoify', 'browserify-swap' ] } },
33 { name: 'sub-dep2',
34 description: 'has no transforms',
35 main: 'index.js',
36 browserify: { transform: [ 'browserify-swap' ] } },
37 { name: 'sub-dep1',
38 description: 'Has no transforms',
39 main: 'index.js',
40 browserify: { transform: [ 'browserify-swap' ] } },
41 { name: 'original',
42 description: 'root project',
43 main: 'index.js',
44 browserify: { transform: [ 'browserify-swap' ] } },
45 { name: 'dep',
46 description: 'dep which itself has two transforms already',
47 main: 'index.js',
48 browserify:
49 { transform:
50 [ 'unoify',
51 'dosify',
52 'browserify-swap' ] } } ]
53 , 'adds transform to end when it was not present before'
54 )
55 addToEndAgain();
56 })
57
58 function addToEndAgain() {
59 viralify.sync(copy, 'browserify-swap')
60
61 getPacks(copy, function (err, packs) {
62 if (err) { t.fail(err); t.end(); }
63
64 t.deepEqual(
65 packs
66 , [ { name: 'sub-sub-dep1',
67 description: 'has one transform already',
68 main: 'index.js',
69 browserify: { transform: [ 'unoify', 'browserify-swap' ] } },
70 { name: 'sub-dep2',
71 description: 'has no transforms',
72 main: 'index.js',
73 browserify: { transform: [ 'browserify-swap' ] } },
74 { name: 'sub-dep1',
75 description: 'Has no transforms',
76 main: 'index.js',
77 browserify: { transform: [ 'browserify-swap' ] } },
78 { name: 'original',
79 description: 'root project',
80 main: 'index.js',
81 browserify: { transform: [ 'browserify-swap' ] } },
82 { name: 'dep',
83 description: 'dep which itself has two transforms already',
84 main: 'index.js',
85 browserify:
86 { transform:
87 [ 'unoify',
88 'dosify',
89 'browserify-swap' ] } } ]
90 , 'leaves one transform at end when it was present before'
91 )
92 addToFront();
93 })
94 }
95
96 function addToFront() {
97 viralify.sync(copy, 'browserify-swap', true)
98
99 getPacks(copy, function (err, packs) {
100 if (err) { t.fail(err); t.end(); }
101
102 t.deepEqual(
103 packs
104 , [ { name: 'sub-sub-dep1',
105 description: 'has one transform already',
106 main: 'index.js',
107 browserify: { transform: [ 'browserify-swap', 'unoify' ] } },
108 { name: 'sub-dep2',
109 description: 'has no transforms',
110 main: 'index.js',
111 browserify: { transform: [ 'browserify-swap' ] } },
112 { name: 'sub-dep1',
113 description: 'Has no transforms',
114 main: 'index.js',
115 browserify: { transform: [ 'browserify-swap' ] } },
116 { name: 'original',
117 description: 'root project',
118 main: 'index.js',
119 browserify: { transform: [ 'browserify-swap' ] } },
120 { name: 'dep',
121 description: 'dep which itself has two transforms already',
122 main: 'index.js',
123 browserify:
124 { transform:
125 [ 'browserify-swap',
126 'unoify',
127 'dosify' ] } } ]
128 , 'removes transform from end and adds it to front when it was present before and front flag was set'
129 )
130 t.end();
131 })
132 }
133 }
134})
135