Skip to content

Commit

Permalink
📻
Browse files Browse the repository at this point in the history
  • Loading branch information
manucorporat committed Jul 4, 2023
1 parent 5c699a1 commit 57672f8
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 57 deletions.
16 changes: 14 additions & 2 deletions .github/workflows/aws.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,20 @@ jobs:
- name: Install Playwright
run: npx playwright install chromium --with-deps

- name: Test AWS Server MPA
- name: Test AWS Offline Server MPA
run: npm run test.aws-offline.mpa

- name: Test AWS Server SPA
- name: Test AWS Offline Server SPA
run: npm run test.aws-offline.spa

- name: Configura AWS credentials
run: npx serverless config credentials --provider aws --key ${{ secrets.AWS_KEY }} --secre ${{ secrets.AWS_SECRET }}

- name: Deploy AWS lambda
run: npm run deploy.aws

- name: Test AWS Server MPA
run: npm run test.aws.mpa

- name: Test AWS Server SPA
run: npm run test.aws.spa
26 changes: 18 additions & 8 deletions custom-src/entry_aws-lambda.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,20 @@ const { router, notFound, staticFile } = createQwikCity({
static: {
cacheControl: "public, max-age=31557600",
},
getOrigin(req) {
if (process.env.IS_OFFLINE) {
return `http://${req.headers.host}`;
}
return null;
},
});

export const qwikApp = serverless(
{
handle: (req: any, res: any) => {
req.url = fixPath(req.url);
if (process.env.IS_OFFLINE) {
req.url = fixPath(req.url);
}
staticFile(req, res, () => {
router(req, res, () => {
notFound(req, res, () => {});
Expand All @@ -47,14 +55,16 @@ export const qwikApp = serverless(
}
);

function fixPath(url: string) {
function fixPath(path: string) {
console.log(path);
if (qwikCityPlan.trailingSlash) {
if (url.slice(url.lastIndexOf("/")).includes(".")) {
return url;
const url = new URL(path, "http://aws-qwik.local");
if (url.pathname.includes(".", url.pathname.lastIndexOf("/"))) {
return path;
}
if (!url.endsWith("/")) {
return url + "/";
if (!url.pathname.endsWith("/")) {
return url.pathname + "/" + url.search;
}
}
return url;
}
return path;
}
17 changes: 0 additions & 17 deletions custom-src/routes/functions/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,23 +39,6 @@ export default component$(() => {
Increment {counter.value} {counterDoubled.value}
</button>

<button
id="save"
onClick$={server$(() => {
globalDB.count = counter.value;
console.log("Current count is", counter.value);
})}
>
SAVE
</button>
<button
id="load"
onClick$={async () => {
message.value = `Stuff is: ${await getstuff(counter.value)}`;
}}
>
LOAD
</button>
<p id="result">{message.value}</p>
<button
onClick$={async () => {
Expand Down
5 changes: 4 additions & 1 deletion playwright.aws-offline.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ const config: PlaywrightTestConfig = {
metadata: {
server: "aws",
},
retries: 2,
grepInvert: [
/@streaming/,
/@trailingSlash/
],
webServer: {
command: "npm run serve.aws",
port: 4000,
Expand Down
6 changes: 4 additions & 2 deletions playwright.aws.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ const config: PlaywrightTestConfig = {
metadata: {
server: "aws",
},

grepInvert: [
/@streaming/,
],
use: {
baseURL: "https://qwik-city-e2e.vercel.app/",
baseURL: "https://3psthbqcak.execute-api.us-west-1.amazonaws.com/",
},
retries: 2,
webServer: undefined,
Expand Down
4 changes: 3 additions & 1 deletion playwright.netlify.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ const config: PlaywrightTestConfig = {
metadata: {
server: "netlify",
},

grepInvert: [
/@streaming/,
],
use: {
baseURL: "https://qwik-city-e2e.netlify.app/",
},
Expand Down
3 changes: 2 additions & 1 deletion serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ custom:
package:
excludeDevDependencies: true
patterns:
- "./!**"
- "!*"
- "!*/**"
- "server/**"
- "dist/**"

Expand Down
24 changes: 1 addition & 23 deletions tests/functions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ test("navigate to /app/functions/ and run test", async ({
}
});

test("streaming", async ({ page, javaScriptEnabled }) => {
test("streaming @streaming", async ({ page, javaScriptEnabled }) => {
await page.goto("/app/functions/");
if (javaScriptEnabled) {
const logs = page.locator(".server-streaming");
Expand All @@ -44,36 +44,14 @@ test("streaming", async ({ page, javaScriptEnabled }) => {

async function functionsTest(page: Page) {
const increment = page.locator("#increment");
const save = page.locator("#save");
const load = page.locator("#load");
const result = page.locator("#result");

await save.click();
await page.waitForTimeout(100);
await load.click();
await page.waitForTimeout(100);

await expect(increment).toHaveText("Increment 0 0");
await expect(result).toHaveText("Stuff is: 0");

await increment.click();
await expect(increment).toHaveText("Increment 1 2");
await save.click();
await page.waitForTimeout(100);
await load.click();
await page.waitForTimeout(100);
await expect(result).toHaveText("Stuff is: 2");

await increment.click();
await expect(increment).toHaveText("Increment 2 4");
await increment.click();
await expect(increment).toHaveText("Increment 3 6");
await load.click();
await page.waitForTimeout(100);
await expect(result).toHaveText("Stuff is: 4");
await save.click();
await page.waitForTimeout(100);
await load.click();
await page.waitForTimeout(100);
await expect(result).toHaveText("Stuff is: 6");
}
2 changes: 1 addition & 1 deletion tests/navigate.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ test("navigate to /app/endpoints/", async ({ page }, { config }) => {
await expect(new URL(page.url()).pathname).toEqual("/app/endpoints/");
});

test("navigate to /app/endpoints (no trailing)", async ({ page }, {
test("navigate to /app/endpoints (no trailing) @trailingSlash", async ({ page }, {
config,
}) => {
await page.goto("/app/");
Expand Down
2 changes: 1 addition & 1 deletion tests/no-trailing-slash.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect, test } from "@playwright/test";

test("no trailing slash should redirect to have a trailing slash", async ({
test("no trailing slash should redirect to have a trailing slash @trailingSlash", async ({
page,
}) => {
const rsp = (await page.goto("/app/endpoints"))!;
Expand Down

0 comments on commit 57672f8

Please sign in to comment.