@@ -3,7 +3,7 @@ namespace ts {
3
3
export namespace Sample1 {
4
4
tick ( ) ;
5
5
const projFs = loadProjectFromDisk ( "tests/projects/sample1" ) ;
6
-
6
+ const sample1ProjectOutput = loadOutputProjectFromDisk ( "sample1" ) ;
7
7
const allExpectedOutputs = [ "/src/tests/index.js" ,
8
8
"/src/core/index.js" , "/src/core/index.d.ts" , "/src/core/index.d.ts.map" ,
9
9
"/src/logic/index.js" , "/src/logic/index.js.map" , "/src/logic/index.d.ts" ] ;
@@ -17,11 +17,34 @@ namespace ts {
17
17
host . clearDiagnostics ( ) ;
18
18
builder . buildAllProjects ( ) ;
19
19
host . assertDiagnosticMessages ( /*empty*/ ) ;
20
+ // Check for outputs
21
+ verifyOutputsFs ( fs , sample1ProjectOutput , "/src" ) ;
22
+ } ) ;
20
23
21
- // Check for outputs. Not an exhaustive list
22
- for ( const output of allExpectedOutputs ) {
23
- assert ( fs . existsSync ( output ) , `Expect file ${ output } to exist` ) ;
24
- }
24
+ it ( "builds correctly when outDir is specified" , ( ) => {
25
+ const fs = projFs . shadow ( ) ;
26
+ fs . writeFileSync ( "/src/logic/tsconfig.json" , JSON . stringify ( {
27
+ compilerOptions : { composite : true , declaration : true , outDir : "outDir" } ,
28
+ references : [ { path : "../core" } ]
29
+ } ) ) ;
30
+ const host = new fakes . SolutionBuilderHost ( fs ) ;
31
+ const builder = createSolutionBuilder ( host , [ "/src/tests" ] , { } ) ;
32
+ builder . buildAllProjects ( ) ;
33
+ host . assertDiagnosticMessages ( /*empty*/ ) ;
34
+ verifyOutputs ( fs , "sample1WithLogicOutDir" ) ;
35
+ } ) ;
36
+
37
+ it ( "builds correctly when declarationDir is specified" , ( ) => {
38
+ const fs = projFs . shadow ( ) ;
39
+ fs . writeFileSync ( "/src/logic/tsconfig.json" , JSON . stringify ( {
40
+ compilerOptions : { composite : true , declaration : true , declarationDir : "out/decls" } ,
41
+ references : [ { path : "../core" } ]
42
+ } ) ) ;
43
+ const host = new fakes . SolutionBuilderHost ( fs ) ;
44
+ const builder = createSolutionBuilder ( host , [ "/src/tests" ] , { } ) ;
45
+ builder . buildAllProjects ( ) ;
46
+ host . assertDiagnosticMessages ( /*empty*/ ) ;
47
+ verifyOutputs ( fs , "sample1WithLogicDeclarationDir" ) ;
25
48
} ) ;
26
49
} ) ;
27
50
@@ -34,9 +57,7 @@ namespace ts {
34
57
host . assertDiagnosticMessages ( Diagnostics . A_non_dry_build_would_build_project_0 , Diagnostics . A_non_dry_build_would_build_project_0 , Diagnostics . A_non_dry_build_would_build_project_0 ) ;
35
58
36
59
// Check for outputs to not be written. Not an exhaustive list
37
- for ( const output of allExpectedOutputs ) {
38
- assert ( ! fs . existsSync ( output ) , `Expect file ${ output } to not exist` ) ;
39
- }
60
+ verifyOutputsNotExistOnFs ( fs , sample1ProjectOutput , "/src" ) ;
40
61
} ) ;
41
62
42
63
it ( "indicates that it would skip builds during a dry build" , ( ) => {
@@ -62,14 +83,10 @@ namespace ts {
62
83
const builder = createSolutionBuilder ( host , [ "/src/tests" ] , { dry : false , force : false , verbose : false } ) ;
63
84
builder . buildAllProjects ( ) ;
64
85
// Verify they exist
65
- for ( const output of allExpectedOutputs ) {
66
- assert ( fs . existsSync ( output ) , `Expect file ${ output } to exist` ) ;
67
- }
86
+ verifyOutputsFs ( fs , sample1ProjectOutput , "/src" ) ;
68
87
builder . cleanAllProjects ( ) ;
69
88
// Verify they are gone
70
- for ( const output of allExpectedOutputs ) {
71
- assert ( ! fs . existsSync ( output ) , `Expect file ${ output } to not exist` ) ;
72
- }
89
+ verifyOutputsNotExistOnFs ( fs , sample1ProjectOutput , "/src" ) ;
73
90
// Subsequent clean shouldn't throw / etc
74
91
builder . cleanAllProjects ( ) ;
75
92
} ) ;
@@ -529,4 +546,50 @@ export class cNew {}`);
529
546
fs . makeReadonly ( ) ;
530
547
return fs ;
531
548
}
549
+
550
+ function loadOutputProjectFromDisk ( project : string ) : vfs . FileSystem {
551
+ const resolver = vfs . createResolver ( Harness . IO ) ;
552
+ const fs = new vfs . FileSystem ( /*ignoreCase*/ true , {
553
+ files : {
554
+ [ "/src" ] : new vfs . Mount ( vpath . resolve ( Harness . IO . getWorkspaceRoot ( ) , `tests/baselines/reference/projects/${ project } ` ) , resolver )
555
+ } ,
556
+ cwd : "/" ,
557
+ time,
558
+ } ) ;
559
+ fs . makeReadonly ( ) ;
560
+ return fs ;
561
+ }
562
+
563
+ function verifyOutputs ( buildFs : vfs . FileSystem , expectedOutputProject : string ) {
564
+ const fs = loadOutputProjectFromDisk ( expectedOutputProject ) ;
565
+ verifyOutputsFs ( buildFs , fs , "/src" ) ;
566
+ }
567
+
568
+ function verifyOutputsFs ( buildFs : vfs . FileSystem , expectedOutputFs : vfs . FileSystem , directory : string ) {
569
+ withOutputFs ( expectedOutputFs , directory , outputFile => {
570
+ const actual = buildFs . readFileSync ( outputFile , "utf8" ) ;
571
+ const expected = expectedOutputFs . readFileSync ( outputFile , "utf8" ) ;
572
+ assert . equal ( actual , expected , `File contents of ${ outputFile } expected to be:
573
+ actual: ${ actual }
574
+ expected: ${ expected } ` ) ;
575
+ } ) ;
576
+ }
577
+
578
+ function verifyOutputsNotExistOnFs ( buildFs : vfs . FileSystem , expectedOutputFs : vfs . FileSystem , directory : string ) {
579
+ withOutputFs ( expectedOutputFs , directory , outputFile =>
580
+ assert ( ! buildFs . existsSync ( outputFile ) , `Expect file ${ outputFile } to not exist` ) ) ;
581
+ }
582
+
583
+ function withOutputFs ( expectedOutputFs : vfs . FileSystem , directory : string , actionOnFile : ( outputFile : string ) => void ) {
584
+ const children = expectedOutputFs . readdirSync ( directory ) ;
585
+ for ( const child of children ) {
586
+ const fullName = `${ directory } /${ child } ` ;
587
+ if ( expectedOutputFs . statSync ( fullName ) . isFile ( ) ) {
588
+ actionOnFile ( fullName ) ;
589
+ }
590
+ else {
591
+ withOutputFs ( expectedOutputFs , fullName , actionOnFile ) ;
592
+ }
593
+ }
594
+ }
532
595
}
0 commit comments