@@ -11,32 +11,31 @@ public class CopyFromNPMTests
11
11
public async Task NodeModulesAreTranslated ( )
12
12
{
13
13
//arrange
14
- var context = new TestExecutionContext ( ) ;
15
- context . FileSystem . GetInputFile ( "/node_modules/x/1.js" ) . OpenWrite ( ) ;
16
- context . FileSystem . GetInputFile ( "/node_modules/y/2.js" ) . OpenWrite ( ) ;
14
+ var context = new TestExecutionContext { FileSystem = { RootPath = "/code/app" } } ;
15
+ context . FileSystem . GetInputFile ( "/code/app/ node_modules/x/1.js" ) . OpenWrite ( ) ;
16
+ context . FileSystem . GetInputFile ( "/code/app/ node_modules/y/2.js" ) . OpenWrite ( ) ;
17
17
18
18
var pipeline = new CopyFromNPM ( new [ ] { "x/1.js" , "y/2.js" } , "assets/js" ) ;
19
- var input = pipeline . InputModules . Where ( m => m is ReadFiles ) ;
19
+ var input = pipeline . InputModules . First ( m => m is ReadFiles ) ;
20
20
21
21
//act
22
- var tasks = input . Select ( async i => await i . ExecuteAsync ( context ) ) ;
23
- var output = await Task . WhenAll ( tasks ) ;
22
+ var output = await input . ExecuteAsync ( context ) ;
24
23
25
24
//assert
26
- var files = output . SelectMany ( d => d ) . Select ( d => d . Source . FileName . ToString ( ) ) . ToArray ( ) ;
25
+ var files = output . Select ( d => d . Source . FileName . ToString ( ) ) . ToArray ( ) ;
27
26
Assert . Equal ( 2 , files . Length ) ;
28
27
Assert . Contains ( "1.js" , files ) ;
29
28
Assert . Contains ( "2.js" , files ) ;
30
29
}
31
30
32
31
[ Fact ]
33
- public async Task CopyToFlattensOutputPathForFiles ( )
32
+ public async Task CopyToFlattensOutputByDefault ( )
34
33
{
35
34
//arrange
36
35
var docs = new List < IDocument >
37
36
{
38
- new TestDocument ( new NormalizedPath ( "/node_modules/x/1.js" ) ) ,
39
- new TestDocument ( new NormalizedPath ( "/node_modules/y/2.js" ) )
37
+ new TestDocument ( new NormalizedPath ( "/code/app/ node_modules/x/1.js" ) ) ,
38
+ new TestDocument ( new NormalizedPath ( "/code/app/ node_modules/y/2.js" ) )
40
39
} ;
41
40
var context = new TestExecutionContext ( ) ;
42
41
context . SetInputs ( docs ) ;
@@ -54,26 +53,88 @@ public async Task CopyToFlattensOutputPathForFiles()
54
53
}
55
54
56
55
[ Fact ]
57
- public async Task CopyToDoesNotFlattenOutputPathForDirectories ( )
56
+ public async Task CopyToFlattensOutputForEmptyValues ( )
57
+ {
58
+ //arrange
59
+ var docs = new List < IDocument >
60
+ {
61
+ new TestDocument ( new NormalizedPath ( "/code/app/node_modules/x/1.js" ) ) ,
62
+ new TestDocument ( new NormalizedPath ( "/code/app/node_modules/y/2.js" ) )
63
+ } ;
64
+ var context = new TestExecutionContext ( ) ;
65
+ context . SetInputs ( docs ) ;
66
+
67
+ var files = new Dictionary < string , string >
68
+ {
69
+ { "x/1.js" , "" } ,
70
+ { "y/2.js" , " " }
71
+ } ;
72
+ var pipeline = new CopyFromNPM ( files , "assets/js" ) ;
73
+ var copy = pipeline . ProcessModules . First ( m => m is SetDestination ) ;
74
+
75
+ //act
76
+ var output = await copy . ExecuteAsync ( context ) ;
77
+
78
+ //assert
79
+ var outputDocs = output . ToArray ( ) ;
80
+ Assert . Equal ( "assets/js/1.js" , outputDocs [ 0 ] . Destination ) ;
81
+ Assert . Equal ( "assets/js/2.js" , outputDocs [ 1 ] . Destination ) ;
82
+ }
83
+
84
+ [ Fact ]
85
+ public async Task CopyToUsesSpecifiedValues ( )
86
+ {
87
+ //arrange
88
+ var docs = new List < IDocument >
89
+ {
90
+ new TestDocument ( new NormalizedPath ( "/code/app/node_modules/x/y/1.js" ) ) ,
91
+ new TestDocument ( new NormalizedPath ( "/code/app/node_modules/x/y/z/2.js" ) )
92
+ } ;
93
+ var context = new TestExecutionContext ( ) ;
94
+ context . SetInputs ( docs ) ;
95
+
96
+ var files = new Dictionary < string , string >
97
+ {
98
+ { "x/y/1.js" , "y/1.js" } ,
99
+ { "x/y/z/2.js" , "y/z/2.js" }
100
+ } ;
101
+ var pipeline = new CopyFromNPM ( files , "assets/js" ) ;
102
+ var copy = pipeline . ProcessModules . First ( m => m is SetDestination ) ;
103
+
104
+ //act
105
+ var output = await copy . ExecuteAsync ( context ) ;
106
+
107
+ //assert
108
+ var outputDocs = output . ToArray ( ) ;
109
+ Assert . Equal ( "assets/js/y/1.js" , outputDocs [ 0 ] . Destination ) ;
110
+ Assert . Equal ( "assets/js/y/z/2.js" , outputDocs [ 1 ] . Destination ) ;
111
+ }
112
+
113
+ [ Fact ]
114
+ public async Task CanCopyToOutputUsingWildcardKeys ( )
58
115
{
59
116
//arrange
60
117
var docs = new List < IDocument >
61
118
{
62
- new TestDocument ( new NormalizedPath ( "/node_modules/x/1.js" ) ) ,
63
- new TestDocument ( new NormalizedPath ( "/node_modules/x/y /2.js" ) )
119
+ new TestDocument ( new NormalizedPath ( "/code/app/ node_modules/x/1.js" ) ) ,
120
+ new TestDocument ( new NormalizedPath ( "/code/app/ node_modules/x/2.js" ) )
64
121
} ;
65
122
var context = new TestExecutionContext ( ) ;
66
123
context . SetInputs ( docs ) ;
67
124
68
- var pipeline = new CopyFromNPM ( new [ ] { "x" } , "assets/js" ) ;
125
+ var files = new Dictionary < string , string >
126
+ {
127
+ { "x/*" , "y" }
128
+ } ;
129
+ var pipeline = new CopyFromNPM ( files , "assets/js" ) ;
69
130
var copy = pipeline . ProcessModules . First ( m => m is SetDestination ) ;
70
131
71
132
//act
72
133
var output = await copy . ExecuteAsync ( context ) ;
73
134
74
135
//assert
75
136
var outputDocs = output . ToArray ( ) ;
76
- Assert . Equal ( "assets/js/x /1.js" , outputDocs [ 0 ] . Destination ) ;
77
- Assert . Equal ( "assets/js/x/ y/2.js" , outputDocs [ 1 ] . Destination ) ;
137
+ Assert . Equal ( "assets/js/y /1.js" , outputDocs [ 0 ] . Destination ) ;
138
+ Assert . Equal ( "assets/js/y/2.js" , outputDocs [ 1 ] . Destination ) ;
78
139
}
79
140
}
0 commit comments