activitypub-testing can run tests for Fediverse Enhancement Proposals. Let's use FEP-c551 as an example:
FEP-c551: Use ECMAScript Modules to Create Conformance Tests for Fediverse Enhancement Proposals is a FEP Specification by bengo. It recommends to make tests in ECMAScript aka JavaScript and publish them as ECMAScript Modules that can be easily import(url)ed by scripts in web user-agents, node.js, etc.
@bengo.is later created a FEP Test Implementation for the FEP-c551 Test in JavaScript and published activitypub-testing-fep-c551. The repo also makes the test's JavaScript file available over HTTP, and this URL is used later to instruct activitypub-testing run test to run a test from a remote URL.
activitypub-testing performs Test Runs for the FEP-c551 Test Implementation.
use activitypub-testing run test with the --url flag set to the URL to the custom test module. activitypub-testing will fetch the URL, load the test, and then apply the test to the input built from the other CLI flags.
activitypub-testing run test \
--url=https://codeberg.org/bengo/fep/raw/branch/c551-activitypub-testing/fep/c551/activitypub-testing-fep-c551/fep/c551/fep-c551-actor-object-tombstone-syntax.js \
--input.module="$(cat <<EOF
export default {
name: "sample test"
}
EOF
)"
Note: while the results below have outcome `passed`, the test is a WIP and more check will be added. The sample input here is not guranteed to always pass the test in this repo.
{
"type": [
"Assertion"
],
"result": {
"outcome": "passed"
},
"test": {
"slug": "fep-c551-module-must-export-test-object",
"name": "fep-c551 module must export test object",
"id": "urn:uuid:14bab0ae-e682-4f4c-9474-ef65ca47d527",
"requirementReference": []
},
"input": {
"module": "export default {\n name: \"sample test\"\n}"
},
"@context": [
"https://socialweb.coop/ns/testing/context.json",
"https://www.w3.org/ns/activitystreams"
]
}
Use activitypub-testing run test with the --url flag set to the URL to the custom test module. activitypub-testing will fetch the URL, load the test, and then apply the test to the input built from the other CLI flags. The test accepts an --input.module argument that expects an ECMAScript Module. We can use curl in a shell command substitution to get the URL as JavaScript and substitute that value as --input.module.
fetchECMAScriptModule() {
curl --silent -H 'Accept: text/javascript' "$1"
}
fepC551TestJsUrl='https://codeberg.org/bengo/fep/raw/branch/c551-activitypub-testing/fep/c551/activitypub-testing-fep-c551/fep/c551/fep-c551-actor-object-tombstone-syntax.js'
testFepc551ModuleUrl() {
activitypub-testing run test \
--url="$fepC551TestJsUrl" \
--input.module="$(fetchECMAScriptModule "$1")"
}
# test the fep-c551 test module for fep-c551 conformance (using itself 🙃)
testFepc551ModuleUrl $fepC551TestJsUrl
Running the above commands will output test assertions as newline delimited JSON.