diff --git a/functions/parse.js b/functions/parse.js index a66663aa..dc6f55f9 100644 --- a/functions/parse.js +++ b/functions/parse.js @@ -7,7 +7,7 @@ const parse = (version, options) => { options = parseOptions(options) if (version instanceof SemVer) { - return version + return new SemVer(version.version) } if (typeof version !== 'string') { diff --git a/test/functions/parse.js b/test/functions/parse.js index 16183dc0..33a719e5 100644 --- a/test/functions/parse.js +++ b/test/functions/parse.js @@ -11,8 +11,15 @@ t.test('returns null instead of throwing when presented with garbage', t => { t.test('parse a version into a SemVer object', t => { t.match(parse('1.2.3'), new SemVer('1.2.3')) - const s = new SemVer('4.5.6') - t.equal(parse(s), s, 'just return it if its a SemVer obj') + const inputSemVer = new SemVer('4.5.6') + const parsedSemVer = parse(inputSemVer) + t.equal( + JSON.stringify(parse(inputSemVer)), + JSON.stringify(inputSemVer), + 'returns a copy if input is a SemVer obj' + ) + inputSemVer.version = '4.5.7' + t.equal(parsedSemVer.version, '4.5.6', 'is a deep clone when input is a SemVer obj') const loose = new SemVer('4.2.0', { loose: true }) t.match(parse('4.2.0', true), loose, 'looseness as a boolean') t.match(parse('4.2.0', { loose: true }), loose, 'looseness as an option')