1
- ' use strict' ;
2
-
3
- const fs = require ( 'fs' ) ;
4
- const path = require ( ' path' ) ;
5
- const paths = require ( ' ../fixtures/paths' ) ;
6
- const browserify = require ( ' browserify' ) ;
7
- const sourcemapify = require ( ' ../../' ) ;
8
- const exorcist = require ( ' exorcist' ) ;
9
- const chai = require ( ' chai' ) ;
1
+ " use strict" ;
2
+
3
+ const fs = require ( "fs" ) ;
4
+ const path = require ( " path" ) ;
5
+ const paths = require ( " ../fixtures/paths" ) ;
6
+ const browserify = require ( " browserify" ) ;
7
+ const sourcemapify = require ( " ../../" ) ;
8
+ const exorcist = require ( " exorcist" ) ;
9
+ const chai = require ( " chai" ) ;
10
10
chai . should ( ) ;
11
11
12
12
describe ( 'Sourcemapify with "base" option' , ( ) => {
13
13
it ( 'should have no effect if "base" is an empty string' , done => {
14
14
browserify ( paths . entryFile , { debug : true } )
15
- . plugin ( sourcemapify , { base : '' } )
15
+ . plugin ( sourcemapify , { base : "" } )
16
16
. bundle ( )
17
17
. pipe ( exorcist ( paths . mapFile ) )
18
- . pipe ( fs . createWriteStream ( paths . bundleFile , ' utf8' ) )
19
- . on ( ' error' , done )
20
- . on ( ' finish' , ( ) => {
21
- let sourcemap = JSON . parse ( fs . readFileSync ( paths . mapFile , ' utf8' ) ) ;
18
+ . pipe ( fs . createWriteStream ( paths . bundleFile , " utf8" ) )
19
+ . on ( " error" , done )
20
+ . on ( " finish" , ( ) => {
21
+ let sourcemap = JSON . parse ( fs . readFileSync ( paths . mapFile , " utf8" ) ) ;
22
22
23
23
// Because `base` was an empty string, the sourcemap uses paths that
24
24
// are relative to the current directory
25
25
sourcemap . sources . should . deep . equal ( [
26
26
paths . preludeFile ,
27
- ' test/test-app/lib/foo.js' ,
28
- ' test/test-app/lib/index.js' ,
29
- ' test/test-app/lib/subdir/foo.js' ,
30
- ' test/test-app/lib/subdir/index.js' ,
31
- ' test/test-app/lib/subdir/subdir/foo.js' ,
32
- ' test/test-app/lib/subdir/subdir/index.js' ,
27
+ " test/test-app/lib/foo.js" ,
28
+ " test/test-app/lib/index.js" ,
29
+ " test/test-app/lib/subdir/foo.js" ,
30
+ " test/test-app/lib/subdir/index.js" ,
31
+ " test/test-app/lib/subdir/subdir/foo.js" ,
32
+ " test/test-app/lib/subdir/subdir/index.js" ,
33
33
] ) ;
34
34
35
35
done ( ) ;
@@ -41,38 +41,38 @@ describe('Sourcemapify with "base" option', () => {
41
41
. plugin ( sourcemapify , { base : process . cwd ( ) } )
42
42
. bundle ( )
43
43
. pipe ( exorcist ( paths . mapFile ) )
44
- . pipe ( fs . createWriteStream ( paths . bundleFile , ' utf8' ) )
45
- . on ( ' error' , done )
46
- . on ( ' finish' , ( ) => {
47
- let sourcemap = JSON . parse ( fs . readFileSync ( paths . mapFile , ' utf8' ) ) ;
44
+ . pipe ( fs . createWriteStream ( paths . bundleFile , " utf8" ) )
45
+ . on ( " error" , done )
46
+ . on ( " finish" , ( ) => {
47
+ let sourcemap = JSON . parse ( fs . readFileSync ( paths . mapFile , " utf8" ) ) ;
48
48
49
49
// Because `base` was an empty string, the sourcemap uses paths that
50
50
// are relative to the current directory
51
51
sourcemap . sources . should . deep . equal ( [
52
52
paths . preludeFile ,
53
- ' test/test-app/lib/foo.js' ,
54
- ' test/test-app/lib/index.js' ,
55
- ' test/test-app/lib/subdir/foo.js' ,
56
- ' test/test-app/lib/subdir/index.js' ,
57
- ' test/test-app/lib/subdir/subdir/foo.js' ,
58
- ' test/test-app/lib/subdir/subdir/index.js' ,
53
+ " test/test-app/lib/foo.js" ,
54
+ " test/test-app/lib/index.js" ,
55
+ " test/test-app/lib/subdir/foo.js" ,
56
+ " test/test-app/lib/subdir/index.js" ,
57
+ " test/test-app/lib/subdir/subdir/foo.js" ,
58
+ " test/test-app/lib/subdir/subdir/index.js" ,
59
59
] ) ;
60
60
61
61
done ( ) ;
62
62
} ) ;
63
63
} ) ;
64
64
65
- it ( ' should add an additional directory level to each path' , done => {
65
+ it ( " should add an additional directory level to each path" , done => {
66
66
const parentDir = path . basename ( process . cwd ( ) ) ;
67
67
68
68
browserify ( paths . entryFile , { debug : true } )
69
- . plugin ( sourcemapify , { base : '..' } )
69
+ . plugin ( sourcemapify , { base : ".." } )
70
70
. bundle ( )
71
71
. pipe ( exorcist ( paths . mapFile ) )
72
- . pipe ( fs . createWriteStream ( paths . bundleFile , ' utf8' ) )
73
- . on ( ' error' , done )
74
- . on ( ' finish' , ( ) => {
75
- let sourcemap = JSON . parse ( fs . readFileSync ( paths . mapFile , ' utf8' ) ) ;
72
+ . pipe ( fs . createWriteStream ( paths . bundleFile , " utf8" ) )
73
+ . on ( " error" , done )
74
+ . on ( " finish" , ( ) => {
75
+ let sourcemap = JSON . parse ( fs . readFileSync ( paths . mapFile , " utf8" ) ) ;
76
76
77
77
// Because `root` was an empty string, the sourcemap uses paths that
78
78
// are relative to the current directory
@@ -90,54 +90,54 @@ describe('Sourcemapify with "base" option', () => {
90
90
} ) ;
91
91
} ) ;
92
92
93
- it ( ' should remove directory levels from each path' , done => {
93
+ it ( " should remove directory levels from each path" , done => {
94
94
browserify ( paths . entryFile , { debug : true } )
95
- . plugin ( sourcemapify , { base : ' test/test-app' } )
95
+ . plugin ( sourcemapify , { base : " test/test-app" } )
96
96
. bundle ( )
97
97
. pipe ( exorcist ( paths . mapFile ) )
98
- . pipe ( fs . createWriteStream ( paths . bundleFile , ' utf8' ) )
99
- . on ( ' error' , done )
100
- . on ( ' finish' , ( ) => {
101
- let sourcemap = JSON . parse ( fs . readFileSync ( paths . mapFile , ' utf8' ) ) ;
98
+ . pipe ( fs . createWriteStream ( paths . bundleFile , " utf8" ) )
99
+ . on ( " error" , done )
100
+ . on ( " finish" , ( ) => {
101
+ let sourcemap = JSON . parse ( fs . readFileSync ( paths . mapFile , " utf8" ) ) ;
102
102
103
103
// Because `root` was an empty string, the sourcemap uses paths that
104
104
// are relative to the current directory
105
105
sourcemap . sources . should . deep . equal ( [
106
106
paths . preludeFile ,
107
- ' lib/foo.js' ,
108
- ' lib/index.js' ,
109
- ' lib/subdir/foo.js' ,
110
- ' lib/subdir/index.js' ,
111
- ' lib/subdir/subdir/foo.js' ,
112
- ' lib/subdir/subdir/index.js' ,
107
+ " lib/foo.js" ,
108
+ " lib/index.js" ,
109
+ " lib/subdir/foo.js" ,
110
+ " lib/subdir/index.js" ,
111
+ " lib/subdir/subdir/foo.js" ,
112
+ " lib/subdir/subdir/index.js" ,
113
113
] ) ;
114
114
115
115
done ( ) ;
116
116
} ) ;
117
117
} ) ;
118
118
119
- it ( ' should remove a directory level from each path via an absolute path' , done => {
120
- const absolutePath = path . resolve ( ' test' ) ;
119
+ it ( " should remove a directory level from each path via an absolute path" , done => {
120
+ const absolutePath = path . resolve ( " test" ) ;
121
121
122
122
browserify ( paths . entryFile , { debug : true } )
123
123
. plugin ( sourcemapify , { base : absolutePath } )
124
124
. bundle ( )
125
125
. pipe ( exorcist ( paths . mapFile ) )
126
- . pipe ( fs . createWriteStream ( paths . bundleFile , ' utf8' ) )
127
- . on ( ' error' , done )
128
- . on ( ' finish' , ( ) => {
129
- let sourcemap = JSON . parse ( fs . readFileSync ( paths . mapFile , ' utf8' ) ) ;
126
+ . pipe ( fs . createWriteStream ( paths . bundleFile , " utf8" ) )
127
+ . on ( " error" , done )
128
+ . on ( " finish" , ( ) => {
129
+ let sourcemap = JSON . parse ( fs . readFileSync ( paths . mapFile , " utf8" ) ) ;
130
130
131
131
// Because `root` was an empty string, the sourcemap uses paths that
132
132
// are relative to the current directory
133
133
sourcemap . sources . should . deep . equal ( [
134
134
paths . preludeFile ,
135
- ' test-app/lib/foo.js' ,
136
- ' test-app/lib/index.js' ,
137
- ' test-app/lib/subdir/foo.js' ,
138
- ' test-app/lib/subdir/index.js' ,
139
- ' test-app/lib/subdir/subdir/foo.js' ,
140
- ' test-app/lib/subdir/subdir/index.js' ,
135
+ " test-app/lib/foo.js" ,
136
+ " test-app/lib/index.js" ,
137
+ " test-app/lib/subdir/foo.js" ,
138
+ " test-app/lib/subdir/index.js" ,
139
+ " test-app/lib/subdir/subdir/foo.js" ,
140
+ " test-app/lib/subdir/subdir/index.js" ,
141
141
] ) ;
142
142
143
143
done ( ) ;
@@ -146,24 +146,24 @@ describe('Sourcemapify with "base" option', () => {
146
146
147
147
it ( 'should work in conjunction with the "root" option' , done => {
148
148
browserify ( paths . entryFile , { debug : true } )
149
- . plugin ( sourcemapify , { base : ' test/test-app/lib' , root : ' http://mysite.com/src/' } )
149
+ . plugin ( sourcemapify , { base : " test/test-app/lib" , root : " http://mysite.com/src/" } )
150
150
. bundle ( )
151
151
. pipe ( exorcist ( paths . mapFile ) )
152
- . pipe ( fs . createWriteStream ( paths . bundleFile , ' utf8' ) )
153
- . on ( ' error' , done )
154
- . on ( ' finish' , ( ) => {
155
- let sourcemap = JSON . parse ( fs . readFileSync ( paths . mapFile , ' utf8' ) ) ;
152
+ . pipe ( fs . createWriteStream ( paths . bundleFile , " utf8" ) )
153
+ . on ( " error" , done )
154
+ . on ( " finish" , ( ) => {
155
+ let sourcemap = JSON . parse ( fs . readFileSync ( paths . mapFile , " utf8" ) ) ;
156
156
157
157
// Because `root` was an empty string, the sourcemap uses paths that
158
158
// are relative to the current directory
159
159
sourcemap . sources . should . deep . equal ( [
160
160
paths . preludeFile ,
161
- ' http://mysite.com/src/foo.js' ,
162
- ' http://mysite.com/src/index.js' ,
163
- ' http://mysite.com/src/subdir/foo.js' ,
164
- ' http://mysite.com/src/subdir/index.js' ,
165
- ' http://mysite.com/src/subdir/subdir/foo.js' ,
166
- ' http://mysite.com/src/subdir/subdir/index.js' ,
161
+ " http://mysite.com/src/foo.js" ,
162
+ " http://mysite.com/src/index.js" ,
163
+ " http://mysite.com/src/subdir/foo.js" ,
164
+ " http://mysite.com/src/subdir/index.js" ,
165
+ " http://mysite.com/src/subdir/subdir/foo.js" ,
166
+ " http://mysite.com/src/subdir/subdir/index.js" ,
167
167
] ) ;
168
168
169
169
done ( ) ;
0 commit comments