-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
311 additions
and
253 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
# website | ||
|
||
Simple Website Template | ||
|
||
[![main CI](https://github.com/wandyezj/website/actions/workflows/main.yml/badge.svg?branch=main)](https://github.com/wandyezj/website/actions/workflows/main.yml) | ||
[![Pages](https://github.com/wandyezj/website/actions/workflows/pages.yml/badge.svg?branch=main)](https://github.com/wandyezj/website/actions/workflows/pages.yml) |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import path from "path"; | ||
import { getRootDirectory } from "./getRootDirectory"; | ||
|
||
export const localDistPath = path.resolve(getRootDirectory(), "dist"); | ||
|
||
export const rootUrlLocal = "https://localhost:3000"; | ||
export const rootUrlProduction = "https://wandyezj.github.io/website"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import * as fs from "fs"; | ||
import path from "path"; | ||
import { localDistPath } from "./distConstants"; | ||
|
||
export function getLocalDistData(subpath: string) { | ||
/** | ||
* Local generated file from build | ||
*/ | ||
const localDistDataPath = path.resolve(localDistPath, subpath); | ||
if (!fs.existsSync(localDistDataPath)) { | ||
throw new Error(`cannot find localDistDataPath ${localDistDataPath}`); | ||
} | ||
|
||
const localDistData = fs.readFileSync(localDistDataPath); | ||
return localDistData; | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/** | ||
* Route to use for testing | ||
*/ | ||
export enum Source { | ||
/** | ||
* (default) | ||
* Use local dist. | ||
* Most robust for testing in a pipeline. | ||
*/ | ||
Dist, | ||
|
||
/** | ||
* Use local server. | ||
* Most useful for development. | ||
*/ | ||
Localhost, | ||
|
||
/** | ||
* Use production url | ||
*/ | ||
Production, | ||
} | ||
|
||
const sourceDefault = Source.Dist; | ||
const sourceOverride: Source | undefined = undefined; | ||
|
||
export function getSource() { | ||
if (sourceOverride !== undefined) { | ||
return sourceOverride; | ||
} | ||
|
||
const testMode = process.env["TEST_MODE"]; | ||
|
||
if (testMode === "dist") { | ||
return Source.Dist; | ||
} | ||
|
||
if (testMode === "localhost") { | ||
return Source.Localhost; | ||
} | ||
|
||
return sourceDefault; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
import { test, expect } from "@playwright/test"; | ||
import { mainPageTitle, navigateToMainPage } from "./navigateToMainPage"; | ||
|
||
import { navigateToPage } from "./navigateToPage"; | ||
const mainPageTitle = "Website"; | ||
|
||
test("navigates to correct page title", async ({ browser }) => { | ||
const page = await navigateToMainPage(browser); | ||
const page = await navigateToPage(browser, "index.html", mainPageTitle); | ||
await expect(page).toHaveTitle(mainPageTitle); | ||
}); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { expect, Page, Browser } from "@playwright/test"; | ||
import { getLocalDistData } from "./getLocalDistData"; | ||
import { getSource, Source } from "./getSource"; | ||
import { rootUrlLocal, rootUrlProduction } from "./distConstants"; | ||
|
||
export async function navigateToPage(browser: Browser, subpath: string, title: string): Promise<Page> { | ||
// Create a separate browser context for each test | ||
const context = await browser.newContext(); | ||
const page = await context.newPage(); | ||
const useSource = getSource(); | ||
const rootUrl = useSource === Source.Localhost ? rootUrlLocal : rootUrlProduction; | ||
const pageUrl = rootUrl + "/" + subpath; | ||
|
||
// redirect to local data | ||
if (useSource === Source.Dist) { | ||
// interceptor to replace content of the page | ||
page.route(`${rootUrl}/*`, (route, request) => { | ||
const url = request.url(); | ||
const subpath = url.substring(rootUrl.length + 1); | ||
const body = getLocalDistData(subpath); | ||
route.fulfill({ | ||
body, | ||
}); | ||
}); | ||
} | ||
|
||
await page.goto(pageUrl); | ||
|
||
// Check that the page is the right one | ||
await expect(page).toHaveTitle(title); | ||
|
||
return page; | ||
} |