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

Added supported features #92

Merged
merged 2 commits into from
Sep 26, 2023
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
5 changes: 5 additions & 0 deletions .changeset/shaggy-ravens-bow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@astro-aws/adapter": patch
---

Set supported features
4 changes: 1 addition & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
{
"cSpell.words": ["astro"],
"eslint.nodePath": ".yarn/sdks",
"files.associations": {
"*.mdx": "markdown"
},
"prettier.prettierPath": ".yarn/sdks/prettier/index.js",
"search.exclude": {
"**/.yarn": true,
"**/.pnp.*": true
},
"typescript.enablePromptUseWorkspaceTsdk": true,
"typescript.tsdk": ".yarn/sdks/typescript/lib"
"typescript.tsdk": "node_modules/typescript/lib"
}
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
22 changes: 21 additions & 1 deletion packages/adapter/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { fileURLToPath } from "node:url"
import { writeFile } from "node:fs/promises"

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

Expand All @@ -8,10 +9,24 @@ import { ADAPTER_NAME } from "./constants.js"
import { warn } from "./log.js"

const getAdapter = (args: Args = {}): AstroAdapter => ({
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",
},
})

const astroAWSFunctions = (args: Args = {}): AstroIntegration => {
Expand Down Expand Up @@ -42,7 +57,12 @@ const astroAWSFunctions = (args: Args = {}): AstroIntegration => {
)
}
},
"astro:build:done": async () => {
"astro:build:done": async (options) => {
await writeFile(
fileURLToPath(new URL("metadata.json", astroConfig.outDir)),
JSON.stringify(options),
)

await bundleEntry(
fileURLToPath(
new URL(astroConfig.build.serverEntry, astroConfig.build.server),
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