Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #37 from snyk/fix/jestify
fix: jestify the tests
- Loading branch information
Showing
50 changed files
with
718 additions
and
734 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// remove the noise from express server logs | ||
process.env.LOG_LEVEL="fatal"; | ||
|
||
module.exports = { | ||
preset: 'ts-jest', | ||
testEnvironment: 'node', | ||
}; | ||
|
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 was deleted.
Oops, something went wrong.
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,62 @@ | ||
import { cmp } from '../../'; | ||
|
||
// cmp(v1, comparator, v2): Pass in a comparison string, and it'll call the | ||
// corresponding function above. "===" and "!==" do simple string comparison, | ||
// but are included for completeness. | ||
// Throws if an invalid comparison string is provided. | ||
|
||
describe('test cmp', () => { | ||
it('cmp(v1, ">", v2)', () => { | ||
expect(cmp('2', '>', '1')).toBeTruthy(); | ||
expect(cmp('2', '>', '2')).toBeFalsy(); | ||
expect(cmp('1', '>', '2')).toBeFalsy(); | ||
}); | ||
|
||
it('cmp(v1, ">=", v2)', () => { | ||
expect(cmp('2', '>=', '1')).toBeTruthy(); | ||
expect(cmp('2', '>=', '2')).toBeTruthy(); | ||
expect(cmp('1', '>=', '2')).toBeFalsy(); | ||
}); | ||
|
||
it('cmp(v1, "<", v2)', () => { | ||
expect(cmp('1', '<', '2')).toBeTruthy(); | ||
expect(cmp('2', '<', '2')).toBeFalsy(); | ||
expect(cmp('2', '<', '1')).toBeFalsy(); | ||
}); | ||
|
||
it('cmp(v1, "<=", v2)', () => { | ||
expect(cmp('1', '<=', '2')).toBeTruthy(); | ||
expect(cmp('2', '<=', '2')).toBeTruthy(); | ||
expect(cmp('2', '<=', '1')).toBeFalsy(); | ||
}); | ||
|
||
it('cmp(v1, "==", v2)', () => { | ||
expect(cmp('2', '==', '2')).toBeTruthy(); | ||
expect(cmp('2', '==', '2.0')).toBeTruthy(); | ||
expect(cmp('2', '==', '1')).toBeFalsy(); | ||
}); | ||
|
||
it('cmp(v1, "!=", v2)', () => { | ||
expect(cmp('2', '!=', '1')).toBeTruthy(); | ||
expect(cmp('2', '!=', '2')).toBeFalsy(); | ||
expect(cmp('2', '!=', '2.0')).toBeFalsy(); | ||
}); | ||
|
||
it('cmp(v1, "===", v2)', () => { | ||
expect(cmp('2', '===', '2')).toBeTruthy(); | ||
expect(cmp('2', '===', '1')).toBeFalsy(); | ||
expect(cmp('2', '===', '2.0')).toBeFalsy(); | ||
}); | ||
|
||
it('cmp(v1, "!==", v2)', () => { | ||
expect(cmp('2', '!==', '2')).toBeFalsy(); | ||
expect(cmp('2', '!==', '2.0')).toBeTruthy(); | ||
expect(cmp('2', '!==', '1')).toBeTruthy(); | ||
}); | ||
|
||
it('cmp(v1, "nonsense", v2)', () => { | ||
expect(() => {cmp('2', 'nonsense', '2')}).toThrow(new Error('Invalid comparator: nonsense')); | ||
expect(() => {cmp('2', '!====', '2')}).toThrow(new Error('Invalid comparator: !====')); | ||
expect(() => {cmp('2', '>broken', '2')}).toThrow(new Error('Invalid comparator: >broken')); | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.
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,33 @@ | ||
import { compare } from '../../'; | ||
|
||
// compare(v1, v2): Return 0 if v1 == v2, or 1 if v1 is greater, or -1 if v2 is | ||
// greater. Sorts in ascending order if passed to Array.sort(). | ||
|
||
describe('test compare', () => { | ||
it('compare(v1, v2): 0 if v1 == v2', () => { | ||
expect(compare('1', '1')).toBe(0); | ||
expect(compare('1.1', '1.1')).toBe(0); | ||
expect(compare('1.1.0', '1.1.0')).toBe(0); | ||
expect(compare('1.1.0.1', '1.1.0.1')).toBe(0); | ||
expect(compare('1.1.0.1-alpha', '1.1.0.1-alpha')).toBe(0); | ||
expect(compare('1.1.0.1-alpha.2', '1.1.0.1-alpha.2')).toBe(0); | ||
}); | ||
|
||
it('compare(v1, v2): 1 if v1 > v2', () => { | ||
expect(compare('2', '1')).toBe(1); | ||
expect(compare('1.2', '1.1')).toBe(1); | ||
expect(compare('1.1.1', '1.1.0')).toBe(1); | ||
expect(compare('1.1.0.2', '1.1.0.1')).toBe(1); | ||
expect(compare('1.1.0.1-beta', '1.1.0.1-alpha')).toBe(1); | ||
expect(compare('1.1.0.1-alpha.3', '1.1.0.1-alpha.2')).toBe(1); | ||
}); | ||
|
||
it('compare(v1, v2): -1 if v1 < v2', () => { | ||
expect(compare('1', '2')).toBe(-1); | ||
expect(compare('1.1', '1.2')).toBe(-1); | ||
expect(compare('1.1.0', '1.1.1')).toBe(-1); | ||
expect(compare('1.1.0.1', '1.1.0.2')).toBe(-1); | ||
expect(compare('1.1.0.1-alpha', '1.1.0.1-beta')).toBe(-1); | ||
expect(compare('1.1.0.1-alpha.2', '1.1.0.1-alpha.3')).toBe(-1); | ||
}) | ||
}); |
This file was deleted.
Oops, something went wrong.
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,73 @@ | ||
const semver = require('../../'); | ||
const diff = semver.diff; | ||
|
||
// Not implemented as we don't use it. | ||
|
||
// diff(v1, v2): Returns difference between two versions by the release type | ||
// (major, premajor, minor, preminor, patch, prepatch, or prerelease), or null | ||
// if the versions are the same. | ||
|
||
describe('test diff', () => { | ||
|
||
it('diff(v1, v2): same versions', () => { | ||
expect(diff('1', '1')).toBe(null); | ||
expect(diff('1.1', '1.1')).toBe(null); | ||
expect(diff('1.1.2', '1.1.2')).toBe(null); | ||
expect(diff('1.1.1.1', '1.1.1.1')).toBe(null); | ||
expect(diff('1.0.0.alpha.1', '1.0.0.alpha.1')).toBe(null); | ||
expect(diff('1.1.2-1', '1.1.2.pre.1')).toBe(null); | ||
expect(diff('1.1.2.pre.1', '1.1.2-1')).toBe(null); | ||
expect(diff('2', '2.0')).toBe(null); | ||
expect(diff('2.0', '2')).toBe(null); | ||
expect(diff('2', '2.0.0')).toBe(null); | ||
expect(diff('2.0.0', '2')).toBe(null); | ||
expect(diff('2', '2.0.0.0')).toBe(null); | ||
expect(diff('2.0.0.0', '2')).toBe(null); | ||
}); | ||
|
||
it('diff(v1, v2): major versions', () => { | ||
expect(diff('1', '3')).toBe('major'); | ||
expect(diff('1.1', '3.1')).toBe('major'); | ||
expect(diff('1.1.2', '3.0.0')).toBe('major'); | ||
expect(diff('1.1.2', '2.0.0')).toBe('major'); | ||
expect(diff('1.1.1.1', '2.0.0')).toBe('major'); | ||
}); | ||
|
||
it('diff(v1, v2): minor versions', () => { | ||
expect(diff('1.1', '1.2')).toBe('minor'); | ||
expect(diff('1.1.2', '1.2.1.1')).toBe('minor'); | ||
expect(diff('1.1.2', '1.2.0')).toBe('minor'); | ||
expect(diff('1.1.2.1', '1.2.0')).toBe('minor'); | ||
expect(diff('1.1.2.1', '1.2.0.1')).toBe('minor'); | ||
}); | ||
|
||
it('diff(v1, v2): patch versions', () => { | ||
expect(diff('1.1.2', '1.1.3')).toBe('patch'); | ||
expect(diff('1.1.2', '1.1.2.1')).toBe('patch'); | ||
expect(diff('1.1.2.1', '1.1.3')).toBe('patch'); | ||
expect(diff('1.1.2.1', '1.1.3.2.1')).toBe('patch'); | ||
expect(diff('1.1.2.1', '1.1.2.1.1.1.2')).toBe('patch'); | ||
expect(diff('1.1.2.1.1.1.1', '1.1.2.1.1.1.2')).toBe('patch'); | ||
}); | ||
|
||
it('diff(v1, v2): premajor versions', () => { | ||
expect(diff('1.0.0.alpha.1', '2.0.0')).toBe('premajor'); | ||
}); | ||
|
||
it('diff(v1, v2): preminor versions', () => { | ||
expect(diff('1.1.2.alpha.1', '1.2.0')).toBe('preminor'); | ||
}); | ||
|
||
it('diff(v1, v2): prepatch versions', () => { | ||
expect(diff('1.1.2.alpha.1', '1.1.3')).toBe('prepatch'); | ||
expect(diff('1.1.2.3.alpha.1', '1.1.2.alpha.2')).toBe('prepatch'); | ||
expect(diff('1.1.2.3.alpha.1', '1.1.2.4.alpha.2')).toBe('prepatch'); | ||
expect(diff('1.1.2.alpha.1', '1.1.2.1')).toBe('prepatch'); | ||
}); | ||
|
||
it('diff(v1, v2): prerelease versions', () => { | ||
expect(diff('1.1.2.alpha.1', '1.1.2.alpha.2')).toBe('prerelease'); | ||
expect(diff('1.1.2.3.alpha.1', '1.1.2.3.alpha.2')).toBe('prerelease'); | ||
expect(diff('1.alpha.1', '1')).toBe('prerelease'); | ||
}) | ||
}); |
Oops, something went wrong.