Browse Source

Updated test for loader sourcemaps

ghi-672
Permutator 9 years ago
parent
commit
2a7a1a7090
No known key found for this signature in database GPG Key ID: 763F7A2F18CAB33E
  1. 42
      test/sourcemaps/loaders/_config.js
  2. 1
      test/sourcemaps/loaders/bar.js
  3. 4
      test/sourcemaps/loaders/foo.js
  4. 5
      test/sourcemaps/loaders/main.js

42
test/sourcemaps/loaders/_config.js

@ -10,20 +10,26 @@ module.exports = {
plugins: [
{
load: function ( id ) {
if ( id.endsWith( 'main.js' ) ) {
id = id.replace( /main.js$/, 'foo.js' );
} else {
id = id.replace( /foo.js$/, 'main.js' );
if ( id.endsWith( 'foo.js' ) ) {
id = id.replace( /foo.js$/, 'bar.js' );
} else if ( id.endsWith( 'bar.js' ) ) {
id = id.replace( /bar.js$/, 'foo.js' );
}
var out = babel.transformFileSync( id, {
blacklist: [ 'es6.modules' ],
sourceMap: true
sourceMap: true,
comments: false // misalign the columns
});
const slash = out.map.sources[0].lastIndexOf( '/' ) + 1;
out.map.sources = out.map.sources.map( source => '../' + source.slice( slash ) );
out.map.sourceRoot = 'fake';
if ( id.endsWith( 'main.js' ) ) {
delete out.map.sources;
//throw new Error(JSON.stringify(out.code));
} else {
const slash = out.map.sources[0].lastIndexOf( '/' ) + 1;
out.map.sources = out.map.sources.map( source => '../' + source.slice( slash ) );
out.map.sourceRoot = 'fake';
}
return { code: out.code, map: out.map };
}
@ -33,18 +39,26 @@ module.exports = {
test: function ( code, map ) {
var smc = new SourceMapConsumer( map );
var generatedLoc = getLocation( code, code.indexOf( '42' ) );
var generatedLoc = getLocation( code, code.indexOf( '22' ) );
var originalLoc = smc.originalPositionFor( generatedLoc );
assert.equal( originalLoc.source, '../main.js' );
assert.equal( originalLoc.source, '../foo.js' );
assert.equal( originalLoc.line, 1 );
assert.equal( originalLoc.column, 25 );
assert.equal( originalLoc.column, 32 );
var generatedLoc = getLocation( code, code.indexOf( '20' ) );
var originalLoc = smc.originalPositionFor( generatedLoc );
assert.equal( originalLoc.source, '../bar.js' );
assert.equal( originalLoc.line, 1 );
assert.equal( originalLoc.column, 37 );
generatedLoc = getLocation( code, code.indexOf( 'log' ) );
originalLoc = smc.originalPositionFor( generatedLoc );
assert.equal( originalLoc.source, '../foo.js' );
assert.equal( originalLoc.line, 3 );
assert.equal( originalLoc.column, 8 );
assert.equal( originalLoc.source, '../main.js' );
assert.ok( /columns/.test( smc.sourceContentFor( '../main.js' ) ) );
assert.equal( originalLoc.line, 4 );
assert.equal( originalLoc.column, 19 );
}
};

1
test/sourcemaps/loaders/bar.js

@ -0,0 +1 @@
/*misalign*/export const foo = () => 20;

4
test/sourcemaps/loaders/foo.js

@ -1,3 +1 @@
import { foo } from './foo';
console.log( `the answer is ${foo()}` );
/*the*/export const bar = () => 22;

5
test/sourcemaps/loaders/main.js

@ -1 +1,4 @@
export const foo = () => 42;
import { foo } from './foo';
import { bar } from './bar';
/*columns*/console.log( `the answer is ${foo() + bar()}` );

Loading…
Cancel
Save