From a0c69414b7dbeef7aaefdb00ad78dff2a724b192 Mon Sep 17 00:00:00 2001 From: XhmikosR Date: Fri, 24 Apr 2020 00:46:49 +0300 Subject: Move fixtures to test/fixtures. (#286) --- test/convertLcovToCoveralls.js | 19 +++-- test/fixtures/istanbul.lcov | 131 +++++++++++++++++++++++++++++ test/fixtures/istanbul.remap.lcov | 131 +++++++++++++++++++++++++++++ test/fixtures/lib/index.js | 172 ++++++++++++++++++++++++++++++++++++++ test/fixtures/onefile.lcov | 116 +++++++++++++++++++++++++ test/handleInput.js | 10 +-- 6 files changed, 565 insertions(+), 14 deletions(-) create mode 100644 test/fixtures/istanbul.lcov create mode 100644 test/fixtures/istanbul.remap.lcov create mode 100644 test/fixtures/lib/index.js create mode 100644 test/fixtures/onefile.lcov (limited to 'test') diff --git a/test/convertLcovToCoveralls.js b/test/convertLcovToCoveralls.js index 92ee40d..eca48a9 100644 --- a/test/convertLcovToCoveralls.js +++ b/test/convertLcovToCoveralls.js @@ -11,9 +11,9 @@ logDriver({ level: false }); describe('convertLcovToCoveralls', () => { it('should convert a simple lcov file', done => { delete process.env.TRAVIS; - const lcovpath = path.join(__dirname, '/../fixtures/onefile.lcov'); + const lcovpath = path.join(__dirname, './fixtures/onefile.lcov'); const input = fs.readFileSync(lcovpath, 'utf8'); - const libpath = path.join(__dirname, '/../fixtures/lib'); + const libpath = path.join(__dirname, './fixtures/lib'); convertLcovToCoveralls(input, { filepath: libpath }, (err, output) => { should.not.exist(err); output.source_files[0].name.should.equal('index.js'); @@ -37,7 +37,7 @@ describe('convertLcovToCoveralls', () => { process.env.COVERALLS_FLAG_NAME = 'FLAG_NAME'; getOptions((err, options) => { - const lcovpath = path.join(__dirname, '/../fixtures/onefile.lcov'); + const lcovpath = path.join(__dirname, './fixtures/onefile.lcov'); const input = fs.readFileSync(lcovpath, 'utf8'); const libpath = 'fixtures/lib'; @@ -56,11 +56,12 @@ describe('convertLcovToCoveralls', () => { }); }); }); + it('should work with a relative path as well', done => { delete process.env.TRAVIS; - const lcovpath = path.join(__dirname, '/../fixtures/onefile.lcov'); + const lcovpath = path.join(__dirname, './fixtures/onefile.lcov'); const input = fs.readFileSync(lcovpath, 'utf8'); - const libpath = 'fixtures/lib'; + const libpath = 'test/fixtures/lib'; convertLcovToCoveralls(input, { filepath: libpath }, (err, output) => { should.not.exist(err); output.source_files[0].name.should.equal('index.js'); @@ -71,7 +72,7 @@ describe('convertLcovToCoveralls', () => { it('should convert absolute input paths to relative', done => { delete process.env.TRAVIS; - const lcovpath = path.join(__dirname, '/../fixtures/istanbul.lcov'); + const lcovpath = path.join(__dirname, './fixtures/istanbul.lcov'); const input = fs.readFileSync(lcovpath, 'utf8'); const libpath = '/Users/deepsweet/Dropbox/projects/svgo/lib'; const sourcepath = path.resolve(libpath, 'svgo/config.js'); @@ -100,7 +101,7 @@ describe('convertLcovToCoveralls', () => { it('should handle branch coverage data', done => { process.env.TRAVIS_JOB_ID = -1; - const lcovpath = path.join(__dirname, '/../fixtures/istanbul.lcov'); + const lcovpath = path.join(__dirname, './fixtures/istanbul.lcov'); const input = fs.readFileSync(lcovpath, 'utf8'); const libpath = '/Users/deepsweet/Dropbox/projects/svgo/lib'; const sourcepath = path.resolve(libpath, 'svgo/config.js'); @@ -129,7 +130,7 @@ describe('convertLcovToCoveralls', () => { it('should ignore files that do not exists', done => { delete process.env.TRAVIS; - const lcovpath = path.join(__dirname, '/../fixtures/istanbul.lcov'); + const lcovpath = path.join(__dirname, './fixtures/istanbul.lcov'); const input = fs.readFileSync(lcovpath, 'utf8'); const libpath = '/Users/deepsweet/Dropbox/projects/svgo/lib'; const sourcepath = path.resolve(libpath, 'svgo/config.js'); @@ -158,7 +159,7 @@ describe('convertLcovToCoveralls', () => { it('should parse file paths concatenated by typescript and ng 2', done => { process.env.TRAVIS_JOB_ID = -1; - const lcovpath = path.join(__dirname, '/../fixtures/istanbul.remap.lcov'); + const lcovpath = path.join(__dirname, './fixtures/istanbul.remap.lcov'); const input = fs.readFileSync(lcovpath, 'utf8'); const libpath = '/Users/deepsweet/Dropbox/projects/svgo/lib'; const sourcepath = path.resolve(libpath, 'svgo/config.js'); diff --git a/test/fixtures/istanbul.lcov b/test/fixtures/istanbul.lcov new file mode 100644 index 0000000..64d8d64 --- /dev/null +++ b/test/fixtures/istanbul.lcov @@ -0,0 +1,131 @@ +TN: +SF:/Users/deepsweet/Dropbox/projects/svgo/lib/svgo/config.js +FN:14,(anonymous_1) +FN:51,preparePluginsArray +FN:56,(anonymous_3) +FN:101,extendConfig +FN:108,(anonymous_5) +FN:115,(anonymous_6) +FN:161,optimizePluginsArray +FN:165,(anonymous_8) +FN:169,(anonymous_9) +FNF:9 +FNH:9 +FNDA:87,(anonymous_1) +FNDA:87,preparePluginsArray +FNDA:141,(anonymous_3) +FNDA:1,extendConfig +FNDA:3,(anonymous_5) +FNDA:84,(anonymous_6) +FNDA:87,optimizePluginsArray +FNDA:141,(anonymous_8) +FNDA:141,(anonymous_9) +DA:1,1 +DA:3,1 +DA:5,1 +DA:14,1 +DA:16,87 +DA:18,87 +DA:20,85 +DA:22,85 +DA:23,85 +DA:24,85 +DA:29,2 +DA:31,2 +DA:33,2 +DA:34,1 +DA:37,2 +DA:41,87 +DA:51,1 +DA:53,87 +DA:56,87 +DA:59,141 +DA:61,85 +DA:62,85 +DA:65,85 +DA:66,0 +DA:67,0 +DA:70,85 +DA:71,0 +DA:74,85 +DA:75,85 +DA:78,85 +DA:83,56 +DA:84,56 +DA:88,141 +DA:101,1 +DA:103,1 +DA:106,1 +DA:108,1 +DA:111,3 +DA:113,3 +DA:115,3 +DA:117,84 +DA:119,3 +DA:120,2 +DA:121,2 +DA:124,1 +DA:125,1 +DA:128,0 +DA:129,0 +DA:142,1 +DA:143,0 +DA:147,1 +DA:148,0 +DA:151,1 +DA:161,1 +DA:163,87 +DA:165,87 +DA:166,141 +DA:169,87 +DA:171,141 +DA:172,44 +DA:173,44 +DA:176,97 +DA:178,97 +DA:182,87 +LF:64 +LH:57 +BRDA:18,1,0,85 +BRDA:18,1,1,2 +BRDA:18,2,0,87 +BRDA:18,2,1,86 +BRDA:22,3,0,85 +BRDA:22,3,1,0 +BRDA:33,4,0,1 +BRDA:33,4,1,1 +BRDA:59,5,0,85 +BRDA:59,5,1,56 +BRDA:65,6,0,0 +BRDA:65,6,1,85 +BRDA:66,7,0,0 +BRDA:66,7,1,0 +BRDA:70,8,0,0 +BRDA:70,8,1,85 +BRDA:74,9,0,85 +BRDA:74,9,1,0 +BRDA:106,10,0,1 +BRDA:106,10,1,0 +BRDA:111,11,0,3 +BRDA:111,11,1,0 +BRDA:117,12,0,3 +BRDA:117,12,1,81 +BRDA:119,13,0,2 +BRDA:119,13,1,1 +BRDA:120,14,0,2 +BRDA:120,14,1,1 +BRDA:124,15,0,1 +BRDA:124,15,1,0 +BRDA:128,16,0,0 +BRDA:128,16,1,0 +BRDA:142,17,0,0 +BRDA:142,17,1,1 +BRDA:147,18,0,0 +BRDA:147,18,1,1 +BRDA:171,19,0,44 +BRDA:171,19,1,97 +BRDA:171,20,0,141 +BRDA:171,20,1,54 +BRF:40 +BRH:27 +end_of_record diff --git a/test/fixtures/istanbul.remap.lcov b/test/fixtures/istanbul.remap.lcov new file mode 100644 index 0000000..8da5f83 --- /dev/null +++ b/test/fixtures/istanbul.remap.lcov @@ -0,0 +1,131 @@ +TN: +SF:/Users/deepsweet/Dropbox/projects/svgo/node_modules/angular2-template-loader/index.js!/Users/deepsweet/Dropbox/projects/svgo/node_modules/tslint-loader/index.js!/Users/deepsweet/Dropbox/projects/svgo/lib/svgo/config.js +FN:14,(anonymous_1) +FN:51,preparePluginsArray +FN:56,(anonymous_3) +FN:101,extendConfig +FN:108,(anonymous_5) +FN:115,(anonymous_6) +FN:161,optimizePluginsArray +FN:165,(anonymous_8) +FN:169,(anonymous_9) +FNF:9 +FNH:9 +FNDA:87,(anonymous_1) +FNDA:87,preparePluginsArray +FNDA:141,(anonymous_3) +FNDA:1,extendConfig +FNDA:3,(anonymous_5) +FNDA:84,(anonymous_6) +FNDA:87,optimizePluginsArray +FNDA:141,(anonymous_8) +FNDA:141,(anonymous_9) +DA:1,1 +DA:3,1 +DA:5,1 +DA:14,1 +DA:16,87 +DA:18,87 +DA:20,85 +DA:22,85 +DA:23,85 +DA:24,85 +DA:29,2 +DA:31,2 +DA:33,2 +DA:34,1 +DA:37,2 +DA:41,87 +DA:51,1 +DA:53,87 +DA:56,87 +DA:59,141 +DA:61,85 +DA:62,85 +DA:65,85 +DA:66,0 +DA:67,0 +DA:70,85 +DA:71,0 +DA:74,85 +DA:75,85 +DA:78,85 +DA:83,56 +DA:84,56 +DA:88,141 +DA:101,1 +DA:103,1 +DA:106,1 +DA:108,1 +DA:111,3 +DA:113,3 +DA:115,3 +DA:117,84 +DA:119,3 +DA:120,2 +DA:121,2 +DA:124,1 +DA:125,1 +DA:128,0 +DA:129,0 +DA:142,1 +DA:143,0 +DA:147,1 +DA:148,0 +DA:151,1 +DA:161,1 +DA:163,87 +DA:165,87 +DA:166,141 +DA:169,87 +DA:171,141 +DA:172,44 +DA:173,44 +DA:176,97 +DA:178,97 +DA:182,87 +LF:64 +LH:57 +BRDA:18,1,0,85 +BRDA:18,1,1,2 +BRDA:18,2,0,87 +BRDA:18,2,1,86 +BRDA:22,3,0,85 +BRDA:22,3,1,0 +BRDA:33,4,0,1 +BRDA:33,4,1,1 +BRDA:59,5,0,85 +BRDA:59,5,1,56 +BRDA:65,6,0,0 +BRDA:65,6,1,85 +BRDA:66,7,0,0 +BRDA:66,7,1,0 +BRDA:70,8,0,0 +BRDA:70,8,1,85 +BRDA:74,9,0,85 +BRDA:74,9,1,0 +BRDA:106,10,0,1 +BRDA:106,10,1,0 +BRDA:111,11,0,3 +BRDA:111,11,1,0 +BRDA:117,12,0,3 +BRDA:117,12,1,81 +BRDA:119,13,0,2 +BRDA:119,13,1,1 +BRDA:120,14,0,2 +BRDA:120,14,1,1 +BRDA:124,15,0,1 +BRDA:124,15,1,0 +BRDA:128,16,0,0 +BRDA:128,16,1,0 +BRDA:142,17,0,0 +BRDA:142,17,1,1 +BRDA:147,18,0,0 +BRDA:147,18,1,1 +BRDA:171,19,0,44 +BRDA:171,19,1,97 +BRDA:171,20,0,141 +BRDA:171,20,1,54 +BRF:40 +BRH:27 +end_of_record diff --git a/test/fixtures/lib/index.js b/test/fixtures/lib/index.js new file mode 100644 index 0000000..052e296 --- /dev/null +++ b/test/fixtures/lib/index.js @@ -0,0 +1,172 @@ +var nodeUrl = require('url'); +var querystring = require('querystring'); +var _ = require('underscore'); + +var UrlGrey = function(url){ + this.url = url; + this._parsed = null; +}; + +UrlGrey.prototype.parsed = function(){ + if (!this._parsed){ + this._parsed = nodeUrl.parse(this.url); + var p = this._parsed; + if (p.protocol){ + p.protocol = p.protocol.slice(0,-1); + } else { + p.protocol = 'http'; + } + if (p.hash){ + p.hash = p.hash.substring(1); + } + p.username = ''; + p.password = ''; + if (!p.hostname){ + p.hostname = 'localhost'; + } + if (!p.port){ + p.port = 80; + } else { + p.port = parseInt(p.port, 10); + } + if (p.auth){ + var auth = p.auth.split(':'); + p.username = auth[0]; + p.password = auth[1]; + } + } + return this._parsed; +}; + +UrlGrey.prototype.query = function(mergeObject){ + var path; + if (mergeObject === false){ + // clear the query entirely if the input === false + return this.queryString(''); + } + + var url = this.url; + if (!mergeObject){ + var parsed = nodeUrl.parse(url); + if (!!parsed.search){ + var qstr = parsed.search.substring(1); + return querystring.parse(qstr); + } + return {}; + } else { + // read the object out + var oldQuery = querystring.parse(this.queryString()); + _.each(mergeObject, function(v, k){ + if (v === null){ + delete oldQuery[k]; + } else { + oldQuery[k] = v; + } + }); + var newString = querystring.stringify(oldQuery, '&', '='); + return this.queryString(newString); + } +}; + + +addPropertyGetterSetter('protocol'); +addPropertyGetterSetter('port'); +addPropertyGetterSetter('username'); +addPropertyGetterSetter('password'); +addPropertyGetterSetter('hostname'); +addPropertyGetterSetter('hash'); +// add a method called queryString that manipulates 'query' +addPropertyGetterSetter('query', 'queryString'); +addPropertyGetterSetter('pathname', 'path'); + +UrlGrey.prototype.path = function(){ + var args = _.toArray(arguments); + if (args.length !== 0){ + var obj = new UrlGrey(this.toString()); + var str = _.flatten(args).join('/'); + str = str.replace(/\/+/g, '/'); // remove double slashes + str = str.replace(/\/$/, ''); // remove all trailing slashes + if (str[0] !== '/'){ str = '/' + str; } + obj.parsed().pathname = str; + return obj; + } + return this.parsed().pathname; +}; + + +UrlGrey.prototype.encode = function(str){ + return querystring.escape(str); +}; + +UrlGrey.prototype.decode = function(str){ + return querystring.unescape(str); +}; + +UrlGrey.prototype.parent = function(){ + // read-only. (can't SET parent) + var pieces = this.path().split("/"); + var popped = pieces.pop(); + if (popped === ''){ // ignore trailing slash + pieces.pop(); + } + return this.path(pieces.join("/")); +}; + +UrlGrey.prototype.child = function(suffix){ + if (suffix){ + suffix = encodeURIComponent(suffix); + return this.path(this.path(), suffix); + } else { + // if no suffix, return the child + var pieces = this.path().split("/"); + var last = _.last(pieces); + if ((pieces.length > 1) && (last === '')){ + // ignore trailing slashes + pieces.pop(); + last = _.last(pieces); + } + return last; + } +}; + +UrlGrey.prototype.toJSON = function(){ + return this.toString(); +}; + +UrlGrey.prototype.toString = function(){ + var p = this.parsed(); + var userinfo = p.username + ':' + p.password; + var retval = this.protocol() + '://'; + if (userinfo != ':'){ + retval += userinfo + '@'; + } + retval += p.hostname; + if (this.port() !== 80){ + retval += ':' + this.port(); + } + retval += this.path() === '/' ? '' : this.path(); + var qs = this.queryString(); + if (qs){ + retval += '?' + qs; + } + if (p.hash){ + retval += '#' + p.hash; + } + return retval; +}; + +module.exports = function(url){ return new UrlGrey(url); }; + +function addPropertyGetterSetter(propertyName, methodName){ + if (!methodName){ + methodName = propertyName; + } + UrlGrey.prototype[methodName] = function(str){ + if (!!str || str === ''){ + var obj = new UrlGrey(this.toString()); + obj.parsed()[propertyName] = str; + return obj; + } + return this.parsed()[propertyName]; + }; +} diff --git a/test/fixtures/onefile.lcov b/test/fixtures/onefile.lcov new file mode 100644 index 0000000..bc24682 --- /dev/null +++ b/test/fixtures/onefile.lcov @@ -0,0 +1,116 @@ +make[1]: Entering directory `/home/cainus/urlgrey' +SF:index.js +DA:1,1 +DA:2,1 +DA:3,1 +DA:5,1 +DA:6,66 +DA:7,66 +DA:10,1 +DA:11,323 +DA:12,63 +DA:13,63 +DA:14,63 +DA:15,60 +DA:17,3 +DA:19,63 +DA:20,32 +DA:22,63 +DA:23,63 +DA:24,63 +DA:25,3 +DA:27,63 +DA:28,60 +DA:30,3 +DA:32,63 +DA:33,27 +DA:34,27 +DA:35,27 +DA:38,323 +DA:41,1 +DA:42,5 +DA:43,5 +DA:45,2 +DA:48,3 +DA:49,3 +DA:50,1 +DA:51,1 +DA:52,1 +DA:53,1 +DA:55,0 +DA:58,2 +DA:59,2 +DA:60,2 +DA:61,0 +DA:63,2 +DA:66,2 +DA:67,2 +DA:72,1 +DA:73,1 +DA:74,1 +DA:75,1 +DA:76,1 +DA:77,1 +DA:79,1 +DA:80,1 +DA:82,1 +DA:83,87 +DA:84,87 +DA:85,6 +DA:86,6 +DA:87,6 +DA:88,6 +DA:89,9 +DA:90,6 +DA:91,6 +DA:93,81 +DA:97,1 +DA:98,1 +DA:101,1 +DA:102,1 +DA:105,1 +DA:107,2 +DA:108,2 +DA:109,2 +DA:110,1 +DA:112,2 +DA:115,1 +DA:116,3 +DA:117,1 +DA:118,1 +DA:121,2 +DA:122,2 +DA:123,2 +DA:125,1 +DA:126,1 +DA:128,2 +DA:132,1 +DA:133,1 +DA:136,1 +DA:137,50 +DA:138,50 +DA:139,50 +DA:140,50 +DA:141,20 +DA:143,50 +DA:144,50 +DA:145,2 +DA:147,50 +DA:148,50 +DA:149,50 +DA:150,31 +DA:152,50 +DA:153,24 +DA:155,50 +DA:210,40 +DA:212,1 +DA:213,8 +DA:214,6 +DA:216,8 +DA:217,186 +DA:218,21 +DA:219,21 +DA:220,21 +DA:222,165 +end_of_record +make[1]: Leaving directory `/home/cainus/urlgrey' diff --git a/test/handleInput.js b/test/handleInput.js index 46cbe50..c46aa17 100644 --- a/test/handleInput.js +++ b/test/handleInput.js @@ -15,7 +15,7 @@ describe('handleInput', () => { }); it('returns an error when there\'s an error getting options', done => { sinon.stub(index, 'getOptions', cb => cb('some error', {})); - const path = sysPath.join(__dirname, '/../fixtures/onefile.lcov'); + const path = sysPath.join(__dirname, './fixtures/onefile.lcov'); const input = fs.readFileSync(path, 'utf8'); index.handleInput(input, err => { err.should.equal('some error'); @@ -27,7 +27,7 @@ describe('handleInput', () => { sinon.stub(index, 'convertLcovToCoveralls', (input, options, cb) => { cb('some error'); }); - const path = sysPath.join(__dirname, '/../fixtures/onefile.lcov'); + const path = sysPath.join(__dirname, './fixtures/onefile.lcov'); const input = fs.readFileSync(path, 'utf8'); index.handleInput(input, err => { err.should.equal('some error'); @@ -39,7 +39,7 @@ describe('handleInput', () => { sinon.stub(index, 'sendToCoveralls', (postData, cb) => { cb('some error'); }); - const path = sysPath.join(__dirname, '/../fixtures/onefile.lcov'); + const path = sysPath.join(__dirname, './fixtures/onefile.lcov'); const input = fs.readFileSync(path, 'utf8'); index.handleInput(input, err => { err.should.equal('some error'); @@ -51,7 +51,7 @@ describe('handleInput', () => { sinon.stub(index, 'sendToCoveralls', (postData, cb) => { cb(null, { statusCode: 500 }, 'body'); }); - const path = sysPath.join(__dirname, '/../fixtures/onefile.lcov'); + const path = sysPath.join(__dirname, './fixtures/onefile.lcov'); const input = fs.readFileSync(path, 'utf8'); index.handleInput(input, err => { err.should.equal('Bad response: 500 body'); @@ -63,7 +63,7 @@ describe('handleInput', () => { sinon.stub(index, 'sendToCoveralls', (postData, cb) => { cb(null, { statusCode: 200 }, 'body'); }); - const path = sysPath.join(__dirname, '/../fixtures/onefile.lcov'); + const path = sysPath.join(__dirname, './fixtures/onefile.lcov'); const input = fs.readFileSync(path, 'utf8'); index.handleInput(input, (err, body) => { should.not.exist(err); -- cgit v1.2.3