Skip to content

Commit 2294b20

Browse files
committed
feat!: move package to alpha status
1 parent 28bb3e5 commit 2294b20

File tree

2 files changed

+131
-4
lines changed

2 files changed

+131
-4
lines changed

README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[![npm](https://img.shields.io/npm/v/sveltekit-adapter-aws-pulumi)](https://www.npmjs.com/package/sveltekit-adapter-aws-pulumi)
2-
![stability-wip](https://img.shields.io/badge/stability-wip-lightgrey.svg)
2+
![stability-alpha](https://img.shields.io/badge/stability-alpha-f4d03f.svg)
33

44
[![Unit tests](https://github.com/Data-Only-Greater/sveltekit-adapter-aws-pulumi/actions/workflows/unit_tests.yml/badge.svg)](https://github.com/Data-Only-Greater/sveltekit-adapter-aws-pulumi/actions/workflows/unit_tests.yml)
55
[![Release](https://github.com/Data-Only-Greater/sveltekit-adapter-aws-pulumi/actions/workflows/release.yml/badge.svg)](https://github.com/Data-Only-Greater/sveltekit-adapter-aws-pulumi/actions/workflows/release.yml)
@@ -8,7 +8,8 @@
88

99
# SvelteKit AWS Adapter for Pulumi
1010

11-
This project contains a SvelteKit adapter to deploy SvelteKit to AWS using Pulumi.
11+
This project contains a SvelteKit adapter to deploy SvelteKit to AWS using
12+
Pulumi.
1213

1314
## How to use?
1415

@@ -58,7 +59,8 @@ export default config
5859

5960
## Architecture
6061

61-
The following diagram shows the architecture deployed by this package. The key features are as follows:
62+
The following diagram shows the architecture deployed by this package. The key
63+
features are as follows:
6264

6365
1. A CloudFront CDN
6466
1. An S3 bucket to serve prerendered and static content (secured using OAC)
@@ -84,7 +86,7 @@ export interface AWSAdapterProps {
8486
FQDN?: string // Full qualified domain name of CloudFront deployment (e.g. demo.example.com)
8587
memorySize?: number // Memory size of SSR lambda in MB (default: 128)
8688
pulumiPaths: string[] // For internal use only
87-
zoneName?: string // Region to deploy resources (default: us-east-2)
89+
region?: string // Region to deploy resources (default: us-east-2)
8890
stackName?: string // Pulumi stack name (default: dev)
8991
}
9092
```

tests/stacks.server.index.test.ts

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
import * as fs from 'fs'
2+
import * as path from 'path'
3+
4+
import * as pulumi from '@pulumi/pulumi'
5+
6+
import { MyMocks, getTempDir, promiseOf } from './utils'
7+
import * as resources from '../stacks/server/resources'
8+
9+
vi.mock('../stacks/server/resources')
10+
11+
describe('stacks/server/index.ts', () => {
12+
let envOrig: string
13+
let mocks: MyMocks
14+
let infra: typeof import('../stacks/server')
15+
16+
beforeEach(async () => {
17+
vi.resetModules()
18+
envOrig = JSON.stringify(process.env)
19+
mocks = new MyMocks()
20+
pulumi.runtime.setMocks(mocks)
21+
})
22+
23+
afterEach(() => {
24+
process.env = JSON.parse(envOrig)
25+
vi.resetAllMocks()
26+
})
27+
28+
it('main', async () => {
29+
const tmpDir = getTempDir()
30+
const envPath = path.join(tmpDir, '.env')
31+
const envContent = 'MOCK=\n'
32+
fs.writeFileSync(envPath, envContent)
33+
;(resources.getLambdaRole as any).mockImplementation(() => {
34+
return 'mock'
35+
})
36+
37+
const mockBuildLambda = resources.buildLambda as any
38+
mockBuildLambda.mockImplementation(() => {
39+
return {
40+
functionArn: pulumi.interpolate`arn`,
41+
functionUrl: pulumi.interpolate`https://www.example.com/`,
42+
}
43+
})
44+
45+
// @ts-ignore
46+
pulumi.Config = vi.fn(() => {
47+
return {
48+
get: vi.fn((x) => {
49+
if (x === 'projectPath') {
50+
return tmpDir
51+
}
52+
if (x === 'allowedOrigins') {
53+
return '[example.com]'
54+
}
55+
if (x === 'memorySize') {
56+
return '256'
57+
}
58+
return ''
59+
}),
60+
}
61+
})
62+
63+
infra = await import('../stacks/server')
64+
65+
expect(resources.getLambdaRole).toHaveBeenCalledTimes(1)
66+
expect(resources.buildLambda).toHaveBeenCalledTimes(2)
67+
68+
expect(mockBuildLambda.calls[0][3]).toStrictEqual({ MOCK: '' })
69+
expect(mockBuildLambda.calls[0][4]).toStrictEqual(256)
70+
expect(mockBuildLambda.calls[1][3]).toStrictEqual({
71+
ALLOWED_ORIGINS: '[example.com]',
72+
})
73+
74+
const serverArn = await promiseOf(infra.serverArn)
75+
const optionsArn = await promiseOf(infra.optionsArn)
76+
77+
expect(serverArn).toMatch('arn')
78+
expect(optionsArn).toMatch('arn')
79+
80+
const serverDomain = await promiseOf(infra.serverDomain)
81+
const optionsDomain = await promiseOf(infra.optionsDomain)
82+
83+
expect(serverDomain).toMatch('www.example.com')
84+
expect(optionsDomain).toMatch('www.example.com')
85+
86+
fs.rmSync(tmpDir, { recursive: true })
87+
})
88+
89+
it('main (defaults)', async () => {
90+
const tmpDir = getTempDir()
91+
const envPath = path.join(tmpDir, '.env')
92+
const envContent = 'MOCK=\n'
93+
fs.writeFileSync(envPath, envContent)
94+
;(resources.getLambdaRole as any).mockImplementation(() => {
95+
return 'mock'
96+
})
97+
98+
const mockBuildLambda = resources.buildLambda as any
99+
mockBuildLambda.mockImplementation(() => {
100+
return {
101+
functionArn: pulumi.interpolate`arn`,
102+
functionUrl: pulumi.interpolate`https://www.example.com/`,
103+
}
104+
})
105+
106+
// @ts-ignore
107+
pulumi.Config = vi.fn(() => {
108+
return {
109+
get: vi.fn((x) => {
110+
if (x === 'projectPath') {
111+
return tmpDir
112+
}
113+
return ''
114+
}),
115+
}
116+
})
117+
118+
infra = await import('../stacks/server')
119+
120+
expect(mockBuildLambda.calls[0][4]).toStrictEqual(128)
121+
expect(mockBuildLambda.calls[1][3]).toStrictEqual({})
122+
123+
fs.rmSync(tmpDir, { recursive: true })
124+
})
125+
})

0 commit comments

Comments
 (0)