forked from sveltejs/svelte
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsourcemaps.js
34 lines (25 loc) · 1.14 KB
/
sourcemaps.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import * as fs from 'fs';
import assert from 'assert';
import { svelte, exists } from './helpers.js';
import { SourceMapConsumer } from 'source-map';
import { getLocator } from 'locate-character';
describe( 'sourcemaps', () => {
fs.readdirSync( 'test/sourcemaps' ).forEach( dir => {
if ( dir[0] === '.' ) return;
const solo = exists( `test/sourcemaps/${dir}/solo` );
if ( solo && process.env.CI ) {
throw new Error( 'Forgot to remove `solo: true` from test' );
}
( solo ? it.only : it )( dir, () => {
const input = fs.readFileSync( `test/sourcemaps/${dir}/input.html`, 'utf-8' ).replace( /\s+$/, '' );
const { code, map } = svelte.compile( input );
fs.writeFileSync( `test/sourcemaps/${dir}/output.js`, `${code}\n//# sourceMappingURL=output.js.map` );
fs.writeFileSync( `test/sourcemaps/${dir}/output.js.map`, JSON.stringify( map, null, ' ' ) );
const { test } = require( `./sourcemaps/${dir}/test.js` );
const smc = new SourceMapConsumer( map );
const locateInSource = getLocator( input );
const locateInGenerated = getLocator( code );
test({ assert, code, map, smc, locateInSource, locateInGenerated });
});
});
});