Skip to content

Commit 020e848

Browse files
authored
Capture function coverage (#20)
# Motivation We should be transparent about which functions are covered and which aren't. This helps our users understand our current status, and indicate that we are not 100% complete with our implementation. To aid with this process, I have created #19 which lists the functions we support, and encourage users to list/upvote their suggestions. In turn, to support this I have added a script to capture the functions we implement, and to print them out to the console. We may automate this procedure in the process if it gets too arduous. The example output from this script can be seen in the ["Currently implemented functions"](https://github.com/localstack/appsync-utils/issues/19#user-content-#currently-implemented-functions) section of the linked issue. # Changes * Add script to capture feature coverage by introspecting the utilities library. * Fix a relative import issue when using the script
1 parent bc1d805 commit 020e848

File tree

3 files changed

+67
-2
lines changed

3 files changed

+67
-2
lines changed

dynamodb/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { util } from '..';
1+
import { util } from '../index.js';
22

33
// TODO: consistentRead
44
// TODO: projection

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
"scripts": {
88
"test:aws": "NODE_OPTIONS=\"--experimental-vm-modules\" TEST_TARGET=AWS_CLOUD jest -u",
99
"test": "NODE_OPTIONS=\"--experimental-vm-modules\" jest --ci",
10-
"evaluate": "node ./scripts/evaluate.js ./scripts/testcode.js"
10+
"evaluate": "node ./scripts/evaluate.js ./scripts/testcode.js",
11+
"coverage": "node --experimental-specifier-resolution=node ./scripts/coverage.mjs"
1112
},
1213
"repository": {
1314
"type": "git",

scripts/coverage.mjs

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import { util } from '../index.js';
2+
import * as rds from '../rds/index.js';
3+
import * as dynamodb from '../dynamodb/index.js';
4+
5+
class Namespace {
6+
constructor(name, obj) {
7+
this.name = name;
8+
this.obj = obj;
9+
}
10+
};
11+
12+
const partialImplementations = {
13+
'util.appendError': {
14+
message: "the function exists but errors are not yet captured",
15+
},
16+
};
17+
18+
// ns must be a Namespace type
19+
function evaluateNamespace(ns) {
20+
for (const [key, value] of Object.entries(ns.obj)) {
21+
switch (typeof value) {
22+
case 'function': {
23+
const qualifiedName = `${ns.name}.${key}`;
24+
let message = `* \`${qualifiedName}\``;
25+
if (partialImplementations[qualifiedName] !== undefined) {
26+
const partialDescription = partialImplementations[qualifiedName].message;
27+
message = `${message} _(partial, ${partialDescription})_`;
28+
} else {
29+
};
30+
console.log(message);
31+
break;
32+
};
33+
case "object": {
34+
const newNs = new Namespace(`${ns.name}.${key}`, value);
35+
evaluateNamespace(newNs);
36+
break;
37+
};
38+
default: {
39+
console.error(`Unhandled type ${typeof value}`);
40+
break;
41+
};
42+
}
43+
}
44+
}
45+
46+
function printImportMessage(text) {
47+
console.log(`
48+
Assuming the following import:
49+
50+
\`\`\`javascript
51+
${text}
52+
\`\`\`
53+
`);
54+
}
55+
56+
printImportMessage(`import { util } from '@aws-appsync/utils'`);
57+
evaluateNamespace(new Namespace("util", util));
58+
59+
printImportMessage(`import * as rds from '@aws-appsync/utils/rds'`);
60+
evaluateNamespace(new Namespace("rds", rds));
61+
62+
printImportMessage(`import * as dynamodb from '@aws-appsync/utils/dynamodb'`);
63+
evaluateNamespace(new Namespace("dynamodb", dynamodb));
64+

0 commit comments

Comments
 (0)