Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Capture function coverage #20

Merged
merged 4 commits into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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));

Loading