|
| 1 | +const {readFileSync, exists} = require('fs'); |
| 2 | +const path = require('path'); |
| 3 | + |
| 4 | +const helper = require(process.env.BAZEL_NODE_RUNFILES_HELPER); |
| 5 | +const locationBase = 'build_bazel_rules_nodejs/packages/esbuild/test/sourcemap/'; |
| 6 | + |
| 7 | +// Location for :bundle_default |
| 8 | +const bundleDefaultLocation = helper.resolve(path.join(locationBase, 'bundle_default.js')); |
| 9 | +const bundleDefaultSourcemapLocation = |
| 10 | + helper.resolve(path.join(locationBase, 'bundle_default.js.map')); |
| 11 | + |
| 12 | +// Location for :bundle_inline |
| 13 | +const bundleInlineLocation = helper.resolve(path.join(locationBase, 'bundle_inline.js')); |
| 14 | + |
| 15 | +// Location for :bundle_external |
| 16 | +const bundleExternalLocation = helper.resolve(path.join(locationBase, 'bundle_external.js')); |
| 17 | +const bundleExternalSourcemapLocation = |
| 18 | + helper.resolve(path.join(locationBase, 'bundle_external.js.map')); |
| 19 | + |
| 20 | +// Location for :bundle_both |
| 21 | +const bundleBothLocation = helper.resolve(path.join(locationBase, 'bundle_both.js')); |
| 22 | +const bundleBothSourcemapLocation = helper.resolve(path.join(locationBase, 'bundle_both.js.map')); |
| 23 | + |
| 24 | +describe('esbuild sourcemap', () => { |
| 25 | + it('creates an external sourcemap by default', () => { |
| 26 | + const sourcemap = readFileSync(bundleDefaultSourcemapLocation, {encoding: 'utf8'}); |
| 27 | + expect(sourcemap).toContain( |
| 28 | + '"sources": ["../../../../../../../packages/esbuild/test/sourcemap/main.ts"]'); |
| 29 | + }); |
| 30 | + |
| 31 | + it('does not inline the sourcemap by default', () => { |
| 32 | + const bundle = readFileSync(bundleDefaultLocation, {encoding: 'utf8'}); |
| 33 | + expect(bundle).toContain('//# sourceMappingURL=bundle_default.js.map'); |
| 34 | + }); |
| 35 | + |
| 36 | + it('inlines the sourcemap when set to \'inline\'', () => { |
| 37 | + const bundle = readFileSync(bundleInlineLocation, {encoding: 'utf8'}); |
| 38 | + expect(bundle).toContain('//# sourceMappingURL=data:application/json;base64'); |
| 39 | + }); |
| 40 | + |
| 41 | + it('has no sourcemap comment when set to \'external\'', () => { |
| 42 | + const bundle = readFileSync(bundleExternalLocation, {encoding: 'utf8'}); |
| 43 | + expect(bundle).not.toContain('//# sourceMappingURL='); |
| 44 | + }); |
| 45 | + |
| 46 | + it('creates an external sourcemap when set to \'external\'', () => { |
| 47 | + const sourcemap = readFileSync(bundleExternalSourcemapLocation, {encoding: 'utf8'}); |
| 48 | + expect(sourcemap).toContain( |
| 49 | + '"sources": ["../../../../../../../packages/esbuild/test/sourcemap/main.ts"]'); |
| 50 | + }); |
| 51 | + |
| 52 | + it('inlines the sourcemap when set to \'both\'', () => { |
| 53 | + const bundle = readFileSync(bundleInlineLocation, {encoding: 'utf8'}); |
| 54 | + expect(bundle).toContain('//# sourceMappingURL=data:application/json;base64'); |
| 55 | + }); |
| 56 | + |
| 57 | + it('creates an external sourcemap when set to \'both\'', () => { |
| 58 | + const sourcemap = readFileSync(bundleDefaultSourcemapLocation, {encoding: 'utf8'}); |
| 59 | + expect(sourcemap).toContain( |
| 60 | + '"sources": ["../../../../../../../packages/esbuild/test/sourcemap/main.ts"]'); |
| 61 | + }); |
| 62 | +}) |
0 commit comments