Skip to content
This repository has been archived by the owner on Oct 23, 2023. It is now read-only.

Commit

Permalink
feat: rewrite in TS
Browse files Browse the repository at this point in the history
Fix #2
  • Loading branch information
gregberge committed Feb 18, 2023
1 parent c096f60 commit 23dde98
Show file tree
Hide file tree
Showing 16 changed files with 3,674 additions and 1,556 deletions.
17 changes: 6 additions & 11 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
{
"plugins": ["eslint-plugin-html"],
"extends": ["eslint:recommended"],
"parserOptions": {
"ecmaVersion": 2022,
"sourceType": "module"
},
"env": {
"es6": true,
"node": true,
"browser": true,
"jest": true
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint"],
"root": true,
"rules": {
"@typescript-eslint/ban-ts-comment": "off"
}
}
11 changes: 5 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,9 @@ jobs:

steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
fetch-depth: 2

- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: 16
node-version: current

- name: Install dependencies
run: npm ci
Expand All @@ -32,6 +28,9 @@ jobs:
- name: Check format
run: npm run check-format

- name: Build
run: npm run build

- name: Install playwright browsers
run: npx playwright install --with-deps chromium

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
screenshots/*
!screenshots/.gitkeep
dist
6 changes: 3 additions & 3 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
!index.js
!index.cjs
!index.d.ts
!dist/index.mjs
!dist/index.cjs
!dist/index.d.ts
9 changes: 9 additions & 0 deletions .swcrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"$schema": "https://json.schemastore.org/swcrc",
"jsc": {
"target": "es2021",
"parser": {
"syntax": "typescript"
}
}
}
3 changes: 1 addition & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ All notable changes to this project will be documented in this file. See [standa

### 0.0.1 (2023-01-17)


### Features

* first version ([65aa75b](https://github.com/argos-ci/argos-playwright/commit/65aa75b463a89d14b6208f88193f1a2b5843a90f))
- first version ([65aa75b](https://github.com/argos-ci/argos-playwright/commit/65aa75b463a89d14b6208f88193f1a2b5843a90f))
31 changes: 19 additions & 12 deletions index.test.js → example.spec.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { test, chromium, expect } from "@playwright/test";
/* eslint-disable @typescript-eslint/no-explicit-any */
import { test, chromium, expect, Page } from "@playwright/test";
import { fileURLToPath } from "node:url";
import { stat } from "node:fs/promises";
import { argosScreenshot } from "./index.js";
import { argosScreenshot as argosScreenshotCjs } from "./index.cjs";
import { argosScreenshot } from "./src/index.js";
// @ts-ignore
import { argosScreenshot as argosScreenshotCjs } from "./dist/index.cjs";

test.describe.configure({ mode: "serial" });
const screenshotFolder = "screenshots";

export async function exists(path) {
export async function exists(path: string) {
try {
await stat(path);
return true;
Expand All @@ -16,7 +18,7 @@ export async function exists(path) {
}
}

async function screenshotExists(screenshotName) {
async function screenshotExists(screenshotName: string) {
const filepath = fileURLToPath(
new URL(`${screenshotFolder}/${screenshotName}.png`, import.meta.url).href
);
Expand All @@ -25,7 +27,7 @@ async function screenshotExists(screenshotName) {

const url = new URL("fixtures/dummy.html", import.meta.url).href;
test.describe("#argosScreenshot", () => {
let page;
let page: Page;
const screenshotName = "dummy-page";

test.beforeAll(async () => {
Expand All @@ -42,28 +44,33 @@ test.describe("#argosScreenshot", () => {
});
page.on("console", (msg) => console.log(msg.text()));
await page.goto(url);
await argosScreenshot(page, screenshotName);
await argosScreenshot(page, screenshotName, {});
});

test.afterAll(async () => {
await page.close();
});

test("throws without page", async () => {
let error: any;
try {
// @ts-expect-error - We want to test the error
await argosScreenshot();
} catch (error) {
expect(error.message).toBe("A Playwright `page` object is required.");
} catch (e: any) {
error = e;
}
expect(error.message).toBe("A Playwright `page` object is required.");
});

test("throws without name", async () => {
expect.assertions(1);
let error: any;
try {
// @ts-expect-error - We want to test the error
await argosScreenshot(page);
} catch (error) {
expect(error.message).toBe("The `name` argument is required.");
} catch (e: any) {
error = e;
}
expect(error.message).toBe("The `name` argument is required.");
});

test("waits for loader hiding", async () => {
Expand Down
6 changes: 0 additions & 6 deletions index.cjs

This file was deleted.

29 changes: 0 additions & 29 deletions index.d.ts

This file was deleted.

Loading

0 comments on commit 23dde98

Please sign in to comment.