@@ -10,18 +10,31 @@ import { SchematicTestRunner, UnitTestTree } from '@angular-devkit/schematics/te
1010import { Schema as ApplicationOptions , Style } from '../application/schema' ;
1111import { Schema as WorkspaceOptions } from '../workspace/schema' ;
1212
13- describe ( 'Tailwind Schematic' , ( ) => {
14- const schematicRunner = new SchematicTestRunner (
15- '@schematics/angular' ,
16- require . resolve ( '../collection.json' ) ,
17- ) ;
18-
13+ async function createTestApp (
14+ runner : SchematicTestRunner ,
15+ appOptions : ApplicationOptions ,
16+ style = Style . Css ,
17+ ) : Promise < UnitTestTree > {
1918 const workspaceOptions : WorkspaceOptions = {
2019 name : 'workspace' ,
2120 newProjectRoot : 'projects' ,
2221 version : '6.0.0' ,
2322 } ;
2423
24+ let appTree = await runner . runSchematic ( 'workspace' , workspaceOptions ) ;
25+ return runner . runSchematic ( 'application' , { ...appOptions , style } , appTree ) ;
26+ }
27+
28+ function getWorkspace ( tree : UnitTestTree ) : any {
29+ return JSON . parse ( tree . readContent ( '/angular.json' ) ) ;
30+ }
31+
32+ describe ( 'Tailwind Schematic' , ( ) => {
33+ const schematicRunner = new SchematicTestRunner (
34+ '@schematics/angular' ,
35+ require . resolve ( '../collection.json' ) ,
36+ ) ;
37+
2538 const appOptions : ApplicationOptions = {
2639 name : 'bar' ,
2740 inlineStyle : false ,
@@ -35,8 +48,7 @@ describe('Tailwind Schematic', () => {
3548 let appTree : UnitTestTree ;
3649
3750 beforeEach ( async ( ) => {
38- appTree = await schematicRunner . runSchematic ( 'workspace' , workspaceOptions ) ;
39- appTree = await schematicRunner . runSchematic ( 'application' , appOptions , appTree ) ;
51+ appTree = await createTestApp ( schematicRunner , appOptions ) ;
4052 } ) ;
4153
4254 it ( 'should add tailwind dependencies' , async ( ) => {
@@ -47,17 +59,6 @@ describe('Tailwind Schematic', () => {
4759 expect ( packageJson . devDependencies [ '@tailwindcss/postcss' ] ) . toBeDefined ( ) ;
4860 } ) ;
4961
50- it ( 'should create a .postcssrc.json file in the project root' , async ( ) => {
51- const tree = await schematicRunner . runSchematic ( 'tailwind' , { project : 'bar' } , appTree ) ;
52- expect ( tree . exists ( '/projects/bar/.postcssrc.json' ) ) . toBe ( true ) ;
53- } ) ;
54-
55- it ( 'should configure tailwindcss plugin in .postcssrc.json' , async ( ) => {
56- const tree = await schematicRunner . runSchematic ( 'tailwind' , { project : 'bar' } , appTree ) ;
57- const postCssConfig = JSON . parse ( tree . readContent ( '/projects/bar/.postcssrc.json' ) ) ;
58- expect ( postCssConfig . plugins [ '@tailwindcss/postcss' ] ) . toBeDefined ( ) ;
59- } ) ;
60-
6162 it ( 'should add tailwind imports to styles.css' , async ( ) => {
6263 const tree = await schematicRunner . runSchematic ( 'tailwind' , { project : 'bar' } , appTree ) ;
6364 const stylesContent = tree . readContent ( '/projects/bar/src/styles.css' ) ;
@@ -76,12 +77,7 @@ describe('Tailwind Schematic', () => {
7677
7778 describe ( 'with scss styles' , ( ) => {
7879 beforeEach ( async ( ) => {
79- appTree = await schematicRunner . runSchematic ( 'workspace' , workspaceOptions ) ;
80- appTree = await schematicRunner . runSchematic (
81- 'application' ,
82- { ...appOptions , style : Style . Scss } ,
83- appTree ,
84- ) ;
80+ appTree = await createTestApp ( schematicRunner , appOptions , Style . Scss ) ;
8581 } ) ;
8682
8783 it ( 'should create a tailwind.css file' , async ( ) => {
@@ -93,8 +89,8 @@ describe('Tailwind Schematic', () => {
9389
9490 it ( 'should add tailwind.css to angular.json' , async ( ) => {
9591 const tree = await schematicRunner . runSchematic ( 'tailwind' , { project : 'bar' } , appTree ) ;
96- const angularJson = JSON . parse ( tree . readContent ( '/angular.json' ) ) ;
97- const styles = angularJson . projects . bar . architect . build . options . styles ;
92+ const workspace = getWorkspace ( tree ) ;
93+ const styles = workspace . projects . bar . architect . build . options . styles ;
9894 expect ( styles ) . toEqual ( [ 'projects/bar/src/tailwind.css' , 'projects/bar/src/styles.scss' ] ) ;
9995 } ) ;
10096
0 commit comments