Skip to content

Commit

Permalink
Merge pull request #8 from tiagofilipenunes/multibrowser-improvements
Browse files Browse the repository at this point in the history
Post-Multibrowser support improvements
  • Loading branch information
tiagofilipenunes authored Sep 30, 2024
2 parents cb376d9 + d06c391 commit 0aca11f
Show file tree
Hide file tree
Showing 18 changed files with 5,340 additions and 8,357 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Build
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
build:
timeout-minutes: 60
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: lts/*
- name: Install dependencies
run: npm install -g pnpm && pnpm install
- name: Build for Firefox
run: pnpm build:firefox
- name: Build for Chromium
run: pnpm build:chromium
27 changes: 27 additions & 0 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: E2E Tests
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
e2e:
timeout-minutes: 60
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: lts/*
- name: Install dependencies
run: npm install -g pnpm && pnpm install
- name: Install Playwright Browsers
run: pnpm exec playwright install chromium --with-deps
- name: Run Playwright E2E tests
run: pnpm e2e
- uses: actions/upload-artifact@v4
if: ${{ !cancelled() }}
with:
name: playwright-report
path: playwright-report/
retention-days: 30
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,10 @@ auto-imports.d.ts

# Produced when building or packing
manifest.json
web-ext-artifacts
web-ext-artifacts

# Test
/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,51 +18,51 @@ The extension allows to customize the highlight color in the pop-up settings.
To run the extension in development mode, run the following commands:

```zsh
npm run dev:chromium
pnpm dev:chromium
```

```zsh
npm run dev:firefox
pnpm dev:firefox
```

## Building

To build the extension, run the following commands:

```zsh
npm run build:chromium
pnpm build:chromium
```

```zsh
npm run build:firefox
pnpm build:firefox
```

## Running

To run the extension after building, run the following commands, for Google Chromium and Mozilla Firefox respectively:

```zsh
npm run start:chromium
pnpm start:chromium
```

```zsh
npm run start:firefox
pnpm start:firefox
```

## Installation

### Chromium

1. Clone the repository and install the dependencies using `npm i`
2. Run `npm run build:chromium` to build the extension
2. Run `pnpm build:chromium` to build the extension
3. Open a Chromium-based browser and go to `chrome://extensions/`
4. Enable `Developer mode`
5. Click on `Load unpacked` and select the `dist` folder

### Firefox

1. Clone the repository and install the dependencies using `npm i`
2. Run `npm run build:firefox` to build the extension and `npm run pack:firefox` to prepare it for installation
2. Run `pnpm build:firefox` to build the extension and `pnpm pack:firefox` to prepare it for installation
3. Open Firefox and go to `about:debugging#/runtime/this-firefox`
4. Click on `Load Temporary Add-on...` and select the .zip package in the `web-ext-artifacts` folder

Expand Down
24 changes: 24 additions & 0 deletions e2e/diff.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { test, expect } from "./fixtures";

test("Goto github PR files changed and check diff", async ({ page }) => {
await page.goto(
"https://github.com/bancorprotocol/carbon-app/pull/1464/files"
);
const firstIframe = page.frameLocator("iframe").first();
const iframeBody = firstIframe.locator("body");

await expect(iframeBody).toContainText("Difference");
await expect(iframeBody).toContainText("Overlay");
});

test("Check settings page contains right header and labels", async ({
page,
extensionId,
}) => {
await page.goto(`chrome-extension://${extensionId}/src/popup/index.html`);
await expect(page.locator("h1")).toContainText("Settings");
expect(page.locator("form > label")).toHaveText([
"Diff Color",
"Default Algo",
]);
});
35 changes: 35 additions & 0 deletions e2e/fixtures.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { test as base, chromium, type BrowserContext } from "@playwright/test";
import path from "path";
import { fileURLToPath } from "url";
import { resolve } from "node:path";

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const rootPath = resolve(__dirname, "..");

export const test = base.extend<{
context: BrowserContext;
extensionId: string;
}>({
context: async ({ headless }, use) => {
const pathToExtension = path.join(rootPath, "dist");
const context = await chromium.launchPersistentContext("", {
headless,
args: [
...(headless ? ["--headless=new"] : []),
`--disable-extensions-except=${pathToExtension}`,
`--load-extension=${pathToExtension}`,
],
});
await use(context);
await context.close();
},
extensionId: async ({ context }, use) => {
let [background] = context.serviceWorkers();
if (!background) background = await context.waitForEvent("serviceworker");

const extensionId = background.url().split("/")[2];
await use(extensionId);
},
});
export const expect = test.expect;
Loading

0 comments on commit 0aca11f

Please sign in to comment.