@@ -31,6 +31,23 @@ const readOutputFile = function(webpackConfig, filePath) {
31
31
return fs . readFileSync ( fullPath , 'utf8' ) ;
32
32
} ;
33
33
34
+ const getMatchedFilename = function ( targetDirectory , filenameRegex ) {
35
+ const actualFiles = fs . readdirSync ( targetDirectory ) ;
36
+ let foundFile = false ;
37
+ actualFiles . forEach ( ( actualFile ) => {
38
+ // filter out directories
39
+ if ( fs . statSync ( path . join ( targetDirectory , actualFile ) ) . isDirectory ( ) ) {
40
+ return ;
41
+ }
42
+
43
+ if ( actualFile . match ( filenameRegex ) ) {
44
+ foundFile = actualFile ;
45
+ }
46
+ } ) ;
47
+
48
+ return foundFile ;
49
+ } ;
50
+
34
51
/**
35
52
* Returns a regex to use to match this filename
36
53
*
@@ -61,12 +78,17 @@ class Assert {
61
78
}
62
79
63
80
assertOutputFileContains ( filePath , expectedContents ) {
64
- const fullPath = path . join ( this . webpackConfig . outputPath , filePath ) ;
81
+ const actualFilename = getMatchedFilename (
82
+ this . webpackConfig . outputPath ,
83
+ convertFilenameToMatcher ( filePath )
84
+ ) ;
65
85
66
- if ( ! fs . existsSync ( fullPath ) ) {
86
+ if ( false === actualFilename ) {
67
87
throw new Error ( `Output file "${ filePath } " does not exist.` ) ;
68
88
}
69
89
90
+ const fullPath = path . join ( this . webpackConfig . outputPath , actualFilename ) ;
91
+
70
92
const actualContents = fs . readFileSync ( fullPath , 'utf8' ) ;
71
93
if ( ! actualContents . includes ( expectedContents ) ) {
72
94
throw new Error ( `Expected contents "${ expectedContents } " not found in file ${ fullPath } ` ) ;
0 commit comments