@@ -15,6 +15,8 @@ import cacache from 'cacache';
1515import isGzip from 'is-gzip' ;
1616import zlib from 'zlib' ;
1717
18+ import removeIllegalCharacterForWindows from './utils/removeIllegalCharacterForWindows' ;
19+
1820const BUILD_DIR = path . join ( __dirname , 'build' ) ;
1921const HELPER_DIR = path . join ( __dirname , 'helpers' ) ;
2022const TEMP_DIR = path . join ( __dirname , 'tempdir' ) ;
@@ -58,6 +60,13 @@ describe('apply function', () => {
5860 // Ideally we pass in patterns and confirm the resulting assets
5961 const run = ( opts ) => {
6062 return new Promise ( ( resolve , reject ) => {
63+ if ( Array . isArray ( opts . patterns ) ) {
64+ opts . patterns . forEach ( function ( pattern ) {
65+ if ( pattern . context ) {
66+ pattern . context = removeIllegalCharacterForWindows ( pattern . context ) ;
67+ }
68+ } ) ;
69+ }
6170 const plugin = CopyWebpackPlugin ( opts . patterns , opts . options ) ;
6271
6372 // Get a mock compiler to pass to plugin.apply
@@ -109,7 +118,7 @@ describe('apply function', () => {
109118 return run ( opts )
110119 . then ( ( compilation ) => {
111120 if ( opts . expectedAssetKeys && opts . expectedAssetKeys . length > 0 ) {
112- expect ( compilation . assets ) . to . have . all . keys ( opts . expectedAssetKeys ) ;
121+ expect ( compilation . assets ) . to . have . all . keys ( opts . expectedAssetKeys . map ( removeIllegalCharacterForWindows ) ) ;
113122 } else {
114123 expect ( compilation . assets ) . to . deep . equal ( { } ) ;
115124 }
@@ -268,6 +277,7 @@ describe('apply function', () => {
268277 it ( 'can use a glob to move multiple files to the root directory' , ( done ) => {
269278 runEmit ( {
270279 expectedAssetKeys : [
280+ '[!]/hello.txt' ,
271281 'binextension.bin' ,
272282 'file.txt' ,
273283 'file.txt.gz' ,
@@ -289,6 +299,7 @@ describe('apply function', () => {
289299 it ( 'can use a glob to move multiple files to a non-root directory' , ( done ) => {
290300 runEmit ( {
291301 expectedAssetKeys : [
302+ 'nested/[!]/hello.txt' ,
292303 'nested/binextension.bin' ,
293304 'nested/file.txt' ,
294305 'nested/file.txt.gz' ,
@@ -405,6 +416,7 @@ describe('apply function', () => {
405416 it ( 'can use a glob with a full path to move multiple files to the root directory' , ( done ) => {
406417 runEmit ( {
407418 expectedAssetKeys : [
419+ '[!]/hello.txt' ,
408420 'file.txt' ,
409421 'directory/directoryfile.txt' ,
410422 'directory/nested/nestedfile.txt' ,
@@ -423,6 +435,7 @@ describe('apply function', () => {
423435 it ( 'can use a glob to move multiple files to a non-root directory with name, hash and ext' , ( done ) => {
424436 runEmit ( {
425437 expectedAssetKeys : [
438+ 'nested/[!]/hello-d41d8c.txt' ,
426439 'nested/binextension-d41d8c.bin' ,
427440 'nested/file-22af64.txt' ,
428441 'nested/file.txt-5b311c.gz' ,
@@ -445,13 +458,14 @@ describe('apply function', () => {
445458 it ( 'can flatten or normalize glob matches' , ( done ) => {
446459 runEmit ( {
447460 expectedAssetKeys : [
461+ '[!]-hello.txt' ,
448462 '[special?directory]-(special-*file).txt' ,
449463 '[special?directory]-directoryfile.txt' ,
450464 'directory-directoryfile.txt'
451465 ] ,
452466 patterns : [ {
453467 from : '*/*.*' ,
454- test : / ( [ ^ \/ ] + ) \/ ( [ ^ \/ ] + ) \. \ w+ $ / ,
468+ test : ` ([^\\ ${ path . sep } ]+)\\ ${ path . sep } ([^\\ ${ path . sep } ]+)\\.\\ w+$` ,
455469 to : '[1]-[2].[ext]'
456470 } ]
457471 } )
@@ -887,6 +901,7 @@ describe('apply function', () => {
887901 it ( 'ignores files in pattern' , ( done ) => {
888902 runEmit ( {
889903 expectedAssetKeys : [
904+ '[!]/hello.txt' ,
890905 'binextension.bin' ,
891906 'directory/directoryfile.txt' ,
892907 'directory/nested/nestedfile.txt' ,
@@ -984,7 +999,7 @@ describe('apply function', () => {
984999 'nested/nestedfile.txt'
9851000 ] ,
9861001 patterns : [ {
987- from : ' [special?directory]'
1002+ from : ( path . sep === '/' ? ' [special?directory]' : '[specialdirectory]' )
9881003 } ]
9891004 } )
9901005 . then ( done )
@@ -1324,6 +1339,7 @@ describe('apply function', () => {
13241339 it ( 'ignores files that start with a dot' , ( done ) => {
13251340 runEmit ( {
13261341 expectedAssetKeys : [
1342+ '[!]/hello.txt' ,
13271343 'binextension.bin' ,
13281344 'file.txt' ,
13291345 'file.txt.gz' ,
@@ -1384,13 +1400,14 @@ describe('apply function', () => {
13841400 it ( 'ignores nested directory' , ( done ) => {
13851401 runEmit ( {
13861402 expectedAssetKeys : [
1403+ '[!]/hello.txt' ,
13871404 'binextension.bin' ,
13881405 'file.txt' ,
13891406 'file.txt.gz' ,
13901407 'noextension'
13911408 ] ,
13921409 options : {
1393- ignore : [ 'directory/**/*' , '\\[ special\\? directory\\ ]/**/*' ]
1410+ ignore : [ 'directory/**/*' , `[[] special${ process . platform === 'win32' ? '' : '[?]' } directory]/**/*` ]
13941411 } ,
13951412 patterns : [ {
13961413 from : '.'
@@ -1401,6 +1418,29 @@ describe('apply function', () => {
14011418 . catch ( done ) ;
14021419 } ) ;
14031420
1421+ if ( path . sep === '/' ) {
1422+ it ( 'ignores nested directory(can use "\\" to escape if path.sep is "/")' , ( done ) => {
1423+ runEmit ( {
1424+ expectedAssetKeys : [
1425+ '[!]/hello.txt' ,
1426+ 'binextension.bin' ,
1427+ 'file.txt' ,
1428+ 'file.txt.gz' ,
1429+ 'noextension'
1430+ ] ,
1431+ options : {
1432+ ignore : [ 'directory/**/*' , '\\[special\\?directory\\]/**/*' ]
1433+ } ,
1434+ patterns : [ {
1435+ from : '.'
1436+ } ]
1437+
1438+ } )
1439+ . then ( done )
1440+ . catch ( done ) ;
1441+ } ) ;
1442+ }
1443+
14041444 it ( 'ignores nested directory (glob)' , ( done ) => {
14051445 runEmit ( {
14061446 expectedAssetKeys : [
0 commit comments