Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: enable e2e tests #329

Merged
merged 5 commits into from
Jan 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 18 additions & 27 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ jobs:
with:
node-version-file: 'package.json'
cache: 'pnpm'
- uses: ueokande/setup-firefox@latest
with:
firefox-version: 78.3.0esr
- run: pnpm install --frozen-lockfile
- run: pnpm tsc
- run: pnpm lint
Expand All @@ -30,27 +27,21 @@ jobs:
name: dist
path: ./dist/

# TODO playwright-webextext does not support MV3
# test-e2e:
# name: E2E Test
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v3
# - uses: actions/setup-node@v3
# with:
# node-version: '18.5.0'
# cache: 'yarn'
# - uses: ueokande/setup-firefox@latest
# with:
# firefox-version: 78.3.0esr
# - name: Install xsel
# run: sudo apt-get install -y --no-install-recommends xsel
# - run: yarn install --immutable
# - run: yarn build
# - run: $(npm bin)/webext-agent install
# - run: $(npm bin)/webext-agent create-addon --base-addon . /tmp/vimmatic-mixedin
# - name: Run test
# run: |
# export DISPLAY=:99
# Xvfb -ac :99 -screen 0 1280x1024x24 >/dev/null 2>&1 &
# yarn test:e2e --headed
test-e2e:
name: E2E Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v2
- uses: actions/setup-node@v3
with:
node-version-file: 'package.json'
cache: 'pnpm'
- name: Install xsel
run: sudo apt-get install -y --no-install-recommends xsel
- run: pnpm install --frozen-lockfile
- run: pnpm exec playwright install firefox
- run: pnpm build
- run: pnpm exec webext-agent install --addon-ids [email protected]
- run: pnpm exec webext-agent create-addon --base-addon dist/firefox /tmp/vimmatic-mixedin
- run: xvfb-run --auto-servernum --server-args="-screen 0 1280x960x24" -- pnpm run test:e2e --headed
50 changes: 15 additions & 35 deletions e2e/blacklist.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,9 @@ import { test, expect } from "./lib/fixture";
import { newScrollableServer } from "./lib/servers";
import SettingRepository from "./lib/SettingRepository";

const setupBlacklist = async (
api: typeof browser,
blacklist: Array<string | { url: string; keys: Array<string> }>,
) => {
await new SettingRepository(api).save({
blacklist,
});
};

const server = newScrollableServer();
const READY_STATE_SELECTOR =
"head[data-vimmatic-content-status='ready'][data-vimmatic-console-status='ready']";

test.beforeAll(async () => {
await server.start();
Expand All @@ -25,38 +18,25 @@ test("should disable add-on if the URL is in the blacklist", async ({
page,
api,
}) => {
await setupBlacklist(api, [new URL(server.url()).host + "/a"]);

await page.goto(server.url("/a"));
await page.keyboard.press("j");

const y = await page.evaluate(() => window.pageYOffset);
expect(y).toBe(0);
});

test("should enabled add-on if the URL is not in the blacklist", async ({
page,
api,
}) => {
await setupBlacklist(api, [new URL(server.url()).host + "/a"]);
await new SettingRepository(api).save({
blacklist: [new URL(server.url()).host + "/a"],
});

await page.goto(server.url("/ab"));
await page.keyboard.press("j");
await page.goto(server.url("/a"), { waitUntil: "domcontentloaded" });
await expect(page.locator(READY_STATE_SELECTOR)).not.toBeAttached();

const y = await page.evaluate(() => window.pageYOffset);
expect(y).toBe(64);
await page.goto(server.url("/ab"), { waitUntil: "domcontentloaded" });
await expect(page.locator(READY_STATE_SELECTOR)).toBeAttached();
});

test("should disable keys in the partial blacklist", async ({ page, api }) => {
await setupBlacklist(api, [{ url: new URL(server.url()).host, keys: ["k"] }]);
await new SettingRepository(api).save({
blacklist: [{ url: new URL(server.url()).host, keys: ["k"] }],
});

await page.goto(server.url());
await expect(page.locator(READY_STATE_SELECTOR)).toBeAttached();

await page.keyboard.press("j");
const y1 = await page.evaluate(() => window.pageYOffset);
expect(y1).toBe(64);

await page.keyboard.press("k");
const y2 = await page.evaluate(() => window.pageYOffset);
expect(y2).toBe(64);
await page.keyboard.type("jk");
expect(await page.evaluate(() => window.scrollY)).toBe(64);
});
62 changes: 38 additions & 24 deletions e2e/clipboard.test.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,49 @@
import { test, expect } from "./lib/fixture";
import * as clipboard from "./lib/clipboard";
import SettingRepository from "./lib/SettingRepository";
import { newNopServer } from "./lib/servers";

const server = newNopServer();

test.beforeAll(async () => {
await server.start();
});

test.afterAll(async () => {
await server.stop();
});

test("should copy current URL by y", async ({ page }) => {
await page.goto("about:blank#should_copy_url");
await page.goto(server.url());
await page.keyboard.press("y");

await expect.poll(() => clipboard.read()).toBe("about:blank#should_copy_url");
await expect.poll(() => clipboard.read()).toBe(server.url());
});

test("should open an URL from clipboard by p", async ({ page }) => {
await clipboard.write("about:blank#open_from_clipboard");
await page.goto(server.url());
await clipboard.write(`${server.url()}#open_to_new_tab`);
await page.keyboard.press("p");

await expect.poll(() => page.url()).toBe("about:blank#open_from_clipboard");
await expect.poll(() => page.url()).toBe(`${server.url()}#open_to_new_tab`);
});

test("should open an URL from clipboard to new tab by P", async ({
page,
api,
}) => {
const { id: windowId } = await api.windows.getCurrent();
await clipboard.write("about:blank#open_to_new_tab");
await page.goto(server.url());

await clipboard.write(`${server.url()}#open_to_new_tab`);
await page.keyboard.press("Shift+P");

await expect
.poll(() => api.tabs.query({ windowId }))
.toMatchObject([
{ url: "about:blank" },
{ url: "about:blank#open_to_new_tab" },
]);
.poll(async () =>
(await api.tabs.query({ currentWindow: true })).map((t) => t.url),
)
.toEqual(
expect.arrayContaining([server.url(), `${server.url()}#open_to_new_tab`]),
);
});

test("should open search result with keywords in clipboard by p", async ({
Expand All @@ -38,42 +52,42 @@ test("should open search result with keywords in clipboard by p", async ({
}) => {
await new SettingRepository(api).save({
search: {
default: "aboutblank",
default: "localhost",
engines: {
aboutblank: "about:blank?q={}",
localhost: `${server.url()}?q={}`,
},
},
});
await page.reload();
await page.goto(server.url());

await clipboard.write(`an apple`);
await page.keyboard.press("p");

await expect.poll(() => page.url()).toBe("about:blank?q=an%20apple");
await expect.poll(() => page.url()).toBe(`${server.url()}?q=an%20apple`);
});

test("should open search result with keywords in clipboard to new tab by P", async ({
page,
api,
}) => {
const { id: windowId } = await api.windows.getCurrent();
await new SettingRepository(api).save({
search: {
default: "aboutblank",
default: "localhost",
engines: {
aboutblank: "about:blank?q={}",
localhost: `${server.url()}?q={}`,
},
},
});
await page.reload();
await page.goto(server.url());

await clipboard.write(`an apple`);
await page.keyboard.press("Shift+P");

await expect
.poll(() => api.tabs.query({ windowId }))
.toMatchObject([
{ url: "about:blank" },
{ url: "about:blank?q=an%20apple" },
]);
.poll(async () =>
(await api.tabs.query({ currentWindow: true })).map((t) => t.url),
)
.toEqual(
expect.arrayContaining([server.url(), `${server.url()}?q=an%20apple`]),
);
});
2 changes: 1 addition & 1 deletion e2e/colorscheme.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ test.afterAll(async () => {
await server.stop();
});

test("changes color scheme by set command", async ({ page }) => {
test.fixme("changes color scheme by set command", async ({ page }) => {
await page.goto(server.url());

await page.console.show();
Expand Down
Loading
Loading