mirror of
https://github.com/dorny/test-reporter.git
synced 2025-12-17 06:47:09 +01:00
revert: getBasePath() logic to original
This commit is contained in:
parent
cdfbf90a4e
commit
3606ee2f36
2 changed files with 30 additions and 13 deletions
21
__tests__/utils/path-utils.test.ts
Normal file
21
__tests__/utils/path-utils.test.ts
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
import {getBasePath} from '../../src/utils/path-utils'
|
||||||
|
|
||||||
|
describe('getBasePath', () => {
|
||||||
|
it('tracked file in path', () => {
|
||||||
|
const path = 'C:/Users/Michal/Workspace/dorny/test-check/reports/jest/__tests__/main.test.js'
|
||||||
|
const trackedFiles = ['__tests__/main.test.js', '__tests__/second.test.js', 'lib/main.js']
|
||||||
|
|
||||||
|
const result = getBasePath(path, trackedFiles)
|
||||||
|
|
||||||
|
expect(result).toBe('C:/Users/Michal/Workspace/dorny/test-check/reports/jest/')
|
||||||
|
})
|
||||||
|
|
||||||
|
// it('tracked file contains part of the path', () => {
|
||||||
|
// const path = 'mnt/extra-addons/product_changes/tests/first_test.py'
|
||||||
|
// const trackedFiles = ['addons/product_changes/tests/first_test.py']
|
||||||
|
//
|
||||||
|
// const result = getBasePath(path, trackedFiles)
|
||||||
|
//
|
||||||
|
// expect(result).toBe('addons/product_changes/tests/first_test.py')
|
||||||
|
// })
|
||||||
|
})
|
||||||
|
|
@ -23,21 +23,17 @@ export function getBasePath(path: string, trackedFiles: string[]): string | unde
|
||||||
return ''
|
return ''
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let max = ''
|
||||||
for (const file of trackedFiles) {
|
for (const file of trackedFiles) {
|
||||||
const pathParts = path.split('/')
|
if (path.endsWith(file) && file.length > max.length) {
|
||||||
const originalLength = pathParts.length
|
max = file
|
||||||
const fileParts = file.split('/')
|
|
||||||
|
|
||||||
while (pathParts.length && pathParts.slice(-1)[0] === fileParts.slice(-1)[0]) {
|
|
||||||
pathParts.pop()
|
|
||||||
fileParts.pop()
|
|
||||||
}
|
|
||||||
|
|
||||||
// we found some matching path parts
|
|
||||||
if (pathParts.length !== originalLength) {
|
|
||||||
return pathParts.join('/')
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (max === '') {
|
||||||
return undefined
|
return undefined
|
||||||
|
}
|
||||||
|
|
||||||
|
const base = path.substr(0, path.length - max.length)
|
||||||
|
return base
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue