mirror of https://github.com/sveltejs/svelte
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
1.4 KiB
44 lines
1.4 KiB
8 years ago
|
import * as fs from 'fs';
|
||
8 years ago
|
import * as path from 'path';
|
||
8 years ago
|
import assert from 'assert';
|
||
8 years ago
|
import { svelte, exists } from '../helpers.js';
|
||
8 years ago
|
import { SourceMapConsumer } from 'source-map';
|
||
|
import { getLocator } from 'locate-character';
|
||
|
|
||
|
describe( 'sourcemaps', () => {
|
||
8 years ago
|
fs.readdirSync( 'test/sourcemaps/samples' ).forEach( dir => {
|
||
8 years ago
|
if ( dir[0] === '.' ) return;
|
||
|
|
||
8 years ago
|
const solo = exists( `test/sourcemaps/samples/${dir}/solo` );
|
||
8 years ago
|
|
||
8 years ago
|
if ( solo && process.env.CI ) {
|
||
|
throw new Error( 'Forgot to remove `solo: true` from test' );
|
||
|
}
|
||
|
|
||
8 years ago
|
( solo ? it.only : it )( dir, () => {
|
||
8 years ago
|
const filename = path.resolve( `test/sourcemaps/samples/${dir}/input.html` );
|
||
|
const outputFilename = path.resolve( `test/sourcemaps/samples/${dir}/output.js` );
|
||
8 years ago
|
|
||
8 years ago
|
const input = fs.readFileSync( filename, 'utf-8' ).replace( /\s+$/, '' );
|
||
|
const { code, map } = svelte.compile( input, {
|
||
|
filename,
|
||
|
outputFilename
|
||
|
});
|
||
|
|
||
|
fs.writeFileSync( outputFilename, `${code}\n//# sourceMappingURL=output.js.map` );
|
||
|
fs.writeFileSync( `${outputFilename}.map`, JSON.stringify( map, null, ' ' ) );
|
||
|
|
||
|
assert.deepEqual( map.sources, [ 'input.html' ]);
|
||
8 years ago
|
|
||
8 years ago
|
const { test } = require( `./samples/${dir}/test.js` );
|
||
8 years ago
|
|
||
|
const smc = new SourceMapConsumer( map );
|
||
|
|
||
|
const locateInSource = getLocator( input );
|
||
|
const locateInGenerated = getLocator( code );
|
||
|
|
||
|
test({ assert, code, map, smc, locateInSource, locateInGenerated });
|
||
|
});
|
||
|
});
|
||
|
});
|