@@ -18,22 +18,14 @@ describe('addon generator', () => {
1818 // we call this unwanted path doubleGenPath
1919 const doubleGenPath = path . join ( genPath , genName ) ;
2020
21- beforeAll ( ( ) => {
22- rimraf . sync ( testAssetsPath ) ;
23- fs . mkdirSync ( genPath , { recursive : true } ) ;
24- // set the working directory to here so that the addon directory is
25- // generated in ./test-assets/test-addon
26- process . chdir ( genPath ) ;
27- packageMock = getPackageManager as jest . Mock ;
28- } ) ;
29-
3021 afterAll ( ( ) => {
3122 rimraf . sync ( testAssetsPath ) ;
3223 } ) ;
3324
3425 beforeEach ( ( ) => {
3526 // eslint-disable-next-line @typescript-eslint/no-empty-function
3627 const Gen = addonGenerator ( [ ] , '' , [ ] , [ ] , ( ) => { } ) ;
28+
3729 gen = new Gen ( null , null ) ;
3830 gen . props = {
3931 name : genName ,
@@ -43,9 +35,20 @@ describe('addon generator', () => {
4335 } ) ;
4436
4537 it ( 'schedules install using npm' , ( ) => {
38+ const defaultCwd = process . cwd ( ) ;
39+
40+ rimraf . sync ( testAssetsPath ) ;
41+ fs . mkdirSync ( genPath , { recursive : true } ) ;
42+
43+ // set the working directory to here so that the addon directory is
44+ // generated in ./test-assets/test-addon
45+ process . chdir ( genPath ) ;
46+
47+ packageMock = getPackageManager as jest . Mock ;
4648 packageMock . mockReturnValue ( 'npm' ) ;
4749
4850 gen . install ( ) ;
51+
4952 expect ( installMock . mock . calls . length ) . toEqual ( 1 ) ;
5053 expect ( installMock . mock . calls [ 0 ] ) . toEqual ( [
5154 'npm' ,
@@ -54,12 +57,24 @@ describe('addon generator', () => {
5457 'save-dev' : true ,
5558 } ,
5659 ] ) ;
60+
61+ process . chdir ( defaultCwd ) ;
5762 } ) ;
5863
5964 it ( 'schedules install using yarn' , ( ) => {
65+ const defaultCwd = process . cwd ( ) ;
66+
67+ rimraf . sync ( testAssetsPath ) ;
68+ fs . mkdirSync ( genPath , { recursive : true } ) ;
69+ // set the working directory to here so that the addon directory is
70+ // generated in ./test-assets/test-addon
71+ process . chdir ( genPath ) ;
72+
73+ packageMock = getPackageManager as jest . Mock ;
6074 packageMock . mockReturnValue ( 'yarn' ) ;
6175
6276 gen . install ( ) ;
77+
6378 expect ( installMock . mock . calls . length ) . toEqual ( 1 ) ;
6479 expect ( installMock . mock . calls [ 0 ] ) . toEqual ( [
6580 'yarn' ,
@@ -68,11 +83,26 @@ describe('addon generator', () => {
6883 dev : true ,
6984 } ,
7085 ] ) ;
86+
87+ process . chdir ( defaultCwd ) ;
7188 } ) ;
7289
7390 it ( 'does not create new directory when current directory matches addon name' , ( ) => {
91+ const defaultCwd = process . cwd ( ) ;
92+
93+ rimraf . sync ( testAssetsPath ) ;
94+ fs . mkdirSync ( genPath , { recursive : true } ) ;
95+
96+ // set the working directory to here so that the addon directory is
97+ // generated in ./test-assets/test-addon
98+ process . chdir ( genPath ) ;
99+
100+ packageMock = getPackageManager as jest . Mock ;
101+
74102 expect ( fs . existsSync ( genPath ) ) . toBeTruthy ( ) ;
103+
75104 gen . default ( ) ;
105+
76106 expect ( fs . existsSync ( genPath ) ) . toBeTruthy ( ) ;
77107 expect ( fs . existsSync ( doubleGenPath ) ) . toBeFalsy ( ) ;
78108
@@ -81,14 +111,26 @@ describe('addon generator', () => {
81111 // generator above
82112 // this is switching the working directory as follows:
83113 // ./test-assets/test-addon -> ./test-assets
84- process . chdir ( testAssetsPath ) ;
85114 rimraf . sync ( genPath ) ;
115+
116+ process . chdir ( defaultCwd ) ;
86117 } ) ;
87118
88119 it ( 'creates a new directory for the generated addon' , ( ) => {
89- expect ( fs . existsSync ( genPath ) ) . toBeFalsy ( ) ;
120+ const defaultCwd = process . cwd ( ) ;
121+
122+ rimraf . sync ( testAssetsPath ) ;
123+ fs . mkdirSync ( genPath , { recursive : true } ) ;
124+
125+ // set the working directory to here so that the addon directory is
126+ // generated in ./test-assets/test-addon
127+ process . chdir ( genPath ) ;
128+
90129 gen . default ( ) ;
130+
91131 expect ( fs . existsSync ( genPath ) ) . toBeTruthy ( ) ;
92132 expect ( fs . existsSync ( doubleGenPath ) ) . toBeFalsy ( ) ;
133+
134+ process . chdir ( defaultCwd ) ;
93135 } ) ;
94136} ) ;
0 commit comments