Skip to content

Conversation

sophiadt
Copy link

@sophiadt sophiadt commented Nov 21, 2024

Fix Unit Test Case01.04

test Case0.104 gave Uncaught ReferenceError: require is not defined

This is because require is a Node.js function but the package type is defined as module in package.json, so we have to use ES modules like import and export. But then Jest wouldn't be able to parse the file so JSResolverOCHTTPSTemplate, output.resolver.graphql.cjs, testLib were changed to .mjs files to mark those files as ES modules.

Changes:

  • changed JSResolverOCHTTPSTemplate, output.resolver.graphql.cjs, testLib to .mjs
  • changed imports to
import pkg from './output.resolver.graphql.js';
const {resolveGraphDBQueryFromAppSyncEvent, refactorGremlinqueryOutput} = pkg;
  • added export default { resolveGraphDBQueryFromAppSyncEvent, resolveGraphDBQueryFromApolloQueryEvent } so it works with the pkg import
  • added "type": "module", in the package.json files for Lambda4AppSyncHTTP and Lambda4AppSyncSDK in the templates folder

@sophiadt sophiadt marked this pull request as ready for review November 27, 2024 17:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants