Skip to content

Commit

Permalink
fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeshay committed Sep 26, 2023
1 parent a871a6b commit 0b31ecd
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 9 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
"turbo": "^1.10.14",
"typescript": "^5.2.2"
},
"packageManager": "[email protected]",
"engines": {
"node": "18.x"
},
Expand Down
50 changes: 45 additions & 5 deletions packages/adapter/src/__tests__/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { URL, fileURLToPath } from "node:url"
import { writeFile } from "node:fs/promises"

import { afterEach, beforeEach, describe, expect, test, vi } from "vitest"
import { faker } from "@faker-js/faker"
Expand All @@ -9,25 +10,43 @@ import { ADAPTER_NAME } from "../constants.js"
import { astroAWSFunctions, getAdapter } from "../index.js"
import * as shared from "../shared.js"

vi.mock("node:fs/promises", () => ({
writeFile: vi.fn(),
}))

describe("index.ts", () => {
afterEach(() => {
vi.clearAllMocks()
})

describe("getAdapter", () => {
const args: Args = {
binaryMediaTypes: [faker.datatype.string()],
binaryMediaTypes: [faker.string.sample()],
}

describe("when there are arguments", () => {
test("should return the adapter info", () => {
const result = getAdapter(args)

expect(result).toStrictEqual({
adapterFeatures: {
edgeMiddleware: false,
functionPerRoute: false,
},
args,
exports: ["handler"],
name: ADAPTER_NAME,
serverEntrypoint: `${ADAPTER_NAME}/lambda/index.js`,
supportedAstroFeatures: {
assets: {
isSharpCompatible: false,
isSquooshCompatible: false,
supportKind: "stable",
},
hybridOutput: "stable",
serverOutput: "stable",
staticOutput: "unsupported",
},
})
})
})
Expand All @@ -37,18 +56,32 @@ describe("index.ts", () => {
const result = getAdapter()

expect(result).toStrictEqual({
adapterFeatures: {
edgeMiddleware: false,
functionPerRoute: false,
},
args: {},
exports: ["handler"],
name: ADAPTER_NAME,
serverEntrypoint: `${ADAPTER_NAME}/lambda/index.js`,
supportedAstroFeatures: {
assets: {
isSharpCompatible: false,
isSquooshCompatible: false,
supportKind: "stable",
},
hybridOutput: "stable",
serverOutput: "stable",
staticOutput: "unsupported",
},
})
})
})
})

describe("astroAWSFunctions", () => {
const args: Args = {
binaryMediaTypes: [faker.datatype.string()],
binaryMediaTypes: [faker.string.sample()],
}

describe("always", () => {
Expand Down Expand Up @@ -92,13 +125,13 @@ describe("index.ts", () => {
} as unknown as AstroConfig
routes = [
{
route: faker.datatype.string(),
route: faker.string.sample(),
} as unknown as RouteData,
{
route: faker.datatype.string(),
route: faker.string.sample(),
} as unknown as RouteData,
{
route: faker.datatype.string(),
route: faker.string.sample(),
} as unknown as RouteData,
]

Expand Down Expand Up @@ -157,6 +190,13 @@ describe("index.ts", () => {
routes,
} as unknown as Parameters<typeof astroBuildDone>[0])

expect(writeFile).toHaveBeenCalledTimes(1)
expect(writeFile).toHaveBeenCalledWith(
fileURLToPath(new URL("metadata.json", config.outDir)),
JSON.stringify({
routes,
}),
)
expect(bundleEntry).toHaveBeenCalledTimes(1)
expect(bundleEntry).toHaveBeenCalledWith(
fileURLToPath(
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { fileURLToPath } from "node:url"
import { writeFile } from "node:fs/promises"

import type { AstroAdapter, AstroConfig, AstroIntegration } from "astro"

import type { Args } from "./args.js"
import { bundleEntry } from "./shared.js"
import { ADAPTER_NAME } from "./constants.js"
import { warn } from "./log.js"
import { writeFile } from "node:fs/promises"

const getAdapter = (args: Args = {}): AstroAdapter => ({
adapterFeatures: {
Expand Down
4 changes: 2 additions & 2 deletions packages/adapter/src/lambda/__tests__/helpers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe("helpers", () => {
headers: Record<string, string>

beforeEach(async () => {
body = faker.datatype.string()
body = faker.string.sample()
headers = {
"content-type": "text/plain",
}
Expand Down Expand Up @@ -61,7 +61,7 @@ describe("helpers", () => {
headers: Record<string, string>

beforeEach(async () => {
body = faker.datatype.string()
body = faker.string.sample()
headers = {
"content-type": "text/plain",
}
Expand Down

0 comments on commit 0b31ecd

Please sign in to comment.