diff --git a/__tests__/__snapshots__/index.test.js.snap b/__tests__/__snapshots__/index.test.js.snap index 903e6c5..54ac0ad 100644 --- a/__tests__/__snapshots__/index.test.js.snap +++ b/__tests__/__snapshots__/index.test.js.snap @@ -1,4 +1,4 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP +// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing exports[`DynamoDB module functions get 1`] = ` { diff --git a/__tests__/__snapshots__/resolvers.test.js.snap b/__tests__/__snapshots__/resolvers.test.js.snap index d7d35b3..4982c6f 100644 --- a/__tests__/__snapshots__/resolvers.test.js.snap +++ b/__tests__/__snapshots__/resolvers.test.js.snap @@ -1,4 +1,4 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP +// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing exports[`dynamodb resolvers something 1`] = ` { diff --git a/__tests__/helpers.js b/__tests__/helpers.js index d336964..092558a 100644 --- a/__tests__/helpers.js +++ b/__tests__/helpers.js @@ -1,10 +1,16 @@ "use strict"; +import { fileURLToPath, pathToFileURL } from "url"; +import { dirname, resolve } from "path"; import { AppSyncClient, EvaluateCodeCommand } from "@aws-sdk/client-appsync"; import { util } from ".."; import * as ddb from "../dynamodb"; import * as rds from "../rds"; +const __filename = fileURLToPath(import.meta.url); +const __dirname = dirname(__filename); +const projectRoot = resolve(__dirname, ".."); + let client = null; const runResolverFunctionOnAWS = async (code, context, functionName) => { @@ -65,8 +71,8 @@ export const checkResolverValid = async (code, context, functionName) => { result = await runResolverFunctionOnAWS(fullCode, context, functionName); } else { const fullCode = ` - import { util } from '..'; - import * as rds from '../rds'; + import { util } from '${pathToFileURL(resolve(projectRoot, "index.js"))}'; + import * as rds from '${pathToFileURL(resolve(projectRoot, "rds/index.js"))}'; ` + code; const encodedJs = encodeURIComponent(fullCode); const dataUri = 'data:text/javascript;charset=utf-8,' + encodedJs; diff --git a/__tests__/index.test.js b/__tests__/index.test.js index 7f210d4..b160e01 100644 --- a/__tests__/index.test.js +++ b/__tests__/index.test.js @@ -17,22 +17,21 @@ describe("general utilities", () => { }); describe("time utilities", () => { + afterEach(() => { + jest.useRealTimers(); + }); + test("nowFormatted", async () => { - // patch date utilities to ensure consistency - const newDate = new Date(2021, 1, 1); - const spied = jest.spyOn(global, 'Date').mockImplementation(() => newDate); + jest.useFakeTimers(); + jest.setSystemTime(new Date(Date.UTC(2021, 1, 1))); - // TODO: not strictly correct, but close expect(util.time.nowFormatted('YYYY-MM-dd HH:mm:ss')).toEqual("2021-02-01T00:00:00.000Z"); - spied.mockRestore(); }); test("nowISO8601", async () => { - // patch date utilities to ensure consistency - const newDate = new Date(Date.UTC(2021, 1, 1)); - const spied = jest.spyOn(global, 'Date').mockImplementation(() => newDate); + jest.useFakeTimers(); + jest.setSystemTime(new Date(Date.UTC(2021, 1, 1))); expect(util.time.nowISO8601()).toEqual("2021-02-01T00:00:00.000Z"); - spied.mockRestore(); }); });