From 4476b26d0176bcfa3335edfb9f24e5c4d247b2ce Mon Sep 17 00:00:00 2001 From: Jakub Pawlowicz Date: Mon, 9 Jun 2014 23:40:42 +0100 Subject: [PATCH] Improves protocol import tests to avoid DNS lookup. --- test/protocol-imports-test.js | 90 +++++++++++++++++------------------ 1 file changed, 45 insertions(+), 45 deletions(-) diff --git a/test/protocol-imports-test.js b/test/protocol-imports-test.js index b440a939..b838c785 100644 --- a/test/protocol-imports-test.js +++ b/test/protocol-imports-test.js @@ -14,17 +14,17 @@ if (process.platform == 'win32') vows.describe('protocol imports').addBatch({ 'of a missing file': { topic: function() { - this.reqMocks = nock('http://goalsmashers.com') + this.reqMocks = nock('http://127.0.0.1') .get('/missing.css') .reply(404); - new CleanCSS().minify('@import url(http://goalsmashers.com/missing.css);a{color:red}', this.callback); + new CleanCSS().minify('@import url(http://127.0.0.1/missing.css);a{color:red}', this.callback); }, 'should raise error': function(errors, minified) { assert.equal(errors.length, 1); }, 'should ignore @import': function(errors, minified) { - assert.equal(minified, '@import url(http://goalsmashers.com/missing.css);a{color:red}'); + assert.equal(minified, '@import url(http://127.0.0.1/missing.css);a{color:red}'); }, teardown: function() { assert.equal(this.reqMocks.isDone(), true); @@ -33,11 +33,11 @@ vows.describe('protocol imports').addBatch({ }, 'of an existing file': { topic: function() { - this.reqMocks = nock('http://goalsmashers.com') + this.reqMocks = nock('http://127.0.0.1') .get('/present.css') .reply(200, 'p{font-size:13px}'); - new CleanCSS().minify('@import url(http://goalsmashers.com/present.css);a{color:red}', this.callback); + new CleanCSS().minify('@import url(http://127.0.0.1/present.css);a{color:red}', this.callback); }, 'should not raise errors': function(errors, minified) { assert.isNull(errors); @@ -71,11 +71,11 @@ vows.describe('protocol imports').addBatch({ }, 'of an existing file via HTTPS': { topic: function() { - this.reqMocks = nock('https://goalsmashers.com') + this.reqMocks = nock('https://127.0.0.1') .get('/present.css') .reply(200, 'p{font-size:13px}'); - new CleanCSS().minify('@import url(https://goalsmashers.com/present.css);a{color:red}', this.callback); + new CleanCSS().minify('@import url(https://127.0.0.1/present.css);a{color:red}', this.callback); }, 'should not raise errors': function(errors, minified) { assert.isNull(errors); @@ -90,11 +90,11 @@ vows.describe('protocol imports').addBatch({ }, 'of an existing file with media': { topic: function() { - this.reqMocks = nock('http://goalsmashers.com') + this.reqMocks = nock('http://127.0.0.1') .get('/present.css') .reply(200, 'p{font-size:13px}'); - new CleanCSS().minify('@import url(http://goalsmashers.com/present.css) screen;a{color:red}', this.callback); + new CleanCSS().minify('@import url(http://127.0.0.1/present.css) screen;a{color:red}', this.callback); }, 'should not raise errors': function(errors, minified) { assert.isNull(errors); @@ -109,16 +109,16 @@ vows.describe('protocol imports').addBatch({ }, 'of an existing file with dependencies': { topic: function() { - this.reqMocks1 = nock('http://goalsmashers.com') + this.reqMocks1 = nock('http://127.0.0.1') .get('/present.css') - .reply(200, '@import url(/vendor/reset.css);@import url(https://assets.goalsmashers.com/base.css);p{font-size:13px}') + .reply(200, '@import url(/vendor/reset.css);@import url(https://assets.127.0.0.1/base.css);p{font-size:13px}') .get('/vendor/reset.css') .reply(200, 'body{margin:0}'); - this.reqMocks2 = nock('https://assets.goalsmashers.com') + this.reqMocks2 = nock('https://assets.127.0.0.1') .get('/base.css') .reply(200, 'div{padding:0}'); - new CleanCSS().minify('@import url(http://goalsmashers.com/present.css);a{color:red}', this.callback); + new CleanCSS().minify('@import url(http://127.0.0.1/present.css);a{color:red}', this.callback); }, 'should not raise errors': function(errors, minified) { assert.isNull(errors); @@ -134,13 +134,13 @@ vows.describe('protocol imports').addBatch({ }, 'of an existing file with relative dependencies': { topic: function() { - this.reqMocks = nock('http://goalsmashers.com') + this.reqMocks = nock('http://127.0.0.1') .get('/nested/present.css') .reply(200, '@import url(../vendor/reset.css);p{font-size:13px}') .get('/vendor/reset.css') .reply(200, 'body{margin:0}'); - new CleanCSS().minify('@import url(http://goalsmashers.com/nested/present.css);a{color:red}', this.callback); + new CleanCSS().minify('@import url(http://127.0.0.1/nested/present.css);a{color:red}', this.callback); }, 'should not raise errors': function(errors, minified) { assert.isNull(errors); @@ -155,20 +155,20 @@ vows.describe('protocol imports').addBatch({ }, 'of an existing file missing relative dependency': { topic: function() { - this.reqMocks = nock('http://goalsmashers.com') + this.reqMocks = nock('http://127.0.0.1') .get('/nested/present.css') .reply(200, '@import url(../missing.css);p{font-size:13px}') .get('/missing.css') .reply(404); - new CleanCSS().minify('@import url(http://goalsmashers.com/nested/present.css);a{color:red}', this.callback); + new CleanCSS().minify('@import url(http://127.0.0.1/nested/present.css);a{color:red}', this.callback); }, 'should not raise errors': function(errors, minified) { assert.equal(errors.length, 1); - assert.equal(errors[0], 'Broken @import declaration of "http://goalsmashers.com/missing.css" - error 404'); + assert.equal(errors[0], 'Broken @import declaration of "http://127.0.0.1/missing.css" - error 404'); }, 'should process @import': function(errors, minified) { - assert.equal(minified, '@import url(http://goalsmashers.com/missing.css);p{font-size:13px}a{color:red}'); + assert.equal(minified, '@import url(http://127.0.0.1/missing.css);p{font-size:13px}a{color:red}'); }, teardown: function() { assert.equal(this.reqMocks.isDone(), true); @@ -177,17 +177,17 @@ vows.describe('protocol imports').addBatch({ }, 'of an existing file with URLs to rebase': { topic: function() { - this.reqMocks = nock('http://goalsmashers.com') + this.reqMocks = nock('http://127.0.0.1') .get('/urls.css') .reply(200, 'a{background:url(test.png)}'); - new CleanCSS().minify('@import url(http://goalsmashers.com/urls.css);', this.callback); + new CleanCSS().minify('@import url(http://127.0.0.1/urls.css);', this.callback); }, 'should not raise errors': function(errors, minified) { assert.isNull(errors); }, 'should process @import': function(errors, minified) { - assert.equal(minified, 'a{background:url(http://goalsmashers.com/test.png)}'); + assert.equal(minified, 'a{background:url(http://127.0.0.1/test.png)}'); }, teardown: function() { assert.equal(this.reqMocks.isDone(), true); @@ -196,19 +196,19 @@ vows.describe('protocol imports').addBatch({ }, 'of an existing file with relative URLs to rebase': { topic: function() { - this.reqMocks = nock('http://goalsmashers.com') + this.reqMocks = nock('http://127.0.0.1') .get('/base.css') .reply(200, '@import url(deeply/nested/urls.css);') .get('/deeply/nested/urls.css') .reply(200, 'a{background:url(../images/test.png)}'); - new CleanCSS().minify('@import url(http://goalsmashers.com/base.css);', this.callback); + new CleanCSS().minify('@import url(http://127.0.0.1/base.css);', this.callback); }, 'should not raise errors': function(errors, minified) { assert.isNull(errors); }, 'should process @import': function(errors, minified) { - assert.equal(minified, 'a{background:url(http://goalsmashers.com/deeply/images/test.png)}'); + assert.equal(minified, 'a{background:url(http://127.0.0.1/deeply/images/test.png)}'); }, teardown: function() { assert.equal(this.reqMocks.isDone(), true); @@ -217,25 +217,25 @@ vows.describe('protocol imports').addBatch({ }, 'of a non-resolvable domain': { topic: function() { - new CleanCSS().minify('@import url(http://notdefined.goalsmashers.com/custom.css);a{color:red}', this.callback); + new CleanCSS().minify('@import url(http://notdefined.127.0.0.1/custom.css);a{color:red}', this.callback); }, 'should not raise errors': function(errors, minified) { assert.equal(errors.length, 1); - assert.equal(errors[0], 'Broken @import declaration of "http://notdefined.goalsmashers.com/custom.css" - getaddrinfo ENOTFOUND'); + assert.equal(errors[0], 'Broken @import declaration of "http://notdefined.127.0.0.1/custom.css" - getaddrinfo ENOTFOUND'); }, 'should process @import': function(errors, minified) { - assert.equal(minified, '@import url(http://notdefined.goalsmashers.com/custom.css);a{color:red}'); + assert.equal(minified, '@import url(http://notdefined.127.0.0.1/custom.css);a{color:red}'); } }, 'of a 30x response with absolute URL': { topic: function() { - this.reqMocks = nock('http://goalsmashers.com') + this.reqMocks = nock('http://127.0.0.1') .get('/moved.css') - .reply(301, '', { 'Location': 'http://goalsmashers.com/present.css' }) + .reply(301, '', { 'Location': 'http://127.0.0.1/present.css' }) .get('/present.css') .reply(200, 'body{margin:0}'); - new CleanCSS().minify('@import url(http://goalsmashers.com/moved.css);a{color:red}', this.callback); + new CleanCSS().minify('@import url(http://127.0.0.1/moved.css);a{color:red}', this.callback); }, 'should not raise errors': function(errors, minified) { assert.isNull(errors); @@ -250,13 +250,13 @@ vows.describe('protocol imports').addBatch({ }, 'of a 30x response with relative URL': { topic: function() { - this.reqMocks = nock('http://goalsmashers.com') + this.reqMocks = nock('http://127.0.0.1') .get('/moved.css') .reply(301, '', { 'Location': '/present.css' }) .get('/present.css') .reply(200, 'body{margin:0}'); - new CleanCSS().minify('@import url(http://goalsmashers.com/moved.css);a{color:red}', this.callback); + new CleanCSS().minify('@import url(http://127.0.0.1/moved.css);a{color:red}', this.callback); }, 'should not raise errors': function(errors, minified) { assert.isNull(errors); @@ -297,13 +297,13 @@ vows.describe('protocol imports').addBatch({ }, 'of a cyclical reference response': { topic: function() { - this.reqMocks = nock('http://goalsmashers.com') + this.reqMocks = nock('http://127.0.0.1') .get('/one.css') .reply(200, '@import url(/two.css);div{padding:0}') .get('/two.css') - .reply(200, '@import url(http://goalsmashers.com/two.css);body{margin:0}'); + .reply(200, '@import url(http://127.0.0.1/two.css);body{margin:0}'); - new CleanCSS().minify('@import url(http://goalsmashers.com/one.css);a{color:red}', this.callback); + new CleanCSS().minify('@import url(http://127.0.0.1/one.css);a{color:red}', this.callback); }, 'should not raise errors': function(errors, minified) { assert.isNull(errors); @@ -318,11 +318,11 @@ vows.describe('protocol imports').addBatch({ }, 'of a resource without protocol': { topic: function() { - this.reqMocks = nock('http://goalsmashers.com') + this.reqMocks = nock('http://127.0.0.1') .get('/no-protocol.css') .reply(200, 'div{padding:0}'); - new CleanCSS().minify('@import url(//goalsmashers.com/no-protocol.css);a{color:red}', this.callback); + new CleanCSS().minify('@import url(//127.0.0.1/no-protocol.css);a{color:red}', this.callback); }, 'should not raise errors': function(errors, minified) { assert.isNull(errors); @@ -337,7 +337,7 @@ vows.describe('protocol imports').addBatch({ }, 'of a resource available via POST only': { topic: function() { - this.reqMocks = nock('http://goalsmashers.com') + this.reqMocks = nock('http://127.0.0.1') .post('/computed.css') .reply(200, 'div{padding:0}'); @@ -347,7 +347,7 @@ vows.describe('protocol imports').addBatch({ method: 'POST' } } - }).minify('@import url(http://goalsmashers.com/computed.css);a{color:red}', this.callback); + }).minify('@import url(http://127.0.0.1/computed.css);a{color:red}', this.callback); }, 'should not raise errors': function(errors, minified) { assert.isNull(errors); @@ -362,8 +362,8 @@ vows.describe('protocol imports').addBatch({ }, 'of a remote resource mixed with local ones': { topic: function() { - var source = '@import url(http://goalsmashers.com/remote.css);@import url(test/data/partials/one.css);'; - this.reqMocks = nock('http://goalsmashers.com') + var source = '@import url(http://127.0.0.1/remote.css);@import url(test/data/partials/one.css);'; + this.reqMocks = nock('http://127.0.0.1') .get('/remote.css') .reply(200, 'div{padding:0}'); @@ -382,8 +382,8 @@ vows.describe('protocol imports').addBatch({ }, 'of a remote resource mixed with local ones but no callback': { topic: function() { - var source = '@import url(http://goalsmashers.com/remote.css);@import url(test/data/partials/one.css);'; - this.reqMocks = nock('http://goalsmashers.com') + var source = '@import url(http://127.0.0.1/remote.css);@import url(test/data/partials/one.css);'; + this.reqMocks = nock('http://127.0.0.1') .get('/remote.css') .reply(200, 'div{padding:0}'); @@ -399,7 +399,7 @@ vows.describe('protocol imports').addBatch({ assert.match(minifier.warnings[0], /no callback given/); }, 'should process @import': function(error, minifier, minified) { - assert.equal(minified, '@import url(http://goalsmashers.com/remote.css);.one{color:red}'); + assert.equal(minified, '@import url(http://127.0.0.1/remote.css);.one{color:red}'); }, teardown: function() { assert.equal(this.reqMocks.isDone(), false); -- 2.34.1