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