read.js
2.23 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
// Copyright 2017 Simon Lydell
// X11 (“MIT”) Licensed. (See LICENSE.)
var test = require("tape")
var asyncify = require("simple-asyncify")
var common = require("./common")
var u = common.u
var sourceMapResolve = require("../")
var mapUrl = "operators%20map.json"
var codeUrl = "./built files/operators:+-<>%25.js"
var sourceUrl = "../source files/operators:+-<>%25.coffee"
function readTest(t, files) {
return function(file, callback) {
var fileData = files[file]
t.ok(fileData, "decoded file name")
if (callback) {
callback(null, fileData)
} else {
return fileData
}
}
}
function testResolveSourceMap(method, sync) {
return function(t) {
t.plan(2)
if (sync) {
method = asyncify(method)
}
var read = readTest(t, {
"built files/operators map.json": "{}"
})
method(u(mapUrl), codeUrl, read, function(error) {
t.error(error)
})
}
}
test(".resolveSourceMap", testResolveSourceMap(sourceMapResolve.resolveSourceMap, false))
test(".resolveSourceMapSync", testResolveSourceMap(sourceMapResolve.resolveSourceMapSync, true))
function testResolveSources(method, sync) {
return function(t) {
t.plan(2)
if (sync) {
method = asyncify(method)
}
var map = {
sources: [sourceUrl]
}
var read = readTest(t, {
"../source files/operators:+-<>%.coffee": "source code"
})
method(map, mapUrl, read, function(error) {
t.error(error)
})
}
}
test(".resolveSources", testResolveSources(sourceMapResolve.resolveSources, false))
test(".resolveSourcesSync", testResolveSources(sourceMapResolve.resolveSourcesSync, true))
function testResolve(method, sync) {
return function(t) {
t.plan(3)
if (sync) {
method = asyncify(method)
}
var map = {
sources: [sourceUrl]
}
var read = readTest(t, {
"built files/operators map.json": JSON.stringify(map),
"source files/operators:+-<>%.coffee": "source code"
})
method(u(mapUrl), codeUrl, read, function(error) {
t.error(error)
})
}
}
test(".resolve", testResolve(sourceMapResolve.resolve, false))
test(".resolveSync", testResolve(sourceMapResolve.resolveSync, true))