@@ -10,18 +10,33 @@ 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
+ const appTree = await runner . runSchematic ( 'workspace' , workspaceOptions ) ;
25
+
26
+ return runner . runSchematic ( 'application' , { ...appOptions , style } , appTree ) ;
27
+ }
28
+
29
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
30
+ function getWorkspace ( tree : UnitTestTree ) : any {
31
+ return JSON . parse ( tree . readContent ( '/angular.json' ) ) ;
32
+ }
33
+
34
+ describe ( 'Tailwind Schematic' , ( ) => {
35
+ const schematicRunner = new SchematicTestRunner (
36
+ '@schematics/angular' ,
37
+ require . resolve ( '../collection.json' ) ,
38
+ ) ;
39
+
25
40
const appOptions : ApplicationOptions = {
26
41
name : 'bar' ,
27
42
inlineStyle : false ,
@@ -35,8 +50,7 @@ describe('Tailwind Schematic', () => {
35
50
let appTree : UnitTestTree ;
36
51
37
52
beforeEach ( async ( ) => {
38
- appTree = await schematicRunner . runSchematic ( 'workspace' , workspaceOptions ) ;
39
- appTree = await schematicRunner . runSchematic ( 'application' , appOptions , appTree ) ;
53
+ appTree = await createTestApp ( schematicRunner , appOptions ) ;
40
54
} ) ;
41
55
42
56
it ( 'should add tailwind dependencies' , async ( ) => {
@@ -47,17 +61,6 @@ describe('Tailwind Schematic', () => {
47
61
expect ( packageJson . devDependencies [ '@tailwindcss/postcss' ] ) . toBeDefined ( ) ;
48
62
} ) ;
49
63
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
64
it ( 'should add tailwind imports to styles.css' , async ( ) => {
62
65
const tree = await schematicRunner . runSchematic ( 'tailwind' , { project : 'bar' } , appTree ) ;
63
66
const stylesContent = tree . readContent ( '/projects/bar/src/styles.css' ) ;
@@ -76,12 +79,7 @@ describe('Tailwind Schematic', () => {
76
79
77
80
describe ( 'with scss styles' , ( ) => {
78
81
beforeEach ( async ( ) => {
79
- appTree = await schematicRunner . runSchematic ( 'workspace' , workspaceOptions ) ;
80
- appTree = await schematicRunner . runSchematic (
81
- 'application' ,
82
- { ...appOptions , style : Style . Scss } ,
83
- appTree ,
84
- ) ;
82
+ appTree = await createTestApp ( schematicRunner , appOptions , Style . Scss ) ;
85
83
} ) ;
86
84
87
85
it ( 'should create a tailwind.css file' , async ( ) => {
@@ -93,8 +91,8 @@ describe('Tailwind Schematic', () => {
93
91
94
92
it ( 'should add tailwind.css to angular.json' , async ( ) => {
95
93
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 ;
94
+ const workspace = getWorkspace ( tree ) ;
95
+ const styles = workspace . projects . bar . architect . build . options . styles ;
98
96
expect ( styles ) . toEqual ( [ 'projects/bar/src/tailwind.css' , 'projects/bar/src/styles.scss' ] ) ;
99
97
} ) ;
100
98
0 commit comments