From 020e8488ae08dcc6b5111eeef978a90adcff6b56 Mon Sep 17 00:00:00 2001 From: Simon Walker Date: Thu, 8 Feb 2024 11:32:22 +0000 Subject: [PATCH] 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 https://github.com/localstack/appsync-utils/issues/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 --- dynamodb/index.js | 2 +- package.json | 3 ++- scripts/coverage.mjs | 64 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 scripts/coverage.mjs diff --git a/dynamodb/index.js b/dynamodb/index.js index 1464ef8..e81dd35 100644 --- a/dynamodb/index.js +++ b/dynamodb/index.js @@ -1,4 +1,4 @@ -import { util } from '..'; +import { util } from '../index.js'; // TODO: consistentRead // TODO: projection diff --git a/package.json b/package.json index 49a2d09..b3c55a5 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/scripts/coverage.mjs b/scripts/coverage.mjs new file mode 100644 index 0000000..1a56966 --- /dev/null +++ b/scripts/coverage.mjs @@ -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)); +