1+ import ma = require( 'azure-pipelines-task-lib/mock-answer' ) ;
2+ import tmrm = require( 'azure-pipelines-task-lib/mock-run' ) ;
3+ import path = require( 'path' ) ;
4+ import fs = require( 'fs' ) ;
5+ import assert = require( 'assert' ) ;
6+
7+ let taskPath = path . join ( __dirname , '..' , 'dotnetcore.js' ) ;
8+ let tmr : tmrm . TaskMockRunner = new tmrm . TaskMockRunner ( taskPath ) ;
9+
10+ tmr . setInput ( 'command' , "publish" ) ;
11+ tmr . setInput ( 'projects' , "web/project.json" ) ;
12+ tmr . setInput ( 'publishWebProjects' , "false" ) ;
13+ tmr . setInput ( 'arguments' , "--configuration release --output /usr/out" ) ;
14+ tmr . setInput ( 'zipAfterPublish' , "true" ) ;
15+ tmr . setInput ( 'modifyOutputPath' , "false" ) ;
16+
17+ // Mock file system operations for testing zip functionality
18+ const mockFs = {
19+ createWriteStream : function ( filePath ) {
20+ console . log ( "Creating write stream for: " + filePath ) ;
21+ const events = { } ;
22+ return {
23+ on : ( event , callback ) => {
24+ events [ event ] = callback ;
25+ return this ;
26+ } ,
27+ end : ( ) => {
28+ console . log ( "Closing write stream for: " + filePath ) ;
29+ events [ 'close' ] ( ) ;
30+ }
31+ } ;
32+ } ,
33+ mkdirSync : function ( p ) {
34+ console . log ( "Creating directory: " + p ) ;
35+ } ,
36+ renameSync : function ( oldPath , newPath ) {
37+ console . log ( "Moving file from: " + oldPath + " to: " + newPath ) ;
38+ } ,
39+ existsSync : function ( filePath ) {
40+ return true ;
41+ } ,
42+ readFileSync : function ( ) {
43+ return "" ;
44+ } ,
45+ statSync : function ( ) {
46+ return {
47+ isFile : ( ) => false ,
48+ isDirectory : ( ) => true
49+ } ;
50+ } ,
51+ lstatSync : function ( ) {
52+ return {
53+ isDirectory : ( ) => true
54+ } ;
55+ }
56+ } ;
57+
58+ // Mock archiver
59+ const mockArchiver = function ( ) {
60+ return {
61+ pipe : function ( ) { return this ; } ,
62+ directory : function ( ) { return this ; } ,
63+ finalize : function ( ) { return this ; }
64+ } ;
65+ } ;
66+
67+ let a : ma . TaskLibAnswers = < ma . TaskLibAnswers > {
68+ "which" : { "dotnet" : "dotnet" } ,
69+ "checkPath" : { "dotnet" : true } ,
70+ "exist" : {
71+ "/usr/out" : true
72+ } ,
73+ "exec" : {
74+ "dotnet publish web/project.json --configuration release --output /usr/out" : {
75+ "code" : 0 ,
76+ "stdout" : "published web without adding project name to path\n" ,
77+ "stderr" : ""
78+ }
79+ } ,
80+ "findMatch" : {
81+ "web/project.json" : [ "web/project.json" ]
82+ } ,
83+ "rmRF" : {
84+ "/usr/out" : {
85+ "success" : true
86+ }
87+ }
88+ } ;
89+
90+ tmr . setAnswers ( a ) ;
91+ tmr . registerMock ( 'fs' , Object . assign ( { } , fs , mockFs ) ) ;
92+ tmr . registerMock ( 'archiver' , mockArchiver ) ;
93+ tmr . registerMock ( 'azure-pipelines-task-lib/toolrunner' , require ( 'azure-pipelines-task-lib/mock-toolrunner' ) ) ;
94+
95+ tmr . run ( ) ;
0 commit comments