Skip to content

Commit

Permalink
🎨 🚑 do not use testurl.com in tests (#8254)
Browse files Browse the repository at this point in the history
no issue

- if we are using any random domain in our tests, it could be that the test behaviour changes over time
- in this case: the ghost_head_spec triggers a request for image diminsions (cover image, author image, blog logo)
- if the target blog url/domain can't be reached (connecting....), the timeout would be reached - but the test is not setup to handle longer waiting times
- even with https://github.com/TryGhost/Ghost/pull/8210/files, the default timeout would be 5s, which is not acceptable for a unit test
- that's why, we need to choose a blog url, which definitely is "down" - any long localhost port
  • Loading branch information
kirrg001 authored and ErisDS committed Apr 3, 2017
1 parent 6e24f05 commit be977a5
Show file tree
Hide file tree
Showing 7 changed files with 158 additions and 158 deletions.
2 changes: 1 addition & 1 deletion core/test/unit/importer_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ describe('Importer', function () {
});

it('can load a file (subdirectory)', function (done) {
configUtils.set({url: 'http://testurl.com/subdir'});
configUtils.set({url: 'http://localhost:82832/subdir'});

var filename = 'test-image.jpeg',
file = [{
Expand Down
10 changes: 5 additions & 5 deletions core/test/unit/metadata/paginated_url_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ describe('getPaginatedUrl', function () {

describe('with /blog subdirectory', function () {
before(function () {
configUtils.set({url: 'http://testurl.com/blog'});
configUtils.set({url: 'http://localhost:82832/blog'});
});

after(function () {
Expand All @@ -141,8 +141,8 @@ describe('getPaginatedUrl', function () {
var urls = getTestUrls();

// Check results
urls.should.have.property('next', 'http://testurl.com/blog/page/3/');
urls.should.have.property('prev', 'http://testurl.com/blog/');
urls.should.have.property('next', 'http://localhost:82832/blog/page/3/');
urls.should.have.property('prev', 'http://localhost:82832/blog/');
urls.should.have.property('page1', '/blog/');
urls.should.have.property('page5', '/blog/page/5/');
urls.should.have.property('page10', '/blog/page/10/');
Expand All @@ -157,8 +157,8 @@ describe('getPaginatedUrl', function () {
var urls = getTestUrls();

// Check results
urls.should.have.property('next', 'http://testurl.com/blog/featured/page/3/');
urls.should.have.property('prev', 'http://testurl.com/blog/featured/');
urls.should.have.property('next', 'http://localhost:82832/blog/featured/page/3/');
urls.should.have.property('prev', 'http://localhost:82832/blog/featured/');
urls.should.have.property('page1', '/blog/featured/');
urls.should.have.property('page5', '/blog/featured/page/5/');
urls.should.have.property('page10', '/blog/featured/page/10/');
Expand Down
4 changes: 2 additions & 2 deletions core/test/unit/rss_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ describe('RSS', function () {
});

it('Should 404 if page number too big', function (done) {
configUtils.set({url: 'http://testurl.com/'});
configUtils.set({url: 'http://localhost:82832/'});

req = {params: {page: 4}, route: {path: '/rss/:page/'}};
req.originalUrl = req.route.path.replace(':page', req.params.page);
Expand All @@ -465,7 +465,7 @@ describe('RSS', function () {
});

it('Redirects to last page if page number too big with subdirectory', function (done) {
configUtils.set({url: 'http://testurl.com/blog'});
configUtils.set({url: 'http://localhost:82832/blog'});

req = {params: {page: 4}, route: {path: '/rss/:page/'}};
req.originalUrl = req.route.path.replace(':page', req.params.page);
Expand Down
2 changes: 1 addition & 1 deletion core/test/unit/server_helpers/asset_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ describe('{{asset}} helper', function () {

describe('with /blog subdirectory', function () {
before(function () {
configUtils.set({url: 'http://testurl.com/blog'});
configUtils.set({url: 'http://localhost:82832/blog'});
});

it('handles favicon correctly', function () {
Expand Down
256 changes: 128 additions & 128 deletions core/test/unit/server_helpers/ghost_head_spec.js

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions core/test/unit/server_helpers/image_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ var should = require('should'), // jshint ignore:line

describe('{{image}} helper', function () {
before(function () {
configUtils.set({url: 'http://testurl.com/'});
configUtils.set({url: 'http://localhost:82832/'});
});

afterEach(function () {
Expand Down Expand Up @@ -42,7 +42,7 @@ describe('{{image}} helper', function () {
});

should.exist(rendered);
rendered.should.equal('http://testurl.com/content/images/image-relative-url.png');
rendered.should.equal('http://localhost:82832/content/images/image-relative-url.png');
});

it('should have no output if there is no image ', function () {
Expand All @@ -59,7 +59,7 @@ describe('{{image}} helper', function () {

describe('with sub-directory', function () {
before(function () {
configUtils.set({url: 'http://testurl.com/blog'});
configUtils.set({url: 'http://localhost:82832/blog'});
});
after(function () {
configUtils.restore();
Expand Down Expand Up @@ -87,7 +87,7 @@ describe('{{image}} helper', function () {
});

should.exist(rendered);
rendered.should.equal('http://testurl.com/blog/content/images/image-relative-url.png');
rendered.should.equal('http://localhost:82832/blog/content/images/image-relative-url.png');
});

it('should not change output for an external url', function () {
Expand Down
34 changes: 17 additions & 17 deletions core/test/unit/server_helpers/url_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('{{url}} helper', function () {
var rendered;

before(function () {
configUtils.set({url: 'http://testurl.com/'});
configUtils.set({url: 'http://localhost:82832/'});
});

beforeEach(function () {
Expand Down Expand Up @@ -52,7 +52,7 @@ describe('{{url}} helper', function () {
);

should.exist(rendered);
rendered.string.should.equal('http://testurl.com/slug/');
rendered.string.should.equal('http://localhost:82832/slug/');
});

it('should output an absolute URL with https if the option is present and secure', function () {
Expand All @@ -65,7 +65,7 @@ describe('{{url}} helper', function () {
);

should.exist(rendered);
rendered.string.should.equal('https://testurl.com/slug/');
rendered.string.should.equal('https://localhost:82832/slug/');
});

it('should output an absolute URL with https if secure', function () {
Expand All @@ -78,7 +78,7 @@ describe('{{url}} helper', function () {
);

should.exist(rendered);
rendered.string.should.equal('https://testurl.com/slug/');
rendered.string.should.equal('https://localhost:82832/slug/');
});

it('should return the slug with a prefixed /tag/ if the context is a tag', function () {
Expand Down Expand Up @@ -123,15 +123,15 @@ describe('{{url}} helper', function () {
{url: '/bar', label: 'Bar', slug: 'bar', current: true},
{hash: {absolute: 'true'}});
should.exist(rendered);
rendered.string.should.equal('http://testurl.com/bar');
rendered.string.should.equal('http://localhost:82832/bar');
});

it('should return an absolute url with https if context is secure', function () {
rendered = helpers.url.call(
{url: '/bar', label: 'Bar', slug: 'bar', current: true, secure: true},
{hash: {absolute: 'true'}});
should.exist(rendered);
rendered.string.should.equal('https://testurl.com/bar');
rendered.string.should.equal('https://localhost:82832/bar');
});

it('external urls should be retained in a nav context', function () {
Expand All @@ -144,40 +144,40 @@ describe('{{url}} helper', function () {

it('should handle hosted urls in a nav context', function () {
rendered = helpers.url.call(
{url: 'http://testurl.com/qux', label: 'Qux', slug: 'qux', current: true},
{url: 'http://localhost:82832/qux', label: 'Qux', slug: 'qux', current: true},
{hash: {absolute: 'true'}});
should.exist(rendered);
rendered.string.should.equal('http://testurl.com/qux');
rendered.string.should.equal('http://localhost:82832/qux');
});

it('should handle hosted urls in a nav context with secure', function () {
rendered = helpers.url.call(
{
url: 'http://testurl.com/qux', label: 'Qux', slug: 'qux', current: true,
url: 'http://localhost:82832/qux', label: 'Qux', slug: 'qux', current: true,
secure: true
},
{hash: {absolute: 'true'}});
should.exist(rendered);
rendered.string.should.equal('https://testurl.com/qux');
rendered.string.should.equal('https://localhost:82832/qux');
});

it('should handle hosted https urls in a nav context with secure', function () {
rendered = helpers.url.call(
{
url: 'https://testurl.com/qux', label: 'Qux', slug: 'qux', current: true,
url: 'https://localhost:82832/qux', label: 'Qux', slug: 'qux', current: true,
secure: true
},
{hash: {absolute: 'true'}});
should.exist(rendered);
rendered.string.should.equal('https://testurl.com/qux');
rendered.string.should.equal('https://localhost:82832/qux');
});

it('should handle hosted urls with the wrong protocol in a nav context', function () {
rendered = helpers.url.call(
{url: 'https://testurl.com/quux', label: 'Quux', slug: 'quux', current: true},
{url: 'https://localhost:82832/quux', label: 'Quux', slug: 'quux', current: true},
{hash: {absolute: 'true'}});
should.exist(rendered);
rendered.string.should.equal('http://testurl.com/quux');
rendered.string.should.equal('http://localhost:82832/quux');
});

it('should pass through protocol-less URLs regardless of absolute setting', function () {
Expand Down Expand Up @@ -257,7 +257,7 @@ describe('{{url}} helper', function () {

describe('with subdir', function () {
it('external urls should be retained in a nav context with subdir', function () {
configUtils.set({url: 'http://testurl.com/blog'});
configUtils.set({url: 'http://localhost:82832/blog'});
rendered = helpers.url.call(
{url: 'http://casper.website/baz', label: 'Baz', slug: 'baz', current: true},
{hash: {absolute: 'true'}});
Expand All @@ -266,13 +266,13 @@ describe('{{url}} helper', function () {
});

it('should handle subdir being set in nav context', function () {
configUtils.set({url: 'http://testurl.com/blog'});
configUtils.set({url: 'http://localhost:82832/blog'});

rendered = helpers.url.call(
{url: '/xyzzy', label: 'xyzzy', slug: 'xyzzy', current: true},
{hash: {absolute: 'true'}});
should.exist(rendered);
rendered.string.should.equal('http://testurl.com/blog/xyzzy');
rendered.string.should.equal('http://localhost:82832/blog/xyzzy');
});
});
});

0 comments on commit be977a5

Please sign in to comment.