@@ -3,6 +3,7 @@ import path from 'path'
33import cli from '../src/cli/main'
44import * as constants from '../src/constants'
55import * as utils from '../src/cli/utils'
6+ import runInTempDirectory from '../jest/runInTempDirectory'
67
78describe ( 'cli' , ( ) => {
89 const inputCssPath = path . resolve ( __dirname , 'fixtures/tailwind-input.css' )
@@ -13,37 +14,30 @@ describe('cli', () => {
1314 beforeEach ( ( ) => {
1415 console . log = jest . fn ( )
1516 process . stdout . write = jest . fn ( )
16- utils . writeFile = jest . fn ( )
1717 } )
1818
1919 describe ( 'init' , ( ) => {
2020 it ( 'creates a Tailwind config file' , ( ) => {
21- return cli ( [ 'init' ] ) . then ( ( ) => {
22- expect ( utils . writeFile . mock . calls [ 0 ] [ 0 ] ) . toEqual ( constants . defaultConfigFile )
21+ return runInTempDirectory ( ( ) => {
22+ return cli ( [ 'init' ] ) . then ( ( ) => {
23+ expect ( utils . readFile ( constants . defaultConfigFile ) ) . toEqual ( simpleConfigFixture )
24+ } )
2325 } )
2426 } )
2527
26- it ( 'creates a Tailwind config file in a custom location' , ( ) => {
27- return cli ( [ 'init' , 'custom.js' ] ) . then ( ( ) => {
28- expect ( utils . writeFile . mock . calls [ 0 ] [ 0 ] ) . toEqual ( 'custom.js' )
29- } )
30- } )
31-
32- it ( 'creates a Tailwind config file without comments' , ( ) => {
33- return cli ( [ 'init' , '--no-comments' ] ) . then ( ( ) => {
34- expect ( utils . writeFile . mock . calls [ 0 ] [ 1 ] ) . not . toContain ( '/**' )
35- } )
36- } )
37-
38- it ( 'creates a simple Tailwind config file' , ( ) => {
39- return cli ( [ 'init' ] ) . then ( ( ) => {
40- expect ( utils . writeFile . mock . calls [ 0 ] [ 1 ] ) . toEqual ( simpleConfigFixture )
28+ it ( 'creates a full Tailwind config file' , ( ) => {
29+ return runInTempDirectory ( ( ) => {
30+ return cli ( [ 'init' , '--full' ] ) . then ( ( ) => {
31+ expect ( utils . readFile ( constants . defaultConfigFile ) ) . toEqual ( defaultConfigFixture )
32+ } )
4133 } )
4234 } )
4335
44- it ( 'creates a full Tailwind config file' , ( ) => {
45- return cli ( [ 'init' , '--full' ] ) . then ( ( ) => {
46- expect ( utils . writeFile . mock . calls [ 0 ] [ 1 ] ) . toEqual ( defaultConfigFixture )
36+ it ( 'creates a Tailwind config file in a custom location' , ( ) => {
37+ return runInTempDirectory ( ( ) => {
38+ return cli ( [ 'init' , 'custom.js' ] ) . then ( ( ) => {
39+ expect ( utils . exists ( 'custom.js' ) ) . toEqual ( true )
40+ } )
4741 } )
4842 } )
4943 } )
@@ -62,9 +56,10 @@ describe('cli', () => {
6256 } )
6357
6458 it ( 'creates compiled CSS file' , ( ) => {
65- return cli ( [ 'build' , inputCssPath , '--output' , 'output.css' ] ) . then ( ( ) => {
66- expect ( utils . writeFile . mock . calls [ 0 ] [ 0 ] ) . toEqual ( 'output.css' )
67- expect ( utils . writeFile . mock . calls [ 0 ] [ 1 ] ) . toContain ( '.example' )
59+ return runInTempDirectory ( ( ) => {
60+ return cli ( [ 'build' , inputCssPath , '--output' , 'output.css' ] ) . then ( ( ) => {
61+ expect ( utils . readFile ( 'output.css' ) ) . toContain ( '.example' )
62+ } )
6863 } )
6964 } )
7065
0 commit comments