mirror of
https://github.com/sveltejs/svelte.git
synced 2024-11-30 00:46:29 +01:00
show code for all compiled components if config.show, not just main.html
This commit is contained in:
parent
306a931176
commit
d94209ba31
31
test/test.js
31
test/test.js
@ -22,8 +22,12 @@ const svelte = process.env.COVERAGE ?
|
|||||||
|
|
||||||
const cache = {};
|
const cache = {};
|
||||||
|
|
||||||
|
let showCompiledCode = false;
|
||||||
|
|
||||||
require.extensions[ '.html' ] = function ( module, filename ) {
|
require.extensions[ '.html' ] = function ( module, filename ) {
|
||||||
const code = cache[ filename ] || ( cache[ filename ] = svelte.compile( fs.readFileSync( filename, 'utf-8' ) ).code );
|
const code = cache[ filename ] || ( cache[ filename ] = svelte.compile( fs.readFileSync( filename, 'utf-8' ) ).code );
|
||||||
|
if ( showCompiledCode ) console.log( addLineNumbers( code ) ); // eslint-disable-line no-console
|
||||||
|
|
||||||
return module._compile( code, filename );
|
return module._compile( code, filename );
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -49,6 +53,15 @@ function env () {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function addLineNumbers ( code ) {
|
||||||
|
return code.split( '\n' ).map( ( line, i ) => {
|
||||||
|
i = String( i + 1 );
|
||||||
|
while ( i.length < 3 ) i = ` ${i}`;
|
||||||
|
|
||||||
|
return `${i}: ${line.replace( /^\t+/, match => match.split( '\t' ).join( ' ' ) )}`;
|
||||||
|
}).join( '\n' );
|
||||||
|
}
|
||||||
|
|
||||||
describe( 'svelte', () => {
|
describe( 'svelte', () => {
|
||||||
before( () => {
|
before( () => {
|
||||||
function cleanChildren ( node ) {
|
function cleanChildren ( node ) {
|
||||||
@ -225,6 +238,8 @@ describe( 'svelte', () => {
|
|||||||
( config.skip ? it.skip : config.solo ? it.only : it )( dir, () => {
|
( config.skip ? it.skip : config.solo ? it.only : it )( dir, () => {
|
||||||
let compiled;
|
let compiled;
|
||||||
|
|
||||||
|
showCompiledCode = config.show;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const source = fs.readFileSync( `test/compiler/${dir}/main.html`, 'utf-8' );
|
const source = fs.readFileSync( `test/compiler/${dir}/main.html`, 'utf-8' );
|
||||||
compiled = svelte.compile( source );
|
compiled = svelte.compile( source );
|
||||||
@ -238,12 +253,6 @@ describe( 'svelte', () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const { code } = compiled;
|
const { code } = compiled;
|
||||||
const withLineNumbers = code.split( '\n' ).map( ( line, i ) => {
|
|
||||||
i = String( i + 1 );
|
|
||||||
while ( i.length < 3 ) i = ` ${i}`;
|
|
||||||
|
|
||||||
return `${i}: ${line.replace( /^\t+/, match => match.split( '\t' ).join( ' ' ) )}`;
|
|
||||||
}).join( '\n' );
|
|
||||||
|
|
||||||
// check that no ES2015+ syntax slipped in
|
// check that no ES2015+ syntax slipped in
|
||||||
try {
|
try {
|
||||||
@ -251,7 +260,7 @@ describe( 'svelte', () => {
|
|||||||
const es5 = spaces( startIndex ) + code.slice( startIndex ).replace( /export default .+/, '' );
|
const es5 = spaces( startIndex ) + code.slice( startIndex ).replace( /export default .+/, '' );
|
||||||
acorn.parse( es5, { ecmaVersion: 5 });
|
acorn.parse( es5, { ecmaVersion: 5 });
|
||||||
} catch ( err ) {
|
} catch ( err ) {
|
||||||
console.log( withLineNumbers ); // eslint-disable-line no-console
|
if ( !config.show ) console.log( addLineNumbers( code ) ); // eslint-disable-line no-console
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -262,14 +271,10 @@ describe( 'svelte', () => {
|
|||||||
try {
|
try {
|
||||||
SvelteComponent = require( `./compiler/${dir}/main.html` ).default;
|
SvelteComponent = require( `./compiler/${dir}/main.html` ).default;
|
||||||
} catch ( err ) {
|
} catch ( err ) {
|
||||||
console.log( withLineNumbers ); // eslint-disable-line no-console
|
if ( !config.show ) console.log( addLineNumbers( code ) ); // eslint-disable-line no-console
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( config.show ) {
|
|
||||||
console.log( withLineNumbers ); // eslint-disable-line no-console
|
|
||||||
}
|
|
||||||
|
|
||||||
return env()
|
return env()
|
||||||
.then( window => {
|
.then( window => {
|
||||||
const target = window.document.querySelector( 'main' );
|
const target = window.document.querySelector( 'main' );
|
||||||
@ -291,7 +296,7 @@ describe( 'svelte', () => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch( err => {
|
.catch( err => {
|
||||||
if ( !config.show ) console.log( withLineNumbers ); // eslint-disable-line no-console
|
if ( !config.show ) console.log( addLineNumbers( code ) ); // eslint-disable-line no-console
|
||||||
throw err;
|
throw err;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user