sourcemap.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. var test = require('tape');
  2. var convert = require('convert-source-map');
  3. var insert = require('../');
  4. var mdeps = require('module-deps');
  5. var vm = require('vm');
  6. var path = require('path');
  7. test('sourcemap', function (t) {
  8. t.plan(6);
  9. var file = __dirname + '/sourcemap/main.js';
  10. var deps = mdeps()
  11. deps.on('data', function(row) {
  12. var src = row.source;
  13. var sm = convert.fromSource(src).toObject();
  14. t.deepEqual(sm.sources, [ 'test/sourcemap/main_es6.js' ]);
  15. t.deepEqual(sm.sourcesContent, [ 'console.log(`${__dirname}`, `${__filename}`);\n' ]);
  16. t.deepEqual(sm.mappings, ';AAAA,OAAO,CAAC,GAAG,MAAI,SAAS,OAAO,UAAU,CAAG,CAAC');
  17. t.equal(src.match(convert.commentRegex).length, 1);
  18. var c = {
  19. console: {
  20. log: function(dirname, filename) {
  21. t.equal(dirname, '/');
  22. t.equal(filename, '/main.js');
  23. }
  24. },
  25. };
  26. vm.runInNewContext(src, c);
  27. });
  28. deps.write({ transform: inserter, global: true });
  29. deps.end(file);
  30. });
  31. function inserter (file) {
  32. return insert(file, { debug: true, basedir: __dirname + '/sourcemap' });
  33. }