@@ -10,11 +10,13 @@ const firstPrompt = '? Loader name (my-loader)';
10
10
const ENTER = '\x0D' ;
11
11
const loaderName = 'test-loader' ;
12
12
const loaderPath = join ( __dirname , loaderName ) ;
13
+ const defaultLoaderPath = join ( __dirname , 'my-loader' ) ;
13
14
const genPath = join ( __dirname , 'test-assets' ) ;
14
15
const customLoaderPath = join ( genPath , loaderName ) ;
15
16
16
17
describe ( 'loader command' , ( ) => {
17
18
beforeEach ( ( ) => {
19
+ rimraf . sync ( defaultLoaderPath ) ;
18
20
rimraf . sync ( loaderPath ) ;
19
21
rimraf . sync ( genPath ) ;
20
22
} ) ;
@@ -26,6 +28,32 @@ describe('loader command', () => {
26
28
expect ( stripAnsi ( stdout ) ) . toContain ( firstPrompt ) ;
27
29
} ) ;
28
30
31
+ it ( 'should scaffold loader with default name if no loader name provided' , async ( ) => {
32
+ let { stdout } = await runPromptWithAnswers ( __dirname , [ 'loader' ] , [ `${ ENTER } ` ] ) ;
33
+
34
+ expect ( stripAnsi ( stdout ) ) . toContain ( firstPrompt ) ;
35
+
36
+ // Skip test in case installation fails
37
+ if ( ! existsSync ( resolve ( defaultLoaderPath , './yarn.lock' ) ) ) {
38
+ return ;
39
+ }
40
+
41
+ // Check if the output directory exists with the appropriate loader name
42
+ expect ( existsSync ( defaultLoaderPath ) ) . toBeTruthy ( ) ;
43
+
44
+ // All test files are scaffolded
45
+ const files = [ 'package.json' , 'examples' , 'src' , 'test' , 'src/index.js' , 'examples/simple/webpack.config.js' ] ;
46
+
47
+ files . forEach ( ( file ) => {
48
+ expect ( existsSync ( defaultLoaderPath , file ) ) . toBeTruthy ( ) ;
49
+ } ) ;
50
+
51
+ // Check if the the generated loader works successfully
52
+ const path = resolve ( __dirname , './my-loader/examples/simple/' ) ;
53
+ ( { stdout } = run ( path , [ ] , false ) ) ;
54
+ expect ( stdout ) . toContain ( 'my-loader' ) ;
55
+ } ) ;
56
+
29
57
it ( 'should scaffold loader template with a given name' , async ( ) => {
30
58
let { stdout } = await runPromptWithAnswers ( __dirname , [ 'loader' ] , [ `${ loaderName } ${ ENTER } ` ] ) ;
31
59
0 commit comments