_generate-source-map-initial.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. 'use strict';
  2. const fs = require('fs');
  3. const path = require('path');
  4. const babel = require('@babel/core');
  5. const transformed = babel.transform(`
  6. import {mapFile} from 'source-map-fixtures';
  7. import test from '../../';
  8. const fixture = mapFile('throws').require();
  9. // The uncaught exception is passed to the corresponding cli test. The line
  10. // numbers from the 'throws' fixture (which uses a map file), as well as the
  11. // line of the fixture.run() call, should match the source lines from this
  12. // string.
  13. test('throw an uncaught exception', t => {
  14. setImmediate(run);
  15. t.pass();
  16. })
  17. const run = () => fixture.run();
  18. `.trim(), {
  19. filename: 'source-map-initial-input.js',
  20. sourceMaps: true,
  21. presets: ['@ava/stage-4']
  22. });
  23. fs.writeFileSync(
  24. path.join(__dirname, 'source-map-initial.js'),
  25. transformed.code + '\n//# sourceMappingURL=./source-map-initial.js.map\n// Generated using node test/fixtures/_generate-source-map-initial.js\n'
  26. );
  27. fs.writeFileSync(
  28. path.join(__dirname, 'source-map-initial.js.map'),
  29. JSON.stringify(transformed.map)
  30. );
  31. console.log('Generated source-map-initial.js');