Ghost/ghost/core/test/unit/server/services
Simon Backx 8f8ca481a6
Fixed configUtils and adapter cache issues in E2E tests (#16167)
no issue

There are a couple of issues with resetting the Ghost instance between
E2E test files:

These issues came to the surface because of new tests written in
https://github.com/TryGhost/Ghost/pull/16117

**1. configUtils.restore does not work correctly**
`config.reset()` is a callback based method. On top of that, it doesn't
really work reliably (https://github.com/indexzero/nconf/issues/93)

What kinda happens, is that you first call `config.reset` but
immediately after you correcty reset the config using the `config.set`
calls afterwards. But since `config.reset` is async, that reset will
happen after all those sets, and the end result is that it isn't reset
correctly.

This mainly caused issues in the new updated images tests, which were
updating the config `imageOptimization.contentImageSizes`, which is a
deeply nested config value. Maybe some references to objects are reused
in nconf that cause this issue?

Wrapping `config.reset()` in a promise does fix the issue.

**2. Adapters cache not reset between tests**
At the start of each test, we set `paths:contentPath` to a nice new
temporary directory. But if a previous test already requests a
localStorage adapter, that adapter would have been created and in the
constructor `paths:contentPath` would have been passed. That same
instance will be reused in the next test run. So it won't read the new
config again. To fix this, we need to reset the adapter instances
between E2E tests.

How was this visible? Test uploads were stored in the actual git
repository, and not in a temporary directory. When writing the new image
upload tests, this also resulted in unreliable test runs because some
image names were already taken (from previous test runs).

**3. Old 2E2 test Ghost server not stopped**
Sometimes we still need access to the frontend test server using
`getAgentsWithFrontend`. But that does start a new Ghost server which is
actually listening for HTTP traffic. This could result in a fatal error
in tests because the port is already in use. The issue is that old E2E
tests also start a HTTP server, but they don't stop the server. When you
used the old `startGhost` util, it would check if a server was already
running and stop it first. The new `getAgentsWithFrontend` now also has
the same functionality to fix that issue.
2023-01-30 14:06:20 +01:00
..
adapter-manager Added JSDoc to adapter options resolver 2022-09-06 17:51:57 +08:00
api-version-compatibility Added Content-Version header to all API requests 2023-01-18 08:38:07 +01:00
auth Converted Ghost repo into a monorepo 2022-07-20 16:41:05 +02:00
custom-redirects Renamed redirects to custom-redirects 2022-09-14 13:24:17 -04:00
frontend-data-service Converted Ghost repo into a monorepo 2022-07-20 16:41:05 +02:00
link-tracking Added endpoint for fixing newsletter links 2022-10-20 17:50:02 +05:30
mail Fixed configUtils and adapter cache issues in E2E tests (#16167) 2023-01-30 14:06:20 +01:00
mega Improved email verification required checks (#16060) 2023-01-04 11:22:12 +01:00
members Fixed configUtils and adapter cache issues in E2E tests (#16167) 2023-01-30 14:06:20 +01:00
mentions Fixed RoutingService checks for resource existence 2023-01-24 18:00:52 +07:00
newsletters Converted Ghost repo into a monorepo 2022-07-20 16:41:05 +02:00
notifications Converted Ghost repo into a monorepo 2022-07-20 16:41:05 +02:00
oembed Refactored OEmbed service into a proper service 2023-01-19 18:41:49 +07:00
permissions Removed bluebird dependency from unit tests in core (#16096) 2023-01-23 11:23:48 +00:00
posts Converted Ghost repo into a monorepo 2022-07-20 16:41:05 +02:00
route-settings Converted Ghost repo into a monorepo 2022-07-20 16:41:05 +02:00
settings Added email snapshots to settings BREAD service test 2023-01-18 14:19:27 +01:00
settings-helpers Fixed configUtils and adapter cache issues in E2E tests (#16167) 2023-01-30 14:06:20 +01:00
staff Added DomainEvents.allSettled utility method (#16075) 2023-01-04 14:30:35 +01:00
stripe Fixed configUtils and adapter cache issues in E2E tests (#16167) 2023-01-30 14:06:20 +01:00
themes Added visible theme errors in admin (#16081) 2023-01-06 13:44:27 +01:00
url Fixed route update error on attach/detach events 2023-01-24 12:29:09 +08:00
users Converted Ghost repo into a monorepo 2022-07-20 16:41:05 +02:00
webhooks Converted Ghost repo into a monorepo 2022-07-20 16:41:05 +02:00
labs.test.js Fixed configUtils and adapter cache issues in E2E tests (#16167) 2023-01-30 14:06:20 +01:00
limits.test.js Fixed configUtils and adapter cache issues in E2E tests (#16167) 2023-01-30 14:06:20 +01:00
slack.test.js Fixed configUtils and adapter cache issues in E2E tests (#16167) 2023-01-30 14:06:20 +01:00
xmlrpc.test.js Fixed configUtils and adapter cache issues in E2E tests (#16167) 2023-01-30 14:06:20 +01:00