@manufac/general-tests 0.0.2 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -24,18 +24,38 @@ Then wire it into the app's `playwright.config.ts` using the project-builder hel
24
24
 
25
25
  ```ts
26
26
  import { defineConfig } from "@playwright/test";
27
- import { createDesktopProject, createMobileProject } from "@manufac/general-tests/config/projects.js";
27
+ import { Breakpoints, createProject } from "@manufac/general-tests/config/projects.js";
28
28
 
29
29
  export default defineConfig({
30
30
  use: {
31
31
  baseURL: "http://localhost:8080",
32
32
  },
33
33
  projects: [
34
- createDesktopProject("Desktop Chrome", "Desktop Chrome"),
35
- createDesktopProject("Desktop Safari", "Desktop Safari"),
36
- createDesktopProject("Desktop Firefox", "Desktop Firefox"),
37
- createMobileProject("Mobile Safari", "iPhone 12"),
38
- createMobileProject("Mobile Chrome", "Pixel 5"),
34
+ createProject({
35
+ name: "Desktop Chrome",
36
+ device: "Desktop Chrome",
37
+ configuration: { projectType: "desktop", breakpoint: Breakpoints.Desktop },
38
+ }),
39
+ createProject({
40
+ name: "Desktop Safari",
41
+ device: "Desktop Safari",
42
+ configuration: { projectType: "desktop", breakpoint: Breakpoints.Desktop },
43
+ }),
44
+ createProject({
45
+ name: "Desktop Firefox",
46
+ device: "Desktop Firefox",
47
+ configuration: { projectType: "desktop", breakpoint: Breakpoints.Desktop },
48
+ }),
49
+ createProject({
50
+ name: "Mobile Safari",
51
+ device: "iPhone 12",
52
+ configuration: { projectType: "mobile", breakpoint: Breakpoints.MobileM },
53
+ }),
54
+ createProject({
55
+ name: "Mobile Chrome",
56
+ device: "Pixel 5",
57
+ configuration: { projectType: "mobile", breakpoint: Breakpoints.MobileM },
58
+ }),
39
59
  ],
40
60
  webServer: {
41
61
  command: "npm run start",
@@ -45,14 +65,18 @@ export default defineConfig({
45
65
  });
46
66
  ```
47
67
 
48
- - `createDesktopProject(name, device, breakpoint?)` runs the `shared` + `desktop-only` specs under the given Playwright device, defaulting to the Desktop breakpoint (1440x900).
49
- - `createMobileProject(name, device, breakpoint?)` runs the `shared` + `mobile-only` specs, defaulting to the Mobile M breakpoint (390x844).
50
- - Both accept an optional third `breakpoint` argument — one of `Breakpoints.MobileS/MobileM/Tablet/Laptop/Desktop/Wide` (Section 3 of the test plan) — to test at a different viewport.
68
+ - `createProject({ name, device, configuration })` builds a Playwright project for the given device.
69
+ - `configuration.projectType: "desktop"` runs the `shared` + `desktop-only` specs, and requires `configuration.breakpoint: Breakpoints.Desktop` (1440x900).
70
+ - `configuration.projectType: "mobile"` runs the `shared` + `mobile-only` specs, and requires `configuration.breakpoint: Breakpoints.MobileM` (390x844).
51
71
 
52
72
  By default every spec runs against `/`. To point a project at a different page, override the `targetPage` fixture option:
53
73
 
54
74
  ```ts
55
- createDesktopProject("Desktop Chrome — pricing", "Desktop Chrome"),
75
+ createProject({
76
+ name: "Desktop Chrome — pricing",
77
+ device: "Desktop Chrome",
78
+ configuration: { projectType: "desktop", breakpoint: Breakpoints.Desktop },
79
+ }),
56
80
  // then, in that project's `use`:
57
81
  use: { targetPage: "/pricing" }
58
82
  ```
@@ -37,5 +37,23 @@ export declare const Breakpoints: {
37
37
  readonly height: 1080;
38
38
  };
39
39
  };
40
- export declare function createDesktopProject(name: string, device: keyof typeof devices, breakpoint?: Breakpoint): Project;
41
- export declare function createMobileProject(name: string, device: keyof typeof devices, breakpoint?: Breakpoint): Project;
40
+ declare const ProjectTypes: {
41
+ readonly Mobile: "mobile";
42
+ readonly Desktop: "desktop";
43
+ };
44
+ export type ProjectType = (typeof ProjectTypes)[keyof typeof ProjectTypes];
45
+ export interface MobileConfig {
46
+ projectType: typeof ProjectTypes.Mobile;
47
+ breakpoint: typeof Breakpoints.MobileM;
48
+ }
49
+ export interface DesktopConfig {
50
+ projectType: typeof ProjectTypes.Desktop;
51
+ breakpoint: typeof Breakpoints.Desktop;
52
+ }
53
+ export interface CreateProjectParams {
54
+ name: string;
55
+ device: keyof typeof devices;
56
+ configuration: MobileConfig | DesktopConfig;
57
+ }
58
+ export declare function createProject({ configuration, device, name }: CreateProjectParams): Project;
59
+ export {};
@@ -1,8 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Breakpoints = void 0;
4
- exports.createDesktopProject = createDesktopProject;
5
- exports.createMobileProject = createMobileProject;
4
+ exports.createProject = createProject;
6
5
  const test_1 = require("@playwright/test");
7
6
  const node_path_1 = require("node:path");
8
7
  // Section 3 of the Landing Page Test Plan — breakpoints / viewports.
@@ -19,19 +18,21 @@ const SpecsDirectory = (0, node_path_1.join)(__dirname, "..", "specs");
19
18
  const SharedTestMatch = "shared/**/*.spec.js";
20
19
  const DesktopOnlyTestMatch = "desktop-only/**/*.spec.js";
21
20
  const MobileOnlyTestMatch = "mobile-only/**/*.spec.js";
22
- function createDesktopProject(name, device, breakpoint = exports.Breakpoints.Desktop) {
23
- return {
24
- name,
25
- testDir: SpecsDirectory,
26
- testMatch: [SharedTestMatch, DesktopOnlyTestMatch],
27
- use: { ...test_1.devices[device], viewport: { width: breakpoint.width, height: breakpoint.height } },
28
- };
29
- }
30
- function createMobileProject(name, device, breakpoint = exports.Breakpoints.MobileM) {
21
+ const ProjectTypes = {
22
+ Mobile: "mobile",
23
+ Desktop: "desktop",
24
+ };
25
+ function createProject({ configuration, device, name }) {
31
26
  return {
32
27
  name,
33
28
  testDir: SpecsDirectory,
34
- testMatch: [SharedTestMatch, MobileOnlyTestMatch],
35
- use: { ...test_1.devices[device], viewport: { width: breakpoint.width, height: breakpoint.height } },
29
+ testMatch: [
30
+ SharedTestMatch,
31
+ configuration.projectType === ProjectTypes.Desktop ? DesktopOnlyTestMatch : MobileOnlyTestMatch,
32
+ ],
33
+ use: {
34
+ ...test_1.devices[device],
35
+ viewport: { width: configuration.breakpoint.width, height: configuration.breakpoint.height },
36
+ },
36
37
  };
37
38
  }
@@ -295,7 +295,7 @@ function isCutoffAtViewportEdge(snapshot, viewport) {
295
295
  rect.bottom > viewport.height + exports.ResponsiveConfig.CutoffTolerancePX);
296
296
  return hasDimensions && (isHorizontallyClipped || isVerticallyClipped);
297
297
  }
298
- async function findElementsCutoffAtViewportEdge(page, containerSelector = "body *") {
298
+ async function findElementsCutoffAtViewportEdge(page, containerSelector) {
299
299
  const { elements, viewport } = await page.evaluate((selector) => {
300
300
  function isRenderedElement(element) {
301
301
  const style = window.getComputedStyle(element);
@@ -328,7 +328,7 @@ async function findElementsCutoffAtViewportEdge(page, containerSelector = "body
328
328
  }
329
329
  return isClipped;
330
330
  }
331
- const renderedElements = Array.from(document.querySelectorAll(selector))
331
+ const renderedElements = Array.from(document.querySelectorAll(selector ?? "body *"))
332
332
  .filter(isRenderedElement)
333
333
  .filter((element) => {
334
334
  return !isClippedByAncestorOverflow(element);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@manufac/general-tests",
3
- "version": "0.0.2",
3
+ "version": "0.1.0",
4
4
  "description": "A library for general tests for landing pages",
5
5
  "repository": {
6
6
  "type": "git",