Skip to content

Commit

Permalink
Capture function coverage (#20)
Browse files Browse the repository at this point in the history
# 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
  • Loading branch information
simonrw authored Feb 8, 2024
1 parent bc1d805 commit 020e848
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 2 deletions.
2 changes: 1 addition & 1 deletion dynamodb/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { util } from '..';
import { util } from '../index.js';

// TODO: consistentRead
// TODO: projection
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"scripts": {
"test:aws": "NODE_OPTIONS=\"--experimental-vm-modules\" TEST_TARGET=AWS_CLOUD jest -u",
"test": "NODE_OPTIONS=\"--experimental-vm-modules\" jest --ci",
"evaluate": "node ./scripts/evaluate.js ./scripts/testcode.js"
"evaluate": "node ./scripts/evaluate.js ./scripts/testcode.js",
"coverage": "node --experimental-specifier-resolution=node ./scripts/coverage.mjs"
},
"repository": {
"type": "git",
Expand Down
64 changes: 64 additions & 0 deletions scripts/coverage.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { util } from '../index.js';
import * as rds from '../rds/index.js';
import * as dynamodb from '../dynamodb/index.js';

class Namespace {
constructor(name, obj) {
this.name = name;
this.obj = obj;
}
};

const partialImplementations = {
'util.appendError': {
message: "the function exists but errors are not yet captured",
},
};

// ns must be a Namespace type
function evaluateNamespace(ns) {
for (const [key, value] of Object.entries(ns.obj)) {
switch (typeof value) {
case 'function': {
const qualifiedName = `${ns.name}.${key}`;
let message = `* \`${qualifiedName}\``;
if (partialImplementations[qualifiedName] !== undefined) {
const partialDescription = partialImplementations[qualifiedName].message;
message = `${message} _(partial, ${partialDescription})_`;
} else {
};
console.log(message);
break;
};
case "object": {
const newNs = new Namespace(`${ns.name}.${key}`, value);
evaluateNamespace(newNs);
break;
};
default: {
console.error(`Unhandled type ${typeof value}`);
break;
};
}
}
}

function printImportMessage(text) {
console.log(`
Assuming the following import:
\`\`\`javascript
${text}
\`\`\`
`);
}

printImportMessage(`import { util } from '@aws-appsync/utils'`);
evaluateNamespace(new Namespace("util", util));

printImportMessage(`import * as rds from '@aws-appsync/utils/rds'`);
evaluateNamespace(new Namespace("rds", rds));

printImportMessage(`import * as dynamodb from '@aws-appsync/utils/dynamodb'`);
evaluateNamespace(new Namespace("dynamodb", dynamodb));

0 comments on commit 020e848

Please sign in to comment.