-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest.js
More file actions
133 lines (117 loc) · 4.12 KB
/
test.js
File metadata and controls
133 lines (117 loc) · 4.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
'use strict'
const gutil = require('gulp-util')
const path = require('path')
const assert = require('assert')
const relativeSourcemapsSource = require('./')
describe('relativeSourcemapsSource()', function () {
it('should update the sourcemaps content path in a single output file', function (done) {
// Simulate transpiling to an output directory in the project root
const stream = relativeSourcemapsSource({ dest: 'dist' })
const buffer = []
const files = [
// Source base directory in the project root
new gutil.File({
base: __dirname,
path: path.join(__dirname, 'file.js')
}),
// Source base directory in the "src" directory in the project root
// all files flat there
new gutil.File({
base: path.join(__dirname, 'src'),
path: path.join(__dirname, 'src/file.js')
}),
// Source base directory in the "src" directory in the project root
// files nested in different directory levels there
new gutil.File({
base: path.join(__dirname, 'src'),
path: path.join(__dirname, 'src/folder/file.js')
})
]
// Simulate how gulp-sourcemaps sets paths to source files -
// relatively to the source base directory
files[0].sourceMap = { sources: ['file.ts'] }
files[1].sourceMap = { sources: ['file.ts'] }
files[2].sourceMap = { sources: ['folder/file.ts'] }
stream.on('data', function (file) {
buffer.push(file)
})
stream.on('end', function () {
assert.equal(buffer.length, 3)
// Updated paths point from the output file location in the "dist"
// directory tree to the source file below the source base directory
assert.equal(buffer[0].sourceMap.sources[0], '../file.ts')
assert.equal(buffer[1].sourceMap.sources[0], '../src/file.ts')
assert.equal(buffer[2].sourceMap.sources[0], '../../src/folder/file.ts')
done()
})
files.forEach(function (file) {
stream.write(file)
})
stream.end()
})
it('should update the sourcemaps content path in a multi-file output bundle', function (done) {
// Simulate transpiling to an output directory in the project root
const stream = relativeSourcemapsSource({ dest: 'dist' })
const buffer = []
const files = [
new gutil.File({
base: path.join(__dirname, 'src'),
path: path.join(__dirname, 'src/bundle.js'),
relative: 'bundle.js',
cwd: __dirname
}),
]
// Simulate how gulp-sourcemaps sets paths to source files -
// relatively to the source base directory
files[0].sourceMap = {
sources: [
'file.ts',
'folder/file.ts'
]
}
stream.on('data', function (file) {
buffer.push(file)
})
stream.on('end', function () {
assert.equal(buffer.length, 1)
assert.equal(buffer[0].sourceMap.sources.length, 2)
// Updated paths point from the output file location in the "dist"
// directory tree to the source file below the source base directory
assert.equal(buffer[0].sourceMap.sources[0], '../src/file.ts')
assert.equal(buffer[0].sourceMap.sources[1], '../src/folder/file.ts')
done()
})
files.forEach(function (file) {
stream.write(file)
})
stream.end()
})
it('does not crash if sourcemaps source array is empty', function (done) {
// Simulate transpiling to an output directory in the project root
const stream = relativeSourcemapsSource({ dest: 'dist' })
const buffer = []
const files = [
// Source base directory in the project root
new gutil.File({
base: __dirname,
path: path.join(__dirname, 'file.d.ts')
})
]
// Simulate how gulp-sourcemaps sets paths to source files
// which are not valid JavaScript
files[0].sourceMap = { sources: [] }
stream.on('data', function (file) {
buffer.push(file)
})
stream.on('end', function () {
assert.equal(buffer.length, 1)
// No source list means no updates
assert.equal(buffer[0].sourceMap.sources.length, 0)
done()
})
files.forEach(function (file) {
stream.write(file)
})
stream.end()
})
})