Skip to content

Commit d42463a

Browse files
committed
test: add e2e test for dungeon adventure tutorial (module 1 to 3)
1 parent 0fdf244 commit d42463a

42 files changed

Lines changed: 1289 additions & 5220 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/ci.yml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,17 @@ jobs:
4444
name: build-artifact
4545
path: dist
4646
smoke_tests:
47-
name: Smoke Tests - ${{matrix.package_manager}}
47+
name: Smoke Tests - ${{matrix.smoke_test}}
4848
runs-on: codebuild-nx-plugin-for-aws-runner-${{ github.run_id }}-${{ github.run_attempt }}
4949
needs: build
5050
strategy:
5151
matrix:
52-
package_manager: [npm, yarn, pnpm, bun]
52+
smoke_test:
53+
- npm
54+
- yarn
55+
- pnpm
56+
- bun
57+
- dungeon-adventure
5358
steps:
5459
- uses: actions/checkout@v4
5560
with:
@@ -60,8 +65,8 @@ jobs:
6065
name: build-artifact
6166
path: dist
6267
- uses: ./.github/actions/init-monorepo
63-
- name: Smoke Test - ${{ matrix.package_manager }}
64-
run: pnpm nx run @aws/nx-plugin-e2e:test -t "smoke test - ${{ matrix.package_manager }}"
68+
- name: Smoke Test - ${{ matrix.smoke_test }}
69+
run: pnpm nx run @aws/nx-plugin-e2e:test -t "smoke test - ${{ matrix.smoke_test }}"
6570
release:
6671
name: Release
6772
needs: [build, smoke_tests]

.github/workflows/pr.yml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,17 @@ jobs:
4444
name: build-artifact
4545
path: dist
4646
smoke_tests:
47-
name: Smoke Tests - ${{matrix.package_manager}}
47+
name: Smoke Tests - ${{matrix.smoke_test}}
4848
runs-on: codebuild-nx-plugin-for-aws-runner-${{ github.run_id }}-${{ github.run_attempt }}
4949
needs: build
5050
strategy:
5151
matrix:
52-
package_manager: [npm, yarn, pnpm, bun]
52+
smoke_test:
53+
- npm
54+
- yarn
55+
- pnpm
56+
- bun
57+
- dungeon-adventure
5358
steps:
5459
- uses: actions/checkout@v4
5560
with:
@@ -60,5 +65,5 @@ jobs:
6065
name: build-artifact
6166
path: dist
6267
- uses: ./.github/actions/init-monorepo
63-
- name: Smoke Test - ${{ matrix.package_manager }}
64-
run: pnpm nx run @aws/nx-plugin-e2e:test -t "smoke test - ${{ matrix.package_manager }}"
68+
- name: Smoke Test - ${{ matrix.smoke_test }}
69+
run: pnpm nx run @aws/nx-plugin-e2e:test -t "smoke test - ${{ matrix.smoke_test }}"
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
---
22
import PackageManagerCommand from './package-manager-command.astro';
3+
import { buildCreateNxWorkspaceCommand } from '../../../e2e/src/utils';
34
45
const { workspace } = Astro.props;
5-
const buildCommand = (pm) => `npx create-nx-workspace@~21.0.3 ${workspace} --pm=${pm} --preset=ts --ci=skip --formatter=prettier`;
6+
const buildCommand = (pm) => buildCreateNxWorkspaceCommand(pm, workspace);
67
---
78
<PackageManagerCommand buildCommand={buildCommand} />

docs/src/components/diff.astro

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
import { Code } from '@astrojs/starlight/components';
3+
import { diffLines } from 'diff';
4+
5+
const { before, after, lang } = Astro.props;
6+
7+
const diff = diffLines(before, after, { newlineIsToken: false })
8+
.map(change => {
9+
const prefix = change.added ? '+' : change.removed ? '-' : '';
10+
return change.value.slice(0, -1).split('\n').map(line => `${prefix}${line}`).join('\n') + '\n';
11+
}).join('');
12+
13+
---
14+
<Code lang="diff" code={diff} {...(lang ? { meta: `lang="${lang}"`} : {})} />

docs/src/components/e2e-code.astro

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
import { Code } from '@astrojs/starlight/components';
3+
const e2eFiles = Object.entries(import.meta.glob('../../../e2e/src/files/**/*.template', { eager: true, query: '?raw' }));
4+
5+
const { path, ...props } = Astro.props;
6+
const code = e2eFiles.find(([file, content]) => file.endsWith(path))[1].default;
7+
---
8+
<Code {...props} code={code} />

docs/src/components/e2e-diff.astro

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
import Diff from './diff.astro';
3+
4+
const e2eFiles = Object.entries(import.meta.glob('../../../e2e/src/files/**/*.template', { eager: true, query: '?raw' }));
5+
const { before, after, lang } = Astro.props;
6+
const beforeContent = e2eFiles.find(([file, content]) => file.endsWith(before))[1].default;
7+
const afterContent = e2eFiles.find(([file, content]) => file.endsWith(after))[1].default;
8+
---
9+
<Diff before={beforeContent} after={afterContent} lang={lang} />

docs/src/content/docs/en/get_started/tutorials/dungeon-game/1.mdx

Lines changed: 11 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import RunGenerator from '@components/run-generator.astro';
1111
import NxCommands from '@components/nx-commands.astro';
1212
import InstallCommand from '@components/install-command.astro';
1313
import CreateNxWorkspaceCommand from '@components/create-nx-workspace-command.astro';
14+
import E2EDiff from '@components/e2e-diff.astro';
15+
1416
import dungeonAdventureArchitecturePng from '@assets/dungeon-game-architecture.png'
1517
import dungeonAdventureErPng from '@assets/dungeon-adventure-er.png'
1618
import baselineWebsitePng from '@assets/baseline-website.png'
@@ -137,7 +139,7 @@ import {
137139
} from '@trpc/server/adapters/aws-lambda';
138140
import { echo } from './procedures/echo.js';
139141
import { t } from './init.js';
140-
import { APIGatewayProxyEventV2WithIAMAuthorizer } from 'aws-lambda';
142+
import { APIGatewayProxyEvent } from 'aws-lambda';
141143

142144
export const router = t.router;
143145

@@ -148,8 +150,14 @@ export const appRouter = router({
148150
export const handler = awsLambdaRequestHandler({
149151
router: appRouter,
150152
createContext: (
151-
ctx: CreateAWSLambdaContextOptions<APIGatewayProxyEventV2WithIAMAuthorizer>,
153+
ctx: CreateAWSLambdaContextOptions<APIGatewayProxyEvent>,
152154
) => ctx,
155+
responseMeta: () => ({
156+
headers: {
157+
'Access-Control-Allow-Origin': '*',
158+
'Access-Control-Allow-Methods': '*',
159+
},
160+
}),
153161
});
154162

155163
export type AppRouter = typeof appRouter;
@@ -1015,41 +1023,8 @@ This is where we will instantiate our CDK constructs to build our dungeon advent
10151023

10161024
Let's make an update to our `packages/infra/src/stacks/application-stack.ts` to instantiate some of our already generated constructs:
10171025

1018-
```diff lang="ts"
1019-
+import {
1020-
+ GameApi,
1021-
+ GameUI,
1022-
+ StoryApi,
1023-
+ UserIdentity,
1024-
+} from ':dungeon-adventure/common-constructs';
1025-
import * as cdk from 'aws-cdk-lib';
1026-
import { Construct } from 'constructs';
1027-
1028-
export class ApplicationStack extends cdk.Stack {
1029-
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
1030-
super(scope, id, props);
1031-
1032-
- // The code that defines your stack goes here
1033-
+ const userIdentity = new UserIdentity(this, 'UserIdentity');
1034-
+
1035-
+ const gameApi = new GameApi(this, 'GameApi', {
1036-
+ integrations: GameApi.defaultIntegrations(this).build(),
1037-
+ });
1038-
+ const storyApi = new StoryApi(this, 'StoryApi', {
1039-
+ integrations: StoryApi.defaultIntegrations(this).build(),
1040-
+ });
1041-
+
1042-
+ // grant our authenticated role access to invoke our APIs
1043-
+ [storyApi, gameApi].forEach((api) =>
1044-
+ api.grantInvokeAccess(userIdentity.identityPool.authenticatedRole),
1045-
+ );
1046-
+
1047-
+ // Ensure this is instantiated last so our runtime-config.json can be automatically configured
1048-
+ new GameUI(this, 'GameUI');
1049-
}
1050-
}
10511026

1052-
```
1027+
<E2EDiff before="dungeon-adventure/1/application-stack.ts.original.template" after="dungeon-adventure/1/application-stack.ts.template" lang="ts" />
10531028

10541029
Notice here that we supply default integrations for our two APIs. By default, each operation in our API is mapped to an individual lambda function to handle that operation.
10551030

0 commit comments

Comments
 (0)