-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Detect if new changes break existing links
Added a unit test which determines if any static links have been broken by iterating over the build output and comparing it to a snapshot of existing links. The test will fail if a page is removed and no redirect is added for it.
- Loading branch information
1 parent
fe38b85
commit 2ca57e4
Showing
7 changed files
with
101 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,3 +29,4 @@ jobs: | |
- run: yarn lint | ||
- run: yarn test | ||
- run: ./build.sh | ||
- run: yarn test:build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Vitest Snapshot v1 | ||
|
||
exports[`the build should not break any links 1`] = ` | ||
Set { | ||
"/api/api-keys", | ||
"/api/auth", | ||
"/api/data-types", | ||
"/api/http-status-codes", | ||
"/api/introduction", | ||
"/api/pagination", | ||
"/connections/farmlands", | ||
"/guides/creating-digital-tokens", | ||
"/guides/creating-test-money", | ||
"/guides/ecommerce-website", | ||
"/guides/example-oidc-consumer", | ||
"/guides/farmlands-card-partner-support", | ||
"/guides/farmlands-portal", | ||
"/guides/farmlands-pos-integration", | ||
"/guides/initiating-refunds", | ||
"/guides/integrating-third-party-asset", | ||
"/guides/line-items", | ||
"/guides/loading-and-sending-assets", | ||
"/guides/merchant-integration-barcode-flow", | ||
"/guides/merchant-integration-error-handling", | ||
"/guides/merchant-integration-qr-code-flow", | ||
"/guides/merchant-terminals", | ||
"/guides/partial-payment-extension", | ||
"/guides/patron-not-present", | ||
"/guides/payment-conditions", | ||
"/guides/payment-flows", | ||
"/guides/payment-terminals", | ||
"/guides/point-of-sale", | ||
"/guides/requesting-payment", | ||
"/guides/requesting-pre-auth", | ||
"/guides/third-party-application-payments", | ||
"/guides/transaction-reporting", | ||
"", | ||
} | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
function extractLinksRecursively(directory) { | ||
const files = fs.readdirSync(directory); | ||
let links = new Set(); | ||
for (const file of files) { | ||
const filePath = path.join(directory, file); | ||
const stat = fs.statSync(filePath); | ||
if (stat.isDirectory()) { | ||
links = new Set([...links, ...extractLinksRecursively(filePath)]); | ||
} else if (stat.isFile() && filePath.endsWith('index.html')) { | ||
const urlPath = filePath.substring(filePath.indexOf('/'), filePath.lastIndexOf('/')); | ||
links.add(urlPath); | ||
} | ||
} | ||
return links; | ||
} | ||
|
||
test('the build should not break any links', () => { | ||
expect(extractLinksRecursively('dist')).toMatchSnapshot(); | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { defineConfig } from 'vitest/config'; | ||
|
||
export default defineConfig({ | ||
test: { | ||
globals: true, | ||
include: ['src/__tests__/links.test.js'] | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3344,6 +3344,11 @@ inherits@2, inherits@^2.0.3, inherits@^2.0.4: | |
resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.4.tgz#0fa2c64f932917c3433a0ded55363aae37416b7c" | ||
integrity sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ== | ||
|
||
[email protected]: | ||
version "2.0.3" | ||
resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.3.tgz#633c2c83e3da42a502f52466022480f4208261de" | ||
integrity sha512-x00IRNXNy63jwGkJmzPigoySHbaqpNuzKbBOmzK+g2OdZpQ9w+sxCN+VSB3ja7IAge2OP2qpfxTjeNcyjmW1uw== | ||
|
||
ini@~1.3.0: | ||
version "1.3.8" | ||
resolved "https://registry.yarnpkg.com/ini/-/ini-1.3.8.tgz#a29da425b48806f34767a4efce397269af28432c" | ||
|
@@ -4743,6 +4748,14 @@ path-to-regexp@^6.2.1: | |
resolved "https://registry.yarnpkg.com/path-to-regexp/-/path-to-regexp-6.2.1.tgz#d54934d6798eb9e5ef14e7af7962c945906918e5" | ||
integrity sha512-JLyh7xT1kizaEvcaXOQwOc2/Yhw6KZOvPf1S8401UyLk86CU79LN3vl7ztXGm/pZ+YjoyAJ4rxmHwbkBXJX+yw== | ||
|
||
path@^0.12.7: | ||
version "0.12.7" | ||
resolved "https://registry.yarnpkg.com/path/-/path-0.12.7.tgz#d4dc2a506c4ce2197eb481ebfcd5b36c0140b10f" | ||
integrity sha512-aXXC6s+1w7otVF9UletFkFcDsJeO7lSZBPUQhtb5O0xJe8LtYhj/GxldoL09bBj9+ZmE2hNoHqQSFMN5fikh4Q== | ||
dependencies: | ||
process "^0.11.1" | ||
util "^0.10.3" | ||
|
||
pathe@^1.0.0: | ||
version "1.0.0" | ||
resolved "https://registry.yarnpkg.com/pathe/-/pathe-1.0.0.tgz#135fc11464fc57c84ef93d5c5ed21247e24571df" | ||
|
@@ -4937,6 +4950,11 @@ prismjs@^1.29.0: | |
resolved "https://registry.yarnpkg.com/prismjs/-/prismjs-1.29.0.tgz#f113555a8fa9b57c35e637bba27509dcf802dd12" | ||
integrity sha512-Kx/1w86q/epKcmte75LNrEoT+lX8pBpavuAbvJWRXar7Hz8jrtF+e3vY751p0R8H9HdArwaCTNDDzHg/ScJK1Q== | ||
|
||
process@^0.11.1: | ||
version "0.11.10" | ||
resolved "https://registry.yarnpkg.com/process/-/process-0.11.10.tgz#7332300e840161bda3e69a1d1d91a7d4bc16f182" | ||
integrity sha512-cdGef/drWFoydD1JsMzuFf8100nZl+GT+yacc2bEced5f9Rjk4z+WtFUTBu9PhOi9j/jfmBPu0mMEY4wIdAF8A== | ||
|
||
progress@^2.0.0: | ||
version "2.0.3" | ||
resolved "https://registry.yarnpkg.com/progress/-/progress-2.0.3.tgz#7e8cf8d8f5b8f239c1bc68beb4eb78567d572ef8" | ||
|
@@ -6033,6 +6051,13 @@ util-deprecate@^1.0.1, util-deprecate@^1.0.2: | |
resolved "https://registry.yarnpkg.com/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf" | ||
integrity sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw== | ||
|
||
util@^0.10.3: | ||
version "0.10.4" | ||
resolved "https://registry.yarnpkg.com/util/-/util-0.10.4.tgz#3aa0125bfe668a4672de58857d3ace27ecb76901" | ||
integrity sha512-0Pm9hTQ3se5ll1XihRic3FDIku70C+iHUdT/W926rSgHV5QgXsYbKZN8MSC3tJtSkhuROzvsQjAaFENRXr+19A== | ||
dependencies: | ||
inherits "2.0.3" | ||
|
||
uuid@^9.0.0: | ||
version "9.0.0" | ||
resolved "https://registry.yarnpkg.com/uuid/-/uuid-9.0.0.tgz#592f550650024a38ceb0c562f2f6aa435761efb5" | ||
|