Skip to content

Commit 8749150

Browse files
authoredMay 24, 2021
Jest-did-matcher matcher message cleanup (#124)
* Jest-did-matcher matcher message cleanup Also added a test case to DID URL matcher. * Added how to read jest error messages in READMEs
1 parent 49a4b9c commit 8749150

File tree

15 files changed

+48
-37
lines changed

15 files changed

+48
-37
lines changed
 

‎README.md

+4
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ npm i
4242
npm run generate-report
4343
```
4444

45+
## If tests are failing
46+
47+
- Every time after updating any code, run `npm i`.
48+
- Please refer to [When you observe errors section in packages/did-core-test-server/README.md](packages/did-core-test-server/README.md#when-you-observe-errors)
4549
## DID Working Group Repositories
4650

4751
- [W3C Decentralized Identifier Specification v1.0](https://github.com/w3c/did-core)

‎packages/did-core-test-server/README.md

+30
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,33 @@ npm run docker:build
5757
npm run docker:publish
5858
npm run docker:run
5959
```
60+
61+
## When you observe errors
62+
63+
- Run `npm i` at the top level of this repository. Running `npm i` guarantees every test code to build.
64+
- Run `npm test` in `packages/did-core-test-server` directory.
65+
This way of test run will show detailed tests run. For example, the intentional change to 'did:' to 'did/' for example implementation cause this error:
66+
67+
```
68+
● suites/did-identifier › IMPLEMENTATION ::DID Test Suite:: › 3.x Identifier - did:example - DID Test Suite - DID Working Group › 3.1 DID Syntax › did/example:123 › 3.1 DID Syntax - All DIDs MUST conform to the DID Syntax ABNF Rules.
69+
70+
expect(received).toBeValidDid()
71+
72+
Expected value to be of valid DID, but received:
73+
"did/example:123"
74+
75+
7 | it('3.1 DID Syntax - All DIDs MUST conform to the DID Syntax ' +
76+
8 | 'ABNF Rules.', async () => {
77+
> 9 | expect(didExample).toBeValidDid();
78+
| ^
79+
10 | });
80+
11 | });
81+
12 | });
82+
83+
at Object.<anonymous> (suites/did-identifier/did-syntax.js:9:30)
84+
```
85+
86+
- The first line begins with `●` (shown in red, if you didn't change test framework(jest) configuration). This descriptive text includes the name of test suites, the name of the implementation (marked IMPLEMENTATION), and the DID or DID URL (begins with `did:`) for the test, and also the section number of the DID core specification relates to the test.
87+
- The second line shows how a test matcher (a test code idiom) applied.
88+
- The third line shows the reason for the error, the value in question (received value), and possibly an expected value.
89+
- If there are any errors in the test code itself, the second line may be a JavaScript error (E.g., `TypeError: Cannot read property '...' of undefined`). If this happens or found any anomalies, please open an issue at [ did-test-suite GitHub repository](https://github.com/w3c/did-test-suite/issues).

‎packages/jest-did-matcher/src/matchers/toBeAsciiString/index.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ const passMessage = received => () =>
1010
const failMessage = received => () =>
1111
matcherHint('.toBeAsciiString', 'received', '') +
1212
'\n\n' +
13-
'Expected value to be of type INFRA string:\n' +
14-
` ${printExpected('type of INFRA string')}` +
15-
'Received:\n' +
13+
'Expected value to be of type INFRA string, but received:\n' +
1614
` ${printReceived(received)}`;
1715

1816
export default {

‎packages/jest-did-matcher/src/matchers/toBeBase58String/index.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ const passMessage = received => () =>
1010
const failMessage = received => () =>
1111
matcherHint('.toBeBase58String', 'received', '') +
1212
'\n\n' +
13-
'Expected value to be of a Base58 string:\n' +
14-
` ${printExpected('a Base 58 string')}` +
15-
'Received:\n' +
13+
'Expected value to be of a Base58 string, but received:\n' +
1614
` ${printReceived(received)}`;
1715

1816
export default {

‎packages/jest-did-matcher/src/matchers/toBeDidCoreDatetime/index.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ const passMessage = received => () =>
1010
const failMessage = received => () =>
1111
matcherHint('.toBeDidCoreDatetime', 'received', '') +
1212
'\n\n' +
13-
'Expected value to be of a valid DID Core Datetime:\n' +
14-
` ${printExpected('a valid DID Core Datetime')}\n` +
15-
'Received:\n' +
13+
'Expected value to be of a valid DID Core Datetime, but received:\n' +
1614
` ${printReceived(received)}`;
1715

1816
export default {

‎packages/jest-did-matcher/src/matchers/toBeDidDocumentPropertyValueType/index.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ const passMessage = received => () =>
1010
const failMessage = received => () =>
1111
matcherHint('.toBeDidDocumentPropertyValueType', 'received', '') +
1212
'\n\n' +
13-
'Expected value to be of type allowed in DID Document:\n' +
14-
` ${printExpected('value type allowed in DID Document')}\n` +
15-
'Received:\n' +
13+
'Expected value to be of type allowed in DID Document, but received:\n' +
1614
` ${printReceived(received)}`;
1715

1816
export default {

‎packages/jest-did-matcher/src/matchers/toBeInfraMap/index.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ const passMessage = received => () =>
1010
const failMessage = received => () =>
1111
matcherHint('.toBeInfraMap', 'received', '') +
1212
'\n\n' +
13-
'Expected value to be of type INFRA map:\n' +
14-
` ${printExpected('type of INFRA map')}` +
15-
'Received:\n' +
13+
'Expected value to be of type INFRA map, but received:\n' +
1614
` ${printReceived(received)}`;
1715

1816
export default {

‎packages/jest-did-matcher/src/matchers/toBeInfraString/index.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ const passMessage = received => () =>
1010
const failMessage = received => () =>
1111
matcherHint('.toBeInfraString', 'received', '') +
1212
'\n\n' +
13-
'Expected value to be of type INFRA string:\n' +
14-
` ${printExpected('type of INFRA string')}` +
15-
'Received:\n' +
13+
'Expected value to be of type INFRA string, but received:\n' +
1614
` ${printReceived(received)}`;
1715

1816
export default {

‎packages/jest-did-matcher/src/matchers/toBeMediaType/index.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ const passMessage = received => () =>
1010
const failMessage = received => () =>
1111
matcherHint('.toBeMediaType', 'received', '') +
1212
'\n\n' +
13-
'Expected value to be of a valid Media Type:\n' +
14-
` ${printExpected('a valid Media Type')}` +
15-
'Received:\n' +
13+
'Expected value to be of a valid Media Type, but received:\n' +
1614
` ${printReceived(received)}`;
1715

1816
export default {

‎packages/jest-did-matcher/src/matchers/toBeMultibaseString/index.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ const passMessage = received => () =>
1010
const failMessage = received => () =>
1111
matcherHint('.toBeMultibaseString', 'received', '') +
1212
'\n\n' +
13-
'Expected value to be a Multibase string:\n' +
14-
` ${printExpected('a Multibase string')}` +
15-
'Received:\n' +
13+
'Expected value to be a Multibase string, but received:\n' +
1614
` ${printReceived(received)}`;
1715

1816
export default {

‎packages/jest-did-matcher/src/matchers/toBeValidDid/index.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ const passMessage = received => () =>
1010
const failMessage = received => () =>
1111
matcherHint('.toBeValidDid', 'received', '') +
1212
'\n\n' +
13-
'Expected value to be of valid DID:\n' +
14-
` ${printExpected('DID')}` +
15-
'Received:\n' +
13+
'Expected value to be of valid DID, but received:\n' +
1614
` ${printReceived(received)}`;
1715

1816
export default {

‎packages/jest-did-matcher/src/matchers/toBeValidDidUrl/index.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,13 @@ import predicate from './predicate';
44
const passMessage = received => () =>
55
matcherHint('.not.toBeValidDidUrl', 'received', '') +
66
'\n\n' +
7-
'Expected value to not be of valid DID URL received:\n' +
7+
'Expected value not to be a valid DID URL received:\n' +
88
` ${printReceived(received)}`;
99

1010
const failMessage = received => () =>
1111
matcherHint('.toBeValidDidUrl', 'received', '') +
1212
'\n\n' +
13-
'Expected value to be of valid DID URL:\n' +
14-
` ${printExpected('DID URL')}` +
15-
'Received:\n' +
13+
'Expected value to be a valid DID URL, but received:\n' +
1614
` ${printReceived(received)}`;
1715

1816
export default {

‎packages/jest-did-matcher/src/matchers/toBeValidDidUrl/index.test.js

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ describe('.toBeValidDidUrl', () => {
1515
["did:example:123456/path%20with%20space"],
1616
["did:example:123456?versionId=1"],
1717
["did:example:123#public-key-0"],
18+
["did:example:123#sig_064bebcc"],
1819
["did:example:123?service=agent&relativeRef=/credentials#degree"]
1920
]).test('passes when the item is a valid DID: %s', given => {
2021
expect(given).toBeValidDidUrl();

‎packages/jest-did-matcher/src/matchers/toBeValidUri/index.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ const passMessage = received => () =>
1010
const failMessage = received => () =>
1111
matcherHint('.toBeValidUri', 'received', '') +
1212
'\n\n' +
13-
'Expected value to be of a valid URI:\n' +
14-
` ${printExpected('a valid Uri')}` +
15-
'Received:\n' +
13+
'Expected value to be of a valid URI, but received:\n' +
1614
` ${printReceived(received)}`;
1715

1816
export default {

‎packages/jest-did-matcher/src/matchers/toBeValidUrl/index.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ const passMessage = received => () =>
1010
const failMessage = received => () =>
1111
matcherHint('.toBeValidUrl', 'received', '') +
1212
'\n\n' +
13-
'Expected value to be of a valid URL:\n' +
14-
` ${printExpected('a valid URL')}` +
15-
'Received:\n' +
13+
'Expected value to be of a valid URL, but received:\n' +
1614
` ${printReceived(received)}`;
1715

1816
export default {

0 commit comments

Comments
 (0)
Please sign in to comment.