Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
describe('Composer version comparison', function() {
test(compare, () => {
// composer version scheme ordering
given('0.9.0', '1.0.0-alpha').expect(-1)
given('1.0.0-alpha', '1.0.0-alpha2').expect(-1)
given('1.0.0-alpha2', '1.0.0-beta').expect(-1)
given('1.0.0-beta', '1.0.0-beta2').expect(-1)
given('1.0.0-beta2', '1.0.0-RC').expect(-1)
given('1.0.0-B2', '1.0.0-RC').expect(-1)
given('1.0.0-RC', '1.0.0-RC2').expect(-1)
given('1.0.0-RC2', '1.0.0').expect(-1)
given('1.0.0-rc', '1.0.0').expect(-1)
given('1.0.0', '1.0.0-patch').expect(-1)
given('1.0.0-patch', '1.0.0-dev').expect(-1)
given('1.0.0-dev', '1.0.1').expect(-1)
given('1.0.1', '1.0.x-dev').expect(-1)
// short versions should compare equal to long versions
describe('Version helpers', function() {
test(latest, () => {
// semver-compatible versions.
given(['1.0.0', '1.0.2', '1.0.1']).expect('1.0.2')
given(['1.0.0', '2.0.0', '3.0.0']).expect('3.0.0')
given(['0.0.1', '0.0.10', '0.0.2', '0.0.20']).expect('0.0.20')
// "not-quite-valid" semver versions
given(['1.0.00', '1.0.02', '1.0.01']).expect('1.0.02')
given(['1.0.05', '2.0.05', '3.0.05']).expect('3.0.05')
given(['0.0.01', '0.0.010', '0.0.02', '0.0.020']).expect('0.0.020')
// Mixed style versions. - include pre-releases
given(['1.0.0', 'v1.0.2', 'r1.0.1', 'release-2.0.0', 'v1.0.1-alpha.1'], {
pre: includePre,
}).expect('release-2.0.0')
given(['1.0.0', 'v2.0.0', 'r1.0.1', 'release-1.0.3', 'v1.0.1-alpha.1'], {
pre: includePre,
describe('Version helpers', function() {
test(latest, () => {
// semver-compatible versions.
given(['1.0.0', '1.0.2', '1.0.1']).expect('1.0.2')
given(['1.0.0', '2.0.0', '3.0.0']).expect('3.0.0')
given(['0.0.1', '0.0.10', '0.0.2', '0.0.20']).expect('0.0.20')
// "not-quite-valid" semver versions
given(['1.0.00', '1.0.02', '1.0.01']).expect('1.0.02')
given(['1.0.05', '2.0.05', '3.0.05']).expect('3.0.05')
given(['0.0.01', '0.0.010', '0.0.02', '0.0.020']).expect('0.0.020')
// Mixed style versions. - include pre-releases
given(['1.0.0', 'v1.0.2', 'r1.0.1', 'release-2.0.0', 'v1.0.1-alpha.1'], {
pre: includePre,
}).expect('release-2.0.0')
given(['1.0.0', 'v2.0.0', 'r1.0.1', 'release-1.0.3', 'v1.0.1-alpha.1'], {
pre: includePre,
given('A').expect('brightgreen')
given('B').expect('green')
given('C').expect('yellowgreen')
given('D').expect('yellow')
given('E').expect('orange')
given('F').expect('red')
given('Z').expect('red')
})
const monthsAgo = months => {
const result = new Date()
// This looks wack but it works.
result.setMonth(result.getMonth() - months)
return result
}
test(age, () => {
given(Date.now())
.describe('when given the current timestamp')
.expect('brightgreen')
given(new Date())
.describe('when given the current Date')
.expect('brightgreen')
given(new Date(2001, 1, 1))
.describe('when given a Date many years ago')
.expect('red')
given(monthsAgo(2))
.describe('when given a Date two months ago')
.expect('yellowgreen')
given(monthsAgo(15))
.describe('when given a Date 15 months ago')
.expect('orange')
})
test(isDataUrl, () => {
//valid input
given('data:image/svg+xml;base64,PHN2ZyB4bWxu').expect(true)
// invalid inputs
forCases([given('data:foobar'), given('foobar')]).expect(false)
// attempted XSS attack
given(
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+P+/HgAFhAJ/wlseKgAAAABJRU5ErkJggg=="/>'
).expect(false)
})
describe('Services from PR title', function() {
test(servicesForTitle, () => {
given('[Travis] Fix timeout issues').expect(['travis'])
given('[Travis Sonar] Support user token authentication').expect([
'travis',
'sonar',
])
given('[CRAN CPAN CTAN] Add test coverage').expect(['cran', 'cpan', 'ctan'])
given(
'[RFC] Add Joi-based request validation to BaseJsonService and rewrite [NPM] badges'
).expect(['npm'])
given('make changes to [CRAN] and [CPAN]').expect(['cran', 'cpan'])
given('[github appveyor ]').expect(['github', 'appveyor'])
})
})
test(coalesce, function() {
given().expect(undefined)
given(null, []).expect([])
given(null, [], {}).expect([])
given(null, undefined, 0, {}).expect(0)
const a = null,
c = 0,
d = 1
let b
given(a, b, c, d).expect(0)
})
})
test(coalesce, function() {
given().expect(undefined)
given(null, []).expect([])
given(null, [], {}).expect([])
given(null, undefined, 0, {}).expect(0)
const a = null,
c = 0,
d = 1
let b
given(a, b, c, d).expect(0)
})
})
test(formatRelativeDate, () => {
given(new Date(2018, 9, 31).getTime() / 1000)
.describe('when given the end of october')
.expect('in 2 days')
})
test(formatDate, () => {
given(new Date(2017, 0, 1).getTime())
.describe('when given the beginning of this year')
.expect('january')
})
})