Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

read.js 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. // Copyright 2017 Simon Lydell
  2. // X11 (“MIT”) Licensed. (See LICENSE.)
  3. var test = require("tape")
  4. var asyncify = require("simple-asyncify")
  5. var common = require("./common")
  6. var u = common.u
  7. var sourceMapResolve = require("../")
  8. var mapUrl = "operators%20map.json"
  9. var codeUrl = "./built files/operators:+-<>%25.js"
  10. var sourceUrl = "../source files/operators:+-<>%25.coffee"
  11. function readTest(t, files) {
  12. return function(file, callback) {
  13. var fileData = files[file]
  14. t.ok(fileData, "decoded file name")
  15. if (callback) {
  16. callback(null, fileData)
  17. } else {
  18. return fileData
  19. }
  20. }
  21. }
  22. function testResolveSourceMap(method, sync) {
  23. return function(t) {
  24. t.plan(2)
  25. if (sync) {
  26. method = asyncify(method)
  27. }
  28. var read = readTest(t, {
  29. "built files/operators map.json": "{}"
  30. })
  31. method(u(mapUrl), codeUrl, read, function(error) {
  32. t.error(error)
  33. })
  34. }
  35. }
  36. test(".resolveSourceMap", testResolveSourceMap(sourceMapResolve.resolveSourceMap, false))
  37. test(".resolveSourceMapSync", testResolveSourceMap(sourceMapResolve.resolveSourceMapSync, true))
  38. function testResolveSources(method, sync) {
  39. return function(t) {
  40. t.plan(2)
  41. if (sync) {
  42. method = asyncify(method)
  43. }
  44. var map = {
  45. sources: [sourceUrl]
  46. }
  47. var read = readTest(t, {
  48. "../source files/operators:+-<>%.coffee": "source code"
  49. })
  50. method(map, mapUrl, read, function(error) {
  51. t.error(error)
  52. })
  53. }
  54. }
  55. test(".resolveSources", testResolveSources(sourceMapResolve.resolveSources, false))
  56. test(".resolveSourcesSync", testResolveSources(sourceMapResolve.resolveSourcesSync, true))
  57. function testResolve(method, sync) {
  58. return function(t) {
  59. t.plan(3)
  60. if (sync) {
  61. method = asyncify(method)
  62. }
  63. var map = {
  64. sources: [sourceUrl]
  65. }
  66. var read = readTest(t, {
  67. "built files/operators map.json": JSON.stringify(map),
  68. "source files/operators:+-<>%.coffee": "source code"
  69. })
  70. method(u(mapUrl), codeUrl, read, function(error) {
  71. t.error(error)
  72. })
  73. }
  74. }
  75. test(".resolve", testResolve(sourceMapResolve.resolve, false))
  76. test(".resolveSync", testResolve(sourceMapResolve.resolveSync, true))