-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add L0 tests for new gradle5.x option (#14636)
Co-authored-by: Anatoly Bolshakov <[email protected]>
- Loading branch information
1 parent
8151391
commit 3166447
Showing
4 changed files
with
218 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import * as ma from 'azure-pipelines-task-lib/mock-answer'; | ||
import * as tmrm from 'azure-pipelines-task-lib/mock-run'; | ||
import path = require('path'); | ||
|
||
import * as fs from 'fs'; | ||
|
||
let taskPath = path.join(__dirname, '..', 'gradletask.js'); | ||
let tr: tmrm.TaskMockRunner = new tmrm.TaskMockRunner(taskPath); | ||
|
||
tr.setInput('wrapperScript', 'gradlew'); | ||
tr.setInput('cwd', '/home/repo/src'); | ||
tr.setInput('javaHomeSelection', 'JDKVersion'); | ||
tr.setInput('jdkVersion', 'default'); | ||
tr.setInput('testResultsFiles', '**/build/test-results/TEST-*.xml'); | ||
tr.setInput('codeCoverageTool', 'jacoco'); | ||
tr.setInput('failIfCoverageEmpty', 'false'); | ||
tr.setInput('gradle5xOrHigher', 'false'); | ||
|
||
tr.setInput('tasks', 'build'); | ||
|
||
let a: ma.TaskLibAnswers = <ma.TaskLibAnswers>{ | ||
'checkPath': { | ||
'gradlew': true, | ||
'gradlew.bat': true, | ||
'/home/repo/src': true | ||
}, | ||
'exec': { | ||
'gradlew.bat properties': { | ||
'code': 0, | ||
'stdout': 'More sample gradle output' | ||
}, | ||
'gradlew properties': { | ||
'code': 0, | ||
'stdout': 'More sample gradle output' | ||
}, | ||
'gradlew.bat clean build jacocoTestReport': { | ||
'code': 0, | ||
'stdout': 'More sample gradle output' | ||
}, | ||
'gradlew clean build jacocoTestReport': { | ||
'code': 0, | ||
'stdout': 'More sample gradle output' | ||
} | ||
}, | ||
'rmRF': { | ||
[path.join('/home/repo/src', 'CCReport43F6D5EF')]: { | ||
success: true | ||
} | ||
}, | ||
'stats': { | ||
[path.join('/home/repo/src', 'build.gradle')]: { | ||
isFile() { | ||
return true; | ||
} | ||
} | ||
}, | ||
'exist': { | ||
[path.join('/home/repo/src', 'CCReport43F6D5EF/summary.xml')]: true | ||
} | ||
}; | ||
tr.setAnswers(a); | ||
|
||
const fsClone = Object.assign({}, fs); | ||
Object.assign(fsClone, { | ||
// If gradle version is 5.x or higher, codecoverage-common package should try to insert assignment in this form: | ||
// classDirectories.setFrom files() | ||
// Copare this to how assignments look in gradle 4.x or lower: | ||
// classDirectories = files() | ||
// Since we're checking for gradle 4.x and lower here, we'll look for the latter one | ||
appendFileSync(filePath: string, data: string) { | ||
if (path.join('/home/repo/src', 'build.gradle') === filePath) { | ||
if (data.includes('classDirectories = file')) { | ||
console.log('Code coverage package is appending correct data (gradle 4.x and lower)'); | ||
} else { | ||
throw new Error(`Code coverage package tried to append incorrect data: ${data}`); | ||
} | ||
} | ||
} | ||
}); | ||
tr.registerMock('fs', fsClone); | ||
|
||
tr.run(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import * as ma from 'azure-pipelines-task-lib/mock-answer'; | ||
import * as tmrm from 'azure-pipelines-task-lib/mock-run'; | ||
import path = require('path'); | ||
|
||
import * as fs from 'fs'; | ||
|
||
let taskPath = path.join(__dirname, '..', 'gradletask.js'); | ||
let tr: tmrm.TaskMockRunner = new tmrm.TaskMockRunner(taskPath); | ||
|
||
tr.setInput('wrapperScript', 'gradlew'); | ||
tr.setInput('cwd', '/home/repo/src'); | ||
tr.setInput('javaHomeSelection', 'JDKVersion'); | ||
tr.setInput('jdkVersion', 'default'); | ||
tr.setInput('testResultsFiles', '**/build/test-results/TEST-*.xml'); | ||
tr.setInput('codeCoverageTool', 'jacoco'); | ||
tr.setInput('failIfCoverageEmpty', 'false'); | ||
tr.setInput('gradle5xOrHigher', 'true'); | ||
|
||
tr.setInput('tasks', 'build'); | ||
|
||
let a: ma.TaskLibAnswers = <ma.TaskLibAnswers>{ | ||
'checkPath': { | ||
'gradlew': true, | ||
'gradlew.bat': true, | ||
'/home/repo/src': true | ||
}, | ||
'exec': { | ||
'gradlew.bat properties': { | ||
'code': 0, | ||
'stdout': 'More sample gradle output' | ||
}, | ||
'gradlew properties': { | ||
'code': 0, | ||
'stdout': 'More sample gradle output' | ||
}, | ||
'gradlew.bat clean build jacocoTestReport': { | ||
'code': 0, | ||
'stdout': 'More sample gradle output' | ||
}, | ||
'gradlew clean build jacocoTestReport': { | ||
'code': 0, | ||
'stdout': 'More sample gradle output' | ||
} | ||
}, | ||
'rmRF': { | ||
[path.join('/home/repo/src', 'CCReport43F6D5EF')]: { | ||
success: true | ||
} | ||
}, | ||
'stats': { | ||
[path.join('/home/repo/src', 'build.gradle')]: { | ||
isFile() { | ||
return true; | ||
} | ||
} | ||
}, | ||
'exist': { | ||
[path.join('/home/repo/src', 'CCReport43F6D5EF/summary.xml')]: true | ||
} | ||
}; | ||
tr.setAnswers(a); | ||
|
||
const fsClone = Object.assign({}, fs); | ||
Object.assign(fsClone, { | ||
// If gradle version is 5.x or higher, codecoverage-common package should try to insert assignment in this form: | ||
// classDirectories.setFrom files() | ||
// Copare this to how assignments look in gradle 4.x or lower: | ||
// classDirectories = files() | ||
// Since we're checking for gradle 5.x and higher here, we'll look for the former one | ||
appendFileSync(filePath: string, data: string) { | ||
if (path.join('/home/repo/src', 'build.gradle') === filePath) { | ||
if (data.includes('classDirectories.setFrom file')) { | ||
console.log('Code coverage package is appending correct data (gradle 5.x and higher)'); | ||
} else { | ||
throw new Error(`Code coverage package tried to append incorrect data: ${data}`); | ||
} | ||
} | ||
} | ||
}); | ||
tr.registerMock('fs', fsClone); | ||
|
||
tr.run(); |