From d2baf80d58362ccd4ca5b53b335b6c9c688450ab Mon Sep 17 00:00:00 2001 From: Katharina Irrgang Date: Sun, 7 Oct 2018 16:36:02 +0200 Subject: [PATCH] Optimised test folder structure (#9958) refs #9866 - test/functional/ - test/functional/api - test/functional/api/v0.1 - test/functional/api/v0.1/utils - test/functional/api/v2 - test/functional/api/v2/admin - test/functional/api/v2/admin/utils - test/functional/api/v2/content - test/functional/api/v2/content/utils - updated grunt file - instead of `grunt test-routes`, you now need to use `grunt test-functional` (docs are updated) You can use `localUtils.API.getApiQuery('posts/')` and it will generate the correct API url. --- Gruntfile.js | 21 ++++++++++++------- .../functional/{routes => }/admin_spec.js | 8 +++---- .../api => api/v0.1}/authentication_spec.js | 0 .../api => api/v0.1}/configuration_spec.js | 0 .../{routes/api => api/v0.1}/db_spec.js | 0 .../{routes/api => api/v0.1}/error_spec.js | 0 .../{routes/api => api/v0.1}/invites_spec.js | 0 .../api => api/v0.1}/notifications_spec.js | 0 .../{routes/api => api/v0.1}/oembed_spec.js | 0 .../{routes/api => api/v0.1}/posts_spec.js | 0 .../api => api/v0.1}/public_api_spec.js | 0 .../api => api/v0.1}/redirects_spec.js | 0 .../{routes/api => api/v0.1}/roles_spec.js | 0 .../api => api/v0.1}/schedules_spec.js | 0 .../{routes/api => api/v0.1}/settings_spec.js | 0 .../{routes/api => api/v0.1}/slugs_spec.js | 0 .../api => api/v0.1}/spam_prevention_spec.js | 0 .../api => api/v0.1}/subscribers_spec.js | 0 .../{routes/api => api/v0.1}/tags_spec.js | 0 .../{routes/api => api/v0.1}/themes_spec.js | 0 .../api => api/v0.1}/upload_icon_spec.js | 0 .../{routes/api => api/v0.1}/upload_spec.js | 0 .../{routes/api => api/v0.1}/users_spec.js | 0 .../{routes/api => api/v0.1}/utils.js | 0 .../{routes/api => api/v0.1}/webhooks_spec.js | 0 core/test/functional/api/v2/admin/utils.js | 11 ++++++++++ core/test/functional/api/v2/content/utils.js | 11 ++++++++++ .../apps/subscribers/routing_spec.js | 6 +++--- .../{routes => }/dynamic_routing_spec.js | 8 +++---- .../functional/{routes => }/frontend_spec.js | 8 +++---- .../services/url/UrlService_spec.js | 2 +- .../unit/services/settings/settings_spec.js | 2 +- 32 files changed, 52 insertions(+), 25 deletions(-) rename core/test/functional/{routes => }/admin_spec.js (95%) rename core/test/functional/{routes/api => api/v0.1}/authentication_spec.js (100%) rename core/test/functional/{routes/api => api/v0.1}/configuration_spec.js (100%) rename core/test/functional/{routes/api => api/v0.1}/db_spec.js (100%) rename core/test/functional/{routes/api => api/v0.1}/error_spec.js (100%) rename core/test/functional/{routes/api => api/v0.1}/invites_spec.js (100%) rename core/test/functional/{routes/api => api/v0.1}/notifications_spec.js (100%) rename core/test/functional/{routes/api => api/v0.1}/oembed_spec.js (100%) rename core/test/functional/{routes/api => api/v0.1}/posts_spec.js (100%) rename core/test/functional/{routes/api => api/v0.1}/public_api_spec.js (100%) rename core/test/functional/{routes/api => api/v0.1}/redirects_spec.js (100%) rename core/test/functional/{routes/api => api/v0.1}/roles_spec.js (100%) rename core/test/functional/{routes/api => api/v0.1}/schedules_spec.js (100%) rename core/test/functional/{routes/api => api/v0.1}/settings_spec.js (100%) rename core/test/functional/{routes/api => api/v0.1}/slugs_spec.js (100%) rename core/test/functional/{routes/api => api/v0.1}/spam_prevention_spec.js (100%) rename core/test/functional/{routes/api => api/v0.1}/subscribers_spec.js (100%) rename core/test/functional/{routes/api => api/v0.1}/tags_spec.js (100%) rename core/test/functional/{routes/api => api/v0.1}/themes_spec.js (100%) rename core/test/functional/{routes/api => api/v0.1}/upload_icon_spec.js (100%) rename core/test/functional/{routes/api => api/v0.1}/upload_spec.js (100%) rename core/test/functional/{routes/api => api/v0.1}/users_spec.js (100%) rename core/test/functional/{routes/api => api/v0.1}/utils.js (100%) rename core/test/functional/{routes/api => api/v0.1}/webhooks_spec.js (100%) create mode 100644 core/test/functional/api/v2/admin/utils.js create mode 100644 core/test/functional/api/v2/content/utils.js rename core/test/functional/{routes => }/apps/subscribers/routing_spec.js (95%) rename core/test/functional/{routes => }/dynamic_routing_spec.js (99%) rename core/test/functional/{routes => }/frontend_spec.js (99%) diff --git a/Gruntfile.js b/Gruntfile.js index 29a4ff84b7..6fd2966c66 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -158,10 +158,10 @@ var config = require('./core/server/config'), ] }, - // #### All Route tests - routes: { + // #### All functional tests + functional: { src: [ - 'core/test/functional/routes/**/*_spec.js' + 'core/test/functional/**/*_spec.js' ] }, @@ -512,7 +512,7 @@ var config = require('./core/server/config'), // `grunt test-all` will lint and test your pre-built local Ghost codebase. // grunt.registerTask('test-all', 'Run all server tests', - ['test-routes', 'test-unit', 'test-integration']); + ['test-functional', 'test-unit', 'test-integration']); // ### Lint // @@ -575,11 +575,11 @@ var config = require('./core/server/config'), ); // ### Route tests *(sub task)* - // `grunt test-routes` will run just the route tests + // `grunt test-functional` will run just the route tests // // If you need to run an individual route test file, you can use the `grunt test:` task: // - // `grunt test:functional/routes/admin_spec.js` + // `grunt test:functional/admin_spec.js` // // Route tests are run with [mocha](http://mochajs.org/) using // [should](https://github.com/visionmedia/should.js) and [supertest](https://github.com/visionmedia/supertest) @@ -591,8 +591,13 @@ var config = require('./core/server/config'), // The purpose of the route tests is to ensure that all of the routes (pages, and API requests) in Ghost // are working as expected, including checking the headers and status codes received. It is very easy and // quick to test many permutations of routes / urls in the system. - grunt.registerTask('test-routes', 'Run functional route tests (mocha)', - ['test-setup', 'mochacli:routes'] + grunt.registerTask('test-functional', 'Run functional tests (mocha)', + ['test-setup', 'mochacli:functional'] + ); + + // Shortcut + grunt.registerTask('test-func', 'Run functional tests (mocha)', + ['test-setup', 'mochacli:functional'] ); // ### Coverage diff --git a/core/test/functional/routes/admin_spec.js b/core/test/functional/admin_spec.js similarity index 95% rename from core/test/functional/routes/admin_spec.js rename to core/test/functional/admin_spec.js index 842432d560..0d8b5a0dc6 100644 --- a/core/test/functional/routes/admin_spec.js +++ b/core/test/functional/admin_spec.js @@ -5,11 +5,11 @@ var should = require('should'), supertest = require('supertest'), - testUtils = require('../../utils'), - configUtils = require('../../utils/configUtils'), + testUtils = require('../utils'), + configUtils = require('../utils/configUtils'), ghost = testUtils.startGhost, - common = require('../../../server/lib/common'), - config = require('../../../../core/server/config'), + common = require('../../server/lib/common'), + config = require('../../server/config'), request; common.i18n.init(); diff --git a/core/test/functional/routes/api/authentication_spec.js b/core/test/functional/api/v0.1/authentication_spec.js similarity index 100% rename from core/test/functional/routes/api/authentication_spec.js rename to core/test/functional/api/v0.1/authentication_spec.js diff --git a/core/test/functional/routes/api/configuration_spec.js b/core/test/functional/api/v0.1/configuration_spec.js similarity index 100% rename from core/test/functional/routes/api/configuration_spec.js rename to core/test/functional/api/v0.1/configuration_spec.js diff --git a/core/test/functional/routes/api/db_spec.js b/core/test/functional/api/v0.1/db_spec.js similarity index 100% rename from core/test/functional/routes/api/db_spec.js rename to core/test/functional/api/v0.1/db_spec.js diff --git a/core/test/functional/routes/api/error_spec.js b/core/test/functional/api/v0.1/error_spec.js similarity index 100% rename from core/test/functional/routes/api/error_spec.js rename to core/test/functional/api/v0.1/error_spec.js diff --git a/core/test/functional/routes/api/invites_spec.js b/core/test/functional/api/v0.1/invites_spec.js similarity index 100% rename from core/test/functional/routes/api/invites_spec.js rename to core/test/functional/api/v0.1/invites_spec.js diff --git a/core/test/functional/routes/api/notifications_spec.js b/core/test/functional/api/v0.1/notifications_spec.js similarity index 100% rename from core/test/functional/routes/api/notifications_spec.js rename to core/test/functional/api/v0.1/notifications_spec.js diff --git a/core/test/functional/routes/api/oembed_spec.js b/core/test/functional/api/v0.1/oembed_spec.js similarity index 100% rename from core/test/functional/routes/api/oembed_spec.js rename to core/test/functional/api/v0.1/oembed_spec.js diff --git a/core/test/functional/routes/api/posts_spec.js b/core/test/functional/api/v0.1/posts_spec.js similarity index 100% rename from core/test/functional/routes/api/posts_spec.js rename to core/test/functional/api/v0.1/posts_spec.js diff --git a/core/test/functional/routes/api/public_api_spec.js b/core/test/functional/api/v0.1/public_api_spec.js similarity index 100% rename from core/test/functional/routes/api/public_api_spec.js rename to core/test/functional/api/v0.1/public_api_spec.js diff --git a/core/test/functional/routes/api/redirects_spec.js b/core/test/functional/api/v0.1/redirects_spec.js similarity index 100% rename from core/test/functional/routes/api/redirects_spec.js rename to core/test/functional/api/v0.1/redirects_spec.js diff --git a/core/test/functional/routes/api/roles_spec.js b/core/test/functional/api/v0.1/roles_spec.js similarity index 100% rename from core/test/functional/routes/api/roles_spec.js rename to core/test/functional/api/v0.1/roles_spec.js diff --git a/core/test/functional/routes/api/schedules_spec.js b/core/test/functional/api/v0.1/schedules_spec.js similarity index 100% rename from core/test/functional/routes/api/schedules_spec.js rename to core/test/functional/api/v0.1/schedules_spec.js diff --git a/core/test/functional/routes/api/settings_spec.js b/core/test/functional/api/v0.1/settings_spec.js similarity index 100% rename from core/test/functional/routes/api/settings_spec.js rename to core/test/functional/api/v0.1/settings_spec.js diff --git a/core/test/functional/routes/api/slugs_spec.js b/core/test/functional/api/v0.1/slugs_spec.js similarity index 100% rename from core/test/functional/routes/api/slugs_spec.js rename to core/test/functional/api/v0.1/slugs_spec.js diff --git a/core/test/functional/routes/api/spam_prevention_spec.js b/core/test/functional/api/v0.1/spam_prevention_spec.js similarity index 100% rename from core/test/functional/routes/api/spam_prevention_spec.js rename to core/test/functional/api/v0.1/spam_prevention_spec.js diff --git a/core/test/functional/routes/api/subscribers_spec.js b/core/test/functional/api/v0.1/subscribers_spec.js similarity index 100% rename from core/test/functional/routes/api/subscribers_spec.js rename to core/test/functional/api/v0.1/subscribers_spec.js diff --git a/core/test/functional/routes/api/tags_spec.js b/core/test/functional/api/v0.1/tags_spec.js similarity index 100% rename from core/test/functional/routes/api/tags_spec.js rename to core/test/functional/api/v0.1/tags_spec.js diff --git a/core/test/functional/routes/api/themes_spec.js b/core/test/functional/api/v0.1/themes_spec.js similarity index 100% rename from core/test/functional/routes/api/themes_spec.js rename to core/test/functional/api/v0.1/themes_spec.js diff --git a/core/test/functional/routes/api/upload_icon_spec.js b/core/test/functional/api/v0.1/upload_icon_spec.js similarity index 100% rename from core/test/functional/routes/api/upload_icon_spec.js rename to core/test/functional/api/v0.1/upload_icon_spec.js diff --git a/core/test/functional/routes/api/upload_spec.js b/core/test/functional/api/v0.1/upload_spec.js similarity index 100% rename from core/test/functional/routes/api/upload_spec.js rename to core/test/functional/api/v0.1/upload_spec.js diff --git a/core/test/functional/routes/api/users_spec.js b/core/test/functional/api/v0.1/users_spec.js similarity index 100% rename from core/test/functional/routes/api/users_spec.js rename to core/test/functional/api/v0.1/users_spec.js diff --git a/core/test/functional/routes/api/utils.js b/core/test/functional/api/v0.1/utils.js similarity index 100% rename from core/test/functional/routes/api/utils.js rename to core/test/functional/api/v0.1/utils.js diff --git a/core/test/functional/routes/api/webhooks_spec.js b/core/test/functional/api/v0.1/webhooks_spec.js similarity index 100% rename from core/test/functional/routes/api/webhooks_spec.js rename to core/test/functional/api/v0.1/webhooks_spec.js diff --git a/core/test/functional/api/v2/admin/utils.js b/core/test/functional/api/v2/admin/utils.js new file mode 100644 index 0000000000..4eb5611608 --- /dev/null +++ b/core/test/functional/api/v2/admin/utils.js @@ -0,0 +1,11 @@ +const url = require('url'); +const _ = require('lodash'); +const API_URL = '/ghost/api/v2/admin/'; + +module.exports = { + API: { + getApiQuery(route) { + return url.resolve(API_URL, route); + } + } +}; diff --git a/core/test/functional/api/v2/content/utils.js b/core/test/functional/api/v2/content/utils.js new file mode 100644 index 0000000000..7094fdd41f --- /dev/null +++ b/core/test/functional/api/v2/content/utils.js @@ -0,0 +1,11 @@ +const url = require('url'); +const _ = require('lodash'); +const API_URL = '/ghost/api/v2/content/'; + +module.exports = { + API: { + getApiQuery(route) { + return url.resolve(API_URL, route); + } + } +}; diff --git a/core/test/functional/routes/apps/subscribers/routing_spec.js b/core/test/functional/apps/subscribers/routing_spec.js similarity index 95% rename from core/test/functional/routes/apps/subscribers/routing_spec.js rename to core/test/functional/apps/subscribers/routing_spec.js index ea62867c7a..8665b9b05f 100644 --- a/core/test/functional/routes/apps/subscribers/routing_spec.js +++ b/core/test/functional/apps/subscribers/routing_spec.js @@ -1,9 +1,9 @@ var supertest = require('supertest'), should = require('should'), sinon = require('sinon'), - testUtils = require('../../../../utils'), - labs = require('../../../../../server/services/labs'), - config = require('../../../../../server/config'), + testUtils = require('../../../utils'), + labs = require('../../../../server/services/labs'), + config = require('../../../../server/config'), ghost = testUtils.startGhost, sandbox = sinon.sandbox.create(); diff --git a/core/test/functional/routes/dynamic_routing_spec.js b/core/test/functional/dynamic_routing_spec.js similarity index 99% rename from core/test/functional/routes/dynamic_routing_spec.js rename to core/test/functional/dynamic_routing_spec.js index 6169497bd2..66eed007a5 100644 --- a/core/test/functional/routes/dynamic_routing_spec.js +++ b/core/test/functional/dynamic_routing_spec.js @@ -7,11 +7,11 @@ const should = require('should'), sinon = require('sinon'), moment = require('moment'), path = require('path'), - testUtils = require('../../utils'), + testUtils = require('../utils'), cheerio = require('cheerio'), - config = require('../../../../core/server/config'), - api = require('../../../server/api'), - settingsCache = require('../../../server/services/settings/cache'), + config = require('../../server/config'), + api = require('../../server/api'), + settingsCache = require('../../server/services/settings/cache'), ghost = testUtils.startGhost, sandbox = sinon.sandbox.create(); diff --git a/core/test/functional/routes/frontend_spec.js b/core/test/functional/frontend_spec.js similarity index 99% rename from core/test/functional/routes/frontend_spec.js rename to core/test/functional/frontend_spec.js index 630586e7f4..c5576c4ad6 100644 --- a/core/test/functional/routes/frontend_spec.js +++ b/core/test/functional/frontend_spec.js @@ -8,10 +8,10 @@ var should = require('should'), moment = require('moment'), cheerio = require('cheerio'), _ = require('lodash'), - testUtils = require('../../utils'), - configUtils = require('../../utils/configUtils'), - config = require('../../../server/config'), - settingsCache = require('../../../server/services/settings/cache'), + testUtils = require('../utils'), + configUtils = require('../utils/configUtils'), + config = require('../../server/config'), + settingsCache = require('../../server/services/settings/cache'), origCache = _.cloneDeep(settingsCache), ghost = testUtils.startGhost, request, diff --git a/core/test/integration/services/url/UrlService_spec.js b/core/test/integration/services/url/UrlService_spec.js index 92725e9cf3..f6286b3283 100644 --- a/core/test/integration/services/url/UrlService_spec.js +++ b/core/test/integration/services/url/UrlService_spec.js @@ -2,7 +2,7 @@ const _ = require('lodash'); const should = require('should'); const sinon = require('sinon'); const rewire = require('rewire'); -const testUtils = require('../../../utils/index'); +const testUtils = require('../../../utils'); const configUtils = require('../../../utils/configUtils'); const models = require('../../../../server/models'); const common = require('../../../../server/lib/common'); diff --git a/core/test/unit/services/settings/settings_spec.js b/core/test/unit/services/settings/settings_spec.js index e4eacbafa4..0b923146e3 100644 --- a/core/test/unit/services/settings/settings_spec.js +++ b/core/test/unit/services/settings/settings_spec.js @@ -2,7 +2,7 @@ const sinon = require('sinon'), should = require('should'), rewire = require('rewire'), common = require('../../../../server/lib/common'), - settings = rewire('../../../../server/services/settings/index'), + settings = rewire('../../../../server/services/settings'), sandbox = sinon.sandbox.create(); describe('UNIT > Settings Service:', function () {