# activitypub-testing + FEP-c551

&horbar;[bengo][]

## Contents

* [Context](#context)
* [Running the FEP-c551 Test on an ECMAScript Module string](#running-the-fep-c551-test-on-an-ecmascript-module-string)
* [Running the FEP-c551 Test on an ECMAScript Module string fetched via curl](#running-the-fep-c551-test-on-an-ecmascript-module-string-fetched-via-curl)
    * [testing module from test implementation activitypub-testing-fep-c551](#testing-module-from-test-implementation-activitypub-testing-fep-c551)

## Context

`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](https://codeberg.org/bengo/fep/pulls/1) 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](https://codeberg.org/bengo/fep/pulls/2). The repo also makes the test's JavaScript file [available over HTTP](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), and this URL is used later to instruct `activitypub-testing run test` to run a test from a remote URL.

`activitypub-testing` performs **Test Run**s for the FEP-c551 Test Implementation.

## Running the FEP-c551 Test on an ECMAScript Module string

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.

```shell
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
)"
```

<details>
  <summary>show output</summary>
  <p>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.</p>
  <pre>
{
  "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"
  ]
}
</pre>
</details>

## Running the FEP-c551 Test on an ECMAScript Module string fetched via curl

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](https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_03) to get the URL as JavaScript and substitute that value as `--input.module`.

### testing module from test implementation activitypub-testing-fep-c551

```shell
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.

<!-- links for markdown above -->

[bengo]: https://bengo.is
