mirror of
https://github.com/dorny/test-reporter.git
synced 2025-12-15 22:07:09 +01:00
#83 - Use non-capturing optional group, add tests and update dist
This commit is contained in:
parent
c0e7f7f7dc
commit
3a0bb833dc
4 changed files with 40 additions and 5 deletions
37
__tests__/utils/parse-utils.test.ts
Normal file
37
__tests__/utils/parse-utils.test.ts
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
import {parseNetDuration} from '../../src/utils/parse-utils'
|
||||
|
||||
describe('parseNetDuration', () => {
|
||||
it('returns 0 for 00:00:00', () => {
|
||||
const ms = parseNetDuration('00:00:00')
|
||||
expect(ms).toBe(0)
|
||||
})
|
||||
|
||||
it('returns 0 for 00:00:00.0000000', () => {
|
||||
const ms = parseNetDuration('00:00:00.0000000')
|
||||
expect(ms).toBe(0)
|
||||
})
|
||||
|
||||
it('returns 123 for 00:00:00.123', () => {
|
||||
const ms = parseNetDuration('00:00:00.123')
|
||||
expect(ms).toBe(123)
|
||||
})
|
||||
|
||||
it('returns 12 * 1000 for 00:00:12', () => {
|
||||
const ms = parseNetDuration('00:00:12')
|
||||
expect(ms).toBe(12 * 1000)
|
||||
})
|
||||
|
||||
it('returns 12 * 60 * 1000 for 00:12:00', () => {
|
||||
const ms = parseNetDuration('00:12:00')
|
||||
expect(ms).toBe(12 * 60 * 1000)
|
||||
})
|
||||
|
||||
it('returns 12 * 60 * 60 * 1000 for 12:00:00', () => {
|
||||
const ms = parseNetDuration('12:00:00')
|
||||
expect(ms).toBe(12 * 60 * 60 * 1000)
|
||||
})
|
||||
|
||||
it('throws when string has invalid format', () => {
|
||||
expect(() => parseNetDuration('12:34:56 not a duration')).toThrowError(/^Invalid format/)
|
||||
})
|
||||
})
|
||||
3
dist/index.js
generated
vendored
3
dist/index.js
generated
vendored
|
|
@ -1799,8 +1799,7 @@ exports.formatTime = formatTime;
|
|||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||
exports.parseIsoDate = exports.parseNetDuration = void 0;
|
||||
function parseNetDuration(str) {
|
||||
// matches dotnet duration: 00:00:00.0010000
|
||||
const durationRe = /^(\d\d):(\d\d):(\d\d\.\d+)$/;
|
||||
const durationRe = /^(\d\d):(\d\d):(\d\d(?:\.\d+)?)$/;
|
||||
const durationMatch = str.match(durationRe);
|
||||
if (durationMatch === null) {
|
||||
throw new Error(`Invalid format: "${str}" is not NET duration`);
|
||||
|
|
|
|||
2
dist/index.js.map
generated
vendored
2
dist/index.js.map
generated
vendored
File diff suppressed because one or more lines are too long
|
|
@ -1,6 +1,5 @@
|
|||
export function parseNetDuration(str: string): number {
|
||||
// matches dotnet duration: 00:00:00.0010000
|
||||
const durationRe = /^(\d\d):(\d\d):(\d\d($|\.\d+$))/
|
||||
const durationRe = /^(\d\d):(\d\d):(\d\d(?:\.\d+)?)$/
|
||||
const durationMatch = str.match(durationRe)
|
||||
if (durationMatch === null) {
|
||||
throw new Error(`Invalid format: "${str}" is not NET duration`)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue