From e2f8fedf2605389986d866d0851f50f50f7ff773 Mon Sep 17 00:00:00 2001 From: Rich-Harris Date: Thu, 1 Dec 2016 11:50:10 -0500 Subject: [PATCH] add infrastructure for sourcemap tests --- package.json | 1 + test/sourcemaps/basic/input.html | 9 +++++++++ test/sourcemaps/basic/solo | 0 test/sourcemaps/basic/test.js | 7 +++++++ test/test.js | 22 ++++++++++++++++++++++ 5 files changed, 39 insertions(+) create mode 100644 test/sourcemaps/basic/input.html create mode 100644 test/sourcemaps/basic/solo create mode 100644 test/sourcemaps/basic/test.js diff --git a/package.json b/package.json index 96bcdcf10b..9f227ccf5a 100644 --- a/package.json +++ b/package.json @@ -56,6 +56,7 @@ "rollup-plugin-buble": "^0.14.0", "rollup-plugin-commonjs": "^5.0.5", "rollup-plugin-node-resolve": "^2.0.0", + "source-map": "^0.5.6", "source-map-support": "^0.4.6" }, "nyc": { diff --git a/test/sourcemaps/basic/input.html b/test/sourcemaps/basic/input.html new file mode 100644 index 0000000000..785dbb2d68 --- /dev/null +++ b/test/sourcemaps/basic/input.html @@ -0,0 +1,9 @@ +{{foo.bar.baz}} + + diff --git a/test/sourcemaps/basic/solo b/test/sourcemaps/basic/solo new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/sourcemaps/basic/test.js b/test/sourcemaps/basic/test.js new file mode 100644 index 0000000000..6c8d94128c --- /dev/null +++ b/test/sourcemaps/basic/test.js @@ -0,0 +1,7 @@ +export function test ( assert, code, map, smc, locator ) { + console.log( `code`, code ) + console.log( `map`, map ) + + let loc = locator( 'foo.bar.baz' ); + console.log( `loc`, loc ) +} diff --git a/test/test.js b/test/test.js index 9d132849e3..a956ac9852 100644 --- a/test/test.js +++ b/test/test.js @@ -5,6 +5,8 @@ import * as path from 'path'; import * as fs from 'fs'; import jsdom from 'jsdom'; import * as acorn from 'acorn'; +import { SourceMapConsumer } from 'source-map'; +import { getLocator } from 'locate-character'; import * as consoleGroup from 'console-group'; consoleGroup.install(); @@ -468,4 +470,24 @@ describe( 'svelte', () => { }); }); }); + + describe( 'sourcemaps', () => { + fs.readdirSync( 'test/sourcemaps' ).forEach( dir => { + if ( dir[0] === '.' ) return; + + const solo = exists( `test/sourcemaps/${dir}/solo` ); + + ( solo ? it.only : it )( dir, () => { + const input = fs.readFileSync( `test/sourcemaps/${dir}/input.html`, 'utf-8' ).replace( /\s+$/, '' ); + const { code, map } = svelte.compile( input ); + + const { test } = require( `./sourcemaps/${dir}/test.js` ); + + const smc = new SourceMapConsumer( map ); + const locator = getLocator( code ); + + test( assert, code, map, smc, locator ); + }); + }); + }); });