@@ -110,6 +110,19 @@ describe('Application Schematic', () => {
110110 expect ( _extends ) . toBe ( '../../tsconfig.json' ) ;
111111 } ) ;
112112
113+ it ( 'should set the right types in the tsconfig.spec.json when testRunner is karma' , async ( ) => {
114+ const tree = await schematicRunner . runSchematic (
115+ 'application' ,
116+ { ...defaultOptions , testRunner : 'karma' } ,
117+ workspaceTree ,
118+ ) ;
119+
120+ const {
121+ compilerOptions : { types } ,
122+ } = readJsonFile ( tree , '/projects/foo/tsconfig.spec.json' ) ;
123+ expect ( types ) . toEqual ( [ 'jasmine' ] ) ;
124+ } ) ;
125+
113126 it ( 'should add project references in the root tsconfig.json' , async ( ) => {
114127 const tree = await schematicRunner . runSchematic ( 'application' , defaultOptions , workspaceTree ) ;
115128
@@ -324,6 +337,30 @@ describe('Application Schematic', () => {
324337 expect ( pkg . dependencies [ 'zone.js' ] ) . toBeUndefined ( ) ;
325338 } ) ;
326339
340+ it ( 'should add karma dependencies when testRunner is karma' , async ( ) => {
341+ const tree = await schematicRunner . runSchematic (
342+ 'application' ,
343+ {
344+ ...defaultOptions ,
345+ testRunner : 'karma' ,
346+ } ,
347+ workspaceTree ,
348+ ) ;
349+
350+ const pkg = JSON . parse ( tree . readContent ( '/package.json' ) ) ;
351+ expect ( pkg . devDependencies [ 'karma' ] ) . toEqual ( latestVersions [ 'karma' ] ) ;
352+ expect ( pkg . devDependencies [ 'karma-chrome-launcher' ] ) . toEqual (
353+ latestVersions [ 'karma-chrome-launcher' ] ,
354+ ) ;
355+ expect ( pkg . devDependencies [ 'karma-coverage' ] ) . toEqual ( latestVersions [ 'karma-coverage' ] ) ;
356+ expect ( pkg . devDependencies [ 'karma-jasmine' ] ) . toEqual ( latestVersions [ 'karma-jasmine' ] ) ;
357+ expect ( pkg . devDependencies [ 'karma-jasmine-html-reporter' ] ) . toEqual (
358+ latestVersions [ 'karma-jasmine-html-reporter' ] ,
359+ ) ;
360+ expect ( pkg . devDependencies [ 'jasmine-core' ] ) . toEqual ( latestVersions [ 'jasmine-core' ] ) ;
361+ expect ( pkg . devDependencies [ '@types/jasmine' ] ) . toEqual ( latestVersions [ '@types/jasmine' ] ) ;
362+ } ) ;
363+
327364 it ( `should not override existing users dependencies` , async ( ) => {
328365 const oldPackageJson = workspaceTree . readContent ( 'package.json' ) ;
329366 workspaceTree . overwrite (
@@ -391,12 +428,6 @@ describe('Application Schematic', () => {
391428 expect ( buildOpt . assets ) . toEqual ( [ { 'glob' : '**/*' , 'input' : 'public' } ] ) ;
392429 expect ( buildOpt . polyfills ) . toBeUndefined ( ) ;
393430 expect ( buildOpt . tsConfig ) . toEqual ( 'tsconfig.app.json' ) ;
394-
395- const testOpt = prj . architect . test . options ;
396- expect ( testOpt . tsConfig ) . toEqual ( 'tsconfig.spec.json' ) ;
397- expect ( testOpt . karmaConfig ) . toBeUndefined ( ) ;
398- expect ( testOpt . assets ) . toEqual ( [ { 'glob' : '**/*' , 'input' : 'public' } ] ) ;
399- expect ( testOpt . styles ) . toEqual ( [ 'src/styles.css' ] ) ;
400431 } ) ;
401432
402433 it ( 'should set values in angular.json correctly when using a style preprocessor' , async ( ) => {
@@ -407,51 +438,20 @@ describe('Application Schematic', () => {
407438 const prj = config . projects . foo ;
408439 const buildOpt = prj . architect . build . options ;
409440 expect ( buildOpt . styles ) . toEqual ( [ 'src/styles.sass' ] ) ;
410- const testOpt = prj . architect . test . options ;
411- expect ( testOpt . styles ) . toEqual ( [ 'src/styles.sass' ] ) ;
412441 expect ( tree . exists ( 'src/styles.sass' ) ) . toBe ( true ) ;
413442 } ) ;
414443
415- it ( 'sets "inlineStyleLanguage" in angular.json when using a style preprocessor' , async ( ) => {
416- const options = { ...defaultOptions , projectRoot : '' , style : Style . Sass } ;
417- const tree = await schematicRunner . runSchematic ( 'application' , options , workspaceTree ) ;
418-
419- const config = JSON . parse ( tree . readContent ( '/angular.json' ) ) ;
420- const prj = config . projects . foo ;
421-
422- const buildOpt = prj . architect . build . options ;
423- expect ( buildOpt . inlineStyleLanguage ) . toBe ( 'sass' ) ;
424-
425- const testOpt = prj . architect . test . options ;
426- expect ( testOpt . inlineStyleLanguage ) . toBe ( 'sass' ) ;
427- } ) ;
428-
429- it ( 'does not set "inlineStyleLanguage" in angular.json when not using a style preprocessor' , async ( ) => {
430- const options = { ...defaultOptions , projectRoot : '' } ;
444+ it ( 'should set values in angular.json correctly when testRunner is karma' , async ( ) => {
445+ const options = { ...defaultOptions , projectRoot : '' , testRunner : 'karma' as const } ;
431446 const tree = await schematicRunner . runSchematic ( 'application' , options , workspaceTree ) ;
432447
433448 const config = JSON . parse ( tree . readContent ( '/angular.json' ) ) ;
434449 const prj = config . projects . foo ;
435-
436- const buildOpt = prj . architect . build . options ;
437- expect ( buildOpt . inlineStyleLanguage ) . toBeUndefined ( ) ;
438-
439- const testOpt = prj . architect . test . options ;
440- expect ( testOpt . inlineStyleLanguage ) . toBeUndefined ( ) ;
441- } ) ;
442-
443- it ( 'does not set "inlineStyleLanguage" in angular.json when using CSS styles' , async ( ) => {
444- const options = { ...defaultOptions , projectRoot : '' , style : Style . Css } ;
445- const tree = await schematicRunner . runSchematic ( 'application' , options , workspaceTree ) ;
446-
447- const config = JSON . parse ( tree . readContent ( '/angular.json' ) ) ;
448- const prj = config . projects . foo ;
449-
450- const buildOpt = prj . architect . build . options ;
451- expect ( buildOpt . inlineStyleLanguage ) . toBeUndefined ( ) ;
452-
453- const testOpt = prj . architect . test . options ;
454- expect ( testOpt . inlineStyleLanguage ) . toBeUndefined ( ) ;
450+ const testOpt = prj . architect . test ;
451+ expect ( testOpt . builder ) . toEqual ( '@angular/build:karma' ) ;
452+ expect ( testOpt . options . tsConfig ) . toEqual ( 'tsconfig.spec.json' ) ;
453+ expect ( testOpt . options . assets ) . toEqual ( [ { glob : '**/*' , input : 'public' } ] ) ;
454+ expect ( testOpt . options . styles ) . toEqual ( [ 'src/styles.css' ] ) ;
455455 } ) ;
456456
457457 it ( 'should set the relative tsconfig paths' , async ( ) => {
@@ -482,12 +482,6 @@ describe('Application Schematic', () => {
482482 expect ( buildOpt . tsConfig ) . toEqual ( 'foo/tsconfig.app.json' ) ;
483483 expect ( buildOpt . assets ) . toEqual ( [ { 'glob' : '**/*' , 'input' : 'foo/public' } ] ) ;
484484
485- const testOpt = project . architect . test . options ;
486- expect ( testOpt . tsConfig ) . toEqual ( 'foo/tsconfig.spec.json' ) ;
487- expect ( testOpt . karmaConfig ) . toBeUndefined ( ) ;
488- expect ( testOpt . assets ) . toEqual ( [ { 'glob' : '**/*' , 'input' : 'foo/public' } ] ) ;
489- expect ( testOpt . styles ) . toEqual ( [ 'foo/src/styles.css' ] ) ;
490-
491485 const appTsConfig = readJsonFile ( tree , '/foo/tsconfig.app.json' ) ;
492486 expect ( appTsConfig . extends ) . toEqual ( '../tsconfig.json' ) ;
493487 const specTsConfig = readJsonFile ( tree , '/foo/tsconfig.spec.json' ) ;
0 commit comments