Skip to content

Commit b4a5ad2

Browse files
authored
Resnap tests (#185)
1 parent fd02be8 commit b4a5ad2

File tree

4 files changed

+18
-13
lines changed

4 files changed

+18
-13
lines changed

__tests__/__snapshots__/index.test.js.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Jest Snapshot v1, https://goo.gl/fbAQLP
1+
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
22

33
exports[`DynamoDB module functions get 1`] = `
44
{

__tests__/__snapshots__/resolvers.test.js.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Jest Snapshot v1, https://goo.gl/fbAQLP
1+
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
22

33
exports[`dynamodb resolvers something 1`] = `
44
{

__tests__/helpers.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
"use strict";
22

3+
import { fileURLToPath, pathToFileURL } from "url";
4+
import { dirname, resolve } from "path";
35
import { AppSyncClient, EvaluateCodeCommand } from "@aws-sdk/client-appsync";
46
import { util } from "..";
57
import * as ddb from "../dynamodb";
68
import * as rds from "../rds";
79

10+
const __filename = fileURLToPath(import.meta.url);
11+
const __dirname = dirname(__filename);
12+
const projectRoot = resolve(__dirname, "..");
13+
814
let client = null;
915

1016
const runResolverFunctionOnAWS = async (code, context, functionName) => {
@@ -65,8 +71,8 @@ export const checkResolverValid = async (code, context, functionName) => {
6571
result = await runResolverFunctionOnAWS(fullCode, context, functionName);
6672
} else {
6773
const fullCode = `
68-
import { util } from '..';
69-
import * as rds from '../rds';
74+
import { util } from '${pathToFileURL(resolve(projectRoot, "index.js"))}';
75+
import * as rds from '${pathToFileURL(resolve(projectRoot, "rds/index.js"))}';
7076
` + code;
7177
const encodedJs = encodeURIComponent(fullCode);
7278
const dataUri = 'data:text/javascript;charset=utf-8,' + encodedJs;

__tests__/index.test.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,21 @@ describe("general utilities", () => {
1717
});
1818

1919
describe("time utilities", () => {
20+
afterEach(() => {
21+
jest.useRealTimers();
22+
});
23+
2024
test("nowFormatted", async () => {
21-
// patch date utilities to ensure consistency
22-
const newDate = new Date(2021, 1, 1);
23-
const spied = jest.spyOn(global, 'Date').mockImplementation(() => newDate);
25+
jest.useFakeTimers();
26+
jest.setSystemTime(new Date(Date.UTC(2021, 1, 1)));
2427

25-
// TODO: not strictly correct, but close
2628
expect(util.time.nowFormatted('YYYY-MM-dd HH:mm:ss')).toEqual("2021-02-01T00:00:00.000Z");
27-
spied.mockRestore();
2829
});
2930
test("nowISO8601", async () => {
30-
// patch date utilities to ensure consistency
31-
const newDate = new Date(Date.UTC(2021, 1, 1));
32-
const spied = jest.spyOn(global, 'Date').mockImplementation(() => newDate);
31+
jest.useFakeTimers();
32+
jest.setSystemTime(new Date(Date.UTC(2021, 1, 1)));
3333

3434
expect(util.time.nowISO8601()).toEqual("2021-02-01T00:00:00.000Z");
35-
spied.mockRestore();
3635
});
3736
});
3837

0 commit comments

Comments
 (0)