Skip to content

Commit d94209b

Browse files
committed
show code for all compiled components if config.show, not just main.html
1 parent 306a931 commit d94209b

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

test/test.js

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,12 @@ const svelte = process.env.COVERAGE ?
2222

2323
const cache = {};
2424

25+
let showCompiledCode = false;
26+
2527
require.extensions[ '.html' ] = function ( module, filename ) {
2628
const code = cache[ filename ] || ( cache[ filename ] = svelte.compile( fs.readFileSync( filename, 'utf-8' ) ).code );
29+
if ( showCompiledCode ) console.log( addLineNumbers( code ) ); // eslint-disable-line no-console
30+
2731
return module._compile( code, filename );
2832
};
2933

@@ -49,6 +53,15 @@ function env () {
4953
});
5054
}
5155

56+
function addLineNumbers ( code ) {
57+
return code.split( '\n' ).map( ( line, i ) => {
58+
i = String( i + 1 );
59+
while ( i.length < 3 ) i = ` ${i}`;
60+
61+
return `${i}: ${line.replace( /^\t+/, match => match.split( '\t' ).join( ' ' ) )}`;
62+
}).join( '\n' );
63+
}
64+
5265
describe( 'svelte', () => {
5366
before( () => {
5467
function cleanChildren ( node ) {
@@ -225,6 +238,8 @@ describe( 'svelte', () => {
225238
( config.skip ? it.skip : config.solo ? it.only : it )( dir, () => {
226239
let compiled;
227240

241+
showCompiledCode = config.show;
242+
228243
try {
229244
const source = fs.readFileSync( `test/compiler/${dir}/main.html`, 'utf-8' );
230245
compiled = svelte.compile( source );
@@ -238,20 +253,14 @@ describe( 'svelte', () => {
238253
}
239254

240255
const { code } = compiled;
241-
const withLineNumbers = code.split( '\n' ).map( ( line, i ) => {
242-
i = String( i + 1 );
243-
while ( i.length < 3 ) i = ` ${i}`;
244-
245-
return `${i}: ${line.replace( /^\t+/, match => match.split( '\t' ).join( ' ' ) )}`;
246-
}).join( '\n' );
247256

248257
// check that no ES2015+ syntax slipped in
249258
try {
250259
const startIndex = code.indexOf( 'function renderMainFragment' ); // may change!
251260
const es5 = spaces( startIndex ) + code.slice( startIndex ).replace( /export default .+/, '' );
252261
acorn.parse( es5, { ecmaVersion: 5 });
253262
} catch ( err ) {
254-
console.log( withLineNumbers ); // eslint-disable-line no-console
263+
if ( !config.show ) console.log( addLineNumbers( code ) ); // eslint-disable-line no-console
255264
throw err;
256265
}
257266

@@ -262,14 +271,10 @@ describe( 'svelte', () => {
262271
try {
263272
SvelteComponent = require( `./compiler/${dir}/main.html` ).default;
264273
} catch ( err ) {
265-
console.log( withLineNumbers ); // eslint-disable-line no-console
274+
if ( !config.show ) console.log( addLineNumbers( code ) ); // eslint-disable-line no-console
266275
throw err;
267276
}
268277

269-
if ( config.show ) {
270-
console.log( withLineNumbers ); // eslint-disable-line no-console
271-
}
272-
273278
return env()
274279
.then( window => {
275280
const target = window.document.querySelector( 'main' );
@@ -291,7 +296,7 @@ describe( 'svelte', () => {
291296
}
292297
})
293298
.catch( err => {
294-
if ( !config.show ) console.log( withLineNumbers ); // eslint-disable-line no-console
299+
if ( !config.show ) console.log( addLineNumbers( code ) ); // eslint-disable-line no-console
295300
throw err;
296301
});
297302
});

0 commit comments

Comments
 (0)