license import '@tensorflow/tfjs-core' ; import '@tensorflow/tfjs-core/dist/public/chained_ops/register_all_chained_ops' ; import { parseTestEnvFromKarmaFlags , registerTestEnv , setTestEnvs , TEST_ENVS } from '@tensorflow/tfjs-core/dist/jasmine_util' ; import { TAGS } from './constants' ; registerTestEnv ( { name : 'webgl' , backendName : 'webgl' , flags : { 'WEBGL_VERSION' : 2 , 'WEBGL_CPU_FORWARD' : false , 'WEBGL_SIZE_UPLOAD_UNIFORM' : 0 } , isDataSync : true } ) ; registerTestEnv ( { name : 'cpu' , backendName : 'cpu' , isDataSync : true } ) ; declare let __karma__ ; if ( typeof __karma__ !== 'undefined' ) { const args = __karma__ . config . args || [ ] ; const testEnv = parseTestEnvFromKarmaFlags ( __karma__ . config . args , TEST_ENVS ) ; if ( testEnv != null ) { setTestEnvs ( [ testEnv ] ) ; } let tags ; args . forEach ( ( arg , i ) => { if ( arg === '--tags' ) { tags = parseTags ( args [ i + 1 ] ) ; } } ) ; setupTestFilters ( tags ) ; } /**
 * Given a string separated with comma, validate and return tags as an array.
 */ function parseTags ( tagsInput ) { if ( ! tagsInput || tagsInput === '' ) { throw new Error ( '--tags did not have any value. Please specify tags separated ' + 'by comma.' ) ; } const tags = tagsInput . split ( ',' ) ; const $tags = [ ] ; for ( let i = 0 ; i < tags . length ; i ++ ) { const tag = tags [ i ] . trim ( ) ; if ( ! TAGS . includes ( tag ) ) { throw new Error ( `Tag ${ tag } is not supported. Supported tags: ${ TAGS }` ) ; } $tags . push ( tag ) ; } return $tags ; } /**
 * Run Jasmine tests only for allowlisted tags.
 */ function setupTestFilters ( tags = [ ] ) { const env = jasmine . getEnv ( ) ; const grepFilter = env . specFilter ; env . specFilter = ( spec ) => { if ( ! grepFilter ( spec ) ) { return false ; } const name = spec . getFullName ( ) ; for ( let i = 0 ; i < tags . length ; i ++ ) { const tag = tags [ i ] ; if ( name . includes ( tag ) ) { return true ; } } return false ; } ; }