import webpack , { StatsCompilation , StatsError , StatsModule , StatsModuleReason , } from 'webpack' ; import config from './webpack.js' ; function flatMap < A , B > ( arr , f ) { return arr . map ( f ) . reduce ( function ( a , b ) { return a . concat ( b ) ; } , [ ] ) ; } describe ( 'build' , ( ) => { let originalInterval ; beforeAll ( ( ) => { originalInterval = jasmine . DEFAULT_TIMEOUT_INTERVAL ; jasmine . DEFAULT_TIMEOUT_INTERVAL = 60000 ; } ) ; it ( 'should not import typescript other than in transformer' , ( done ) => { webpack ( config , ( err , stats ) => { if ( ! stats ) { fail ( 'Stats not generated' ) ; } const statsAsJson = stats ! . toJson ( ) ; if ( err || statsAsJson ?. errors ?. length ) { fail ( err || statsAsJson ! . errors ! . map ( ( statErr ) => JSON . stringify ( statErr ) ) . join ( '\n' ) ) ; } const modulesImportingTypescript = getModulesImportingTypescript ( statsAsJson ) ; expect ( modulesImportingTypescript . length ) . toBe ( 1 , `Only one transformer.ts should import typescript, but found:\n${ modulesImportingTypescript . map ( ( m ) => m . module ) . join ( ', ' ) }` ) ; expect ( modulesImportingTypescript [ 0 ] . module ) . toBe ( './src/transformer/transformer.ts' ) ; done ( ) ; } ) ; } ) ; function getModulesImportingTypescript ( statsAsJson ) { return flatMap ( statsAsJson . modules ?. filter ( ( x ) => x . identifier === 'external "typescript"' ) || [ ] , ( x ) => x . reasons || [ ] ) ; } afterAll ( ( ) => { jasmine . DEFAULT_TIMEOUT_INTERVAL = originalInterval ; } ) ; } ) ;