Skip to content

Commit

Permalink
Abstracted a hacky local URL matcher
Browse files Browse the repository at this point in the history
refs https://github.com/TryGhost/Toolbox/issues/320

- The URL matcher is very likely to be reused in the future, so having it abstracted away gives two benefits:
1. Central place to document hacky behavior and easier future cleanup
2. The implementer of the e2e test does not have to see the "hacky note" and just concentrate on the implementation of the test
  • Loading branch information
naz committed Oct 5, 2022
1 parent d817e58 commit 320c6e0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 2 additions & 4 deletions ghost/core/test/e2e-webhooks/posts.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const {agentProvider, mockManager, fixtureManager, matchers} = require('../utils/e2e-framework');
const {anyObjectId, anyISODateTime, anyUuid, anyContentVersion, anyNumber, stringMatching} = matchers;
const {anyObjectId, anyISODateTime, anyUuid, anyContentVersion, anyNumber, anyLocalURL} = matchers;

const tierSnapshot = {
id: anyObjectId,
Expand Down Expand Up @@ -35,9 +35,7 @@ const buildPostSnapshotWithTiers = ({published, tiersCount, roles = false}) => {
published_at: published ? anyISODateTime : null,
created_at: anyISODateTime,
updated_at: anyISODateTime,
// @TODO: hack here! it's due to https://github.com/TryGhost/Toolbox/issues/341
// this matcher should be removed once the issue is solved
url: stringMatching(/http:\/\/127.0.0.1:2369\/\w+\//),
url: anyLocalURL,
tiers: new Array(tiersCount).fill(tierSnapshot),
primary_author: buildAuthorSnapshot(roles),
authors: new Array(1).fill(buildAuthorSnapshot(roles))
Expand Down
4 changes: 4 additions & 0 deletions ghost/core/test/utils/e2e-framework.js
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,10 @@ module.exports = {
anyLocationFor: (resource) => {
return stringMatching(new RegExp(`https?://.*?/${resource}/[a-f0-9]{24}/`));
},
// @NOTE: hack here! it's due to https://github.com/TryGhost/Toolbox/issues/341
// this matcher should be removed once the issue is solved - routing is redesigned
// An ideal solution would be removal of this matcher altogether.
anyLocalURL: stringMatching(/http:\/\/127.0.0.1:2369\/\w+\//),
stringMatching
},

Expand Down

0 comments on commit 320c6e0

Please sign in to comment.