@@ -10,18 +10,31 @@ import { SchematicTestRunner, UnitTestTree } from '@angular-devkit/schematics/te
10
10
import { Schema as ApplicationOptions , Style } from '../application/schema' ;
11
11
import { Schema as WorkspaceOptions } from '../workspace/schema' ;
12
12
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 > {
19
18
const workspaceOptions : WorkspaceOptions = {
20
19
name : 'workspace' ,
21
20
newProjectRoot : 'projects' ,
22
21
version : '6.0.0' ,
23
22
} ;
24
23
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
+
25
38
const appOptions : ApplicationOptions = {
26
39
name : 'bar' ,
27
40
inlineStyle : false ,
@@ -35,8 +48,7 @@ describe('Tailwind Schematic', () => {
35
48
let appTree : UnitTestTree ;
36
49
37
50
beforeEach ( async ( ) => {
38
- appTree = await schematicRunner . runSchematic ( 'workspace' , workspaceOptions ) ;
39
- appTree = await schematicRunner . runSchematic ( 'application' , appOptions , appTree ) ;
51
+ appTree = await createTestApp ( schematicRunner , appOptions ) ;
40
52
} ) ;
41
53
42
54
it ( 'should add tailwind dependencies' , async ( ) => {
@@ -47,17 +59,6 @@ describe('Tailwind Schematic', () => {
47
59
expect ( packageJson . devDependencies [ '@tailwindcss/postcss' ] ) . toBeDefined ( ) ;
48
60
} ) ;
49
61
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
-
61
62
it ( 'should add tailwind imports to styles.css' , async ( ) => {
62
63
const tree = await schematicRunner . runSchematic ( 'tailwind' , { project : 'bar' } , appTree ) ;
63
64
const stylesContent = tree . readContent ( '/projects/bar/src/styles.css' ) ;
@@ -76,12 +77,7 @@ describe('Tailwind Schematic', () => {
76
77
77
78
describe ( 'with scss styles' , ( ) => {
78
79
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 ) ;
85
81
} ) ;
86
82
87
83
it ( 'should create a tailwind.css file' , async ( ) => {
@@ -93,8 +89,8 @@ describe('Tailwind Schematic', () => {
93
89
94
90
it ( 'should add tailwind.css to angular.json' , async ( ) => {
95
91
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 ;
98
94
expect ( styles ) . toEqual ( [ 'projects/bar/src/tailwind.css' , 'projects/bar/src/styles.scss' ] ) ;
99
95
} ) ;
100
96
0 commit comments