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

Commit

Permalink
fix(next-image-snapshot): Make it usable for CI (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
kdy1 authored Aug 24, 2023
1 parent aeb53de commit 5a7db3c
Show file tree
Hide file tree
Showing 12 changed files with 173 additions and 162 deletions.
50 changes: 50 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: CI

on:
push:
branches: ["main"]
pull_request:
types: [opened, synchronize]
merge_group:

env:
CI: 1

jobs:
build:
name: Build and Test
timeout-minutes: 15
runs-on: ubuntu-latest
# To use Remote Caching, uncomment the next lines and follow the steps below.
# env:
# TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
# TURBO_TEAM: ${{ vars.TURBO_TEAM }}

env:
DISPLAY: ":99"

steps:
- name: Check out code
uses: actions/checkout@v3
with:
fetch-depth: 2

- uses: pnpm/action-setup@v2.0.1
with:
version: 8.6.3

- uses: nanasess/setup-chromedriver@v2
- run: |
chromedriver --url-base=/wd/hub &
- name: Setup Node.js environment
uses: actions/setup-node@v3
with:
node-version: 18
cache: "pnpm"

- name: Install dependencies
run: pnpm install

- name: Test
run: pnpm turbo run test:ci
2 changes: 1 addition & 1 deletion packages/jest-expect-image/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "jest-expect-image",
"packageManager": "pnpm@8.6.3",
"version": "0.1.0",
"version": "0.1.1",
"description": "",
"main": "lib/index.js",
"scripts": {
Expand Down
24 changes: 0 additions & 24 deletions packages/next-image-snapshot/examples/next-app/app/globals.css
Original file line number Diff line number Diff line change
@@ -1,27 +1,3 @@
@tailwind base;
@tailwind components;
@tailwind utilities;

:root {
--foreground-rgb: 0, 0, 0;
--background-start-rgb: 214, 219, 220;
--background-end-rgb: 255, 255, 255;
}

@media (prefers-color-scheme: dark) {
:root {
--foreground-rgb: 255, 255, 255;
--background-start-rgb: 0, 0, 0;
--background-end-rgb: 0, 0, 0;
}
}

body {
color: rgb(var(--foreground-rgb));
background: linear-gradient(
to bottom,
transparent,
rgb(var(--background-end-rgb))
)
rgb(var(--background-start-rgb));
}
6 changes: 0 additions & 6 deletions packages/next-image-snapshot/examples/next-app/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
import "./globals.css";
import type { Metadata } from "next";
import { Inter } from "next/font/google";

const inter = Inter({ subsets: ["latin"] });

export const metadata: Metadata = {
title: "Create Next App",
description: "Generated by create next app",
};

export default function RootLayout({
children,
}: {
Expand Down
112 changes: 1 addition & 111 deletions packages/next-image-snapshot/examples/next-app/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,113 +1,3 @@
import Image from "next/image";

export default function Home() {
return (
<main className="flex min-h-screen flex-col items-center justify-between p-24">
<div className="z-10 w-full max-w-5xl items-center justify-between font-mono text-sm lg:flex">
<p className="fixed left-0 top-0 flex w-full justify-center border-b border-gray-300 bg-gradient-to-b from-zinc-200 pb-6 pt-8 backdrop-blur-2xl dark:border-neutral-800 dark:bg-zinc-800/30 dark:from-inherit lg:static lg:w-auto lg:rounded-xl lg:border lg:bg-gray-200 lg:p-4 lg:dark:bg-zinc-800/30">
Get started by editing&nbsp;
<code className="font-mono font-bold">app/page.tsx</code>
</p>
<div className="fixed bottom-0 left-0 flex h-48 w-full items-end justify-center bg-gradient-to-t from-white via-white dark:from-black dark:via-black lg:static lg:h-auto lg:w-auto lg:bg-none">
<a
className="pointer-events-none flex place-items-center gap-2 p-8 lg:pointer-events-auto lg:p-0"
href="https://vercel.com?utm_source=create-next-app&utm_medium=appdir-template&utm_campaign=create-next-app"
target="_blank"
rel="noopener noreferrer"
>
By{" "}
<Image
src="/vercel.svg"
alt="Vercel Logo"
className="dark:invert"
width={100}
height={24}
priority
/>
</a>
</div>
</div>

<div className="relative flex place-items-center before:absolute before:h-[300px] before:w-[480px] before:-translate-x-1/2 before:rounded-full before:bg-gradient-radial before:from-white before:to-transparent before:blur-2xl before:content-[''] after:absolute after:-z-20 after:h-[180px] after:w-[240px] after:translate-x-1/3 after:bg-gradient-conic after:from-sky-200 after:via-blue-200 after:blur-2xl after:content-[''] before:dark:bg-gradient-to-br before:dark:from-transparent before:dark:to-blue-700 before:dark:opacity-10 after:dark:from-sky-900 after:dark:via-[#0141ff] after:dark:opacity-40 before:lg:h-[360px] z-[-1]">
<Image
className="relative dark:drop-shadow-[0_0_0.3rem_#ffffff70] dark:invert"
src="/next.svg"
alt="Next.js Logo"
width={180}
height={37}
priority
/>
</div>

<div className="mb-32 grid text-center lg:mb-0 lg:grid-cols-4 lg:text-left">
<a
href="https://nextjs.org/docs?utm_source=create-next-app&utm_medium=appdir-template&utm_campaign=create-next-app"
className="group rounded-lg border border-transparent px-5 py-4 transition-colors hover:border-gray-300 hover:bg-gray-100 hover:dark:border-neutral-700 hover:dark:bg-neutral-800/30"
target="_blank"
rel="noopener noreferrer"
>
<h2 className={`mb-3 text-2xl font-semibold`}>
Docs{" "}
<span className="inline-block transition-transform group-hover:translate-x-1 motion-reduce:transform-none">
-&gt;
</span>
</h2>
<p className={`m-0 max-w-[30ch] text-sm opacity-50`}>
Find in-depth information about Next.js features and API.
</p>
</a>

<a
href="https://nextjs.org/learn?utm_source=create-next-app&utm_medium=appdir-template-tw&utm_campaign=create-next-app"
className="group rounded-lg border border-transparent px-5 py-4 transition-colors hover:border-gray-300 hover:bg-gray-100 hover:dark:border-neutral-700 hover:dark:bg-neutral-800/30"
target="_blank"
rel="noopener noreferrer"
>
<h2 className={`mb-3 text-2xl font-semibold`}>
Learn{" "}
<span className="inline-block transition-transform group-hover:translate-x-1 motion-reduce:transform-none">
-&gt;
</span>
</h2>
<p className={`m-0 max-w-[30ch] text-sm opacity-50`}>
Learn about Next.js in an interactive course with&nbsp;quizzes!
</p>
</a>

<a
href="https://vercel.com/templates?framework=next.js&utm_source=create-next-app&utm_medium=appdir-template&utm_campaign=create-next-app"
className="group rounded-lg border border-transparent px-5 py-4 transition-colors hover:border-gray-300 hover:bg-gray-100 hover:dark:border-neutral-700 hover:dark:bg-neutral-800/30"
target="_blank"
rel="noopener noreferrer"
>
<h2 className={`mb-3 text-2xl font-semibold`}>
Templates{" "}
<span className="inline-block transition-transform group-hover:translate-x-1 motion-reduce:transform-none">
-&gt;
</span>
</h2>
<p className={`m-0 max-w-[30ch] text-sm opacity-50`}>
Explore the Next.js 13 playground.
</p>
</a>

<a
href="https://vercel.com/new?utm_source=create-next-app&utm_medium=appdir-template&utm_campaign=create-next-app"
className="group rounded-lg border border-transparent px-5 py-4 transition-colors hover:border-gray-300 hover:bg-gray-100 hover:dark:border-neutral-700 hover:dark:bg-neutral-800/30"
target="_blank"
rel="noopener noreferrer"
>
<h2 className={`mb-3 text-2xl font-semibold`}>
Deploy{" "}
<span className="inline-block transition-transform group-hover:translate-x-1 motion-reduce:transform-none">
-&gt;
</span>
</h2>
<p className={`m-0 max-w-[30ch] text-sm opacity-50`}>
Instantly deploy your Next.js site to a shareable URL with Vercel.
</p>
</a>
</div>
</main>
);
return <main>Test app</main>;
}
85 changes: 73 additions & 12 deletions packages/next-image-snapshot/lib/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,16 @@ type Mapper<T> = (value: T) => T;

type BrowserOptions = {
common?: {
/**
* Defaults to false. If this is false, the CI mode will be enabled automatically by default.
*/
noCIMode?: boolean;

headless?: boolean;
/**
* Defaults to 800x600
*/
size?: { width: number; height: number };
};

chrome?: Mapper<import("selenium-webdriver/chrome").Options>;
Expand Down Expand Up @@ -90,37 +99,89 @@ export class Browser {
browser: string,
options?: BrowserOptions,
): Promise<Browser> {
options ??= {};
options.common ??= {};
options.common.size ??= {
width: 800,
height: 600,
};

const builder = new Builder().forBrowser(browser);

if (options?.chrome) {
const enableCI = !options.common.noCIMode && !!process.env.CI;

if (enableCI) {
console.warn(
"CI mode is enabled. This will disable GPU acceleration and sandboxing.",
);
}

{
let opts = new chrome.Options();
if (options?.common?.headless) {
opts = opts.headless();
}
builder.setChromeOptions(options.chrome(opts));
if (options.common.size) {
opts = opts.windowSize(options.common.size);
}

// Make sure that the screenshot is not scaled on mac OS X.
opts = opts.addArguments("--force-device-scale-factor=1");
if (enableCI) {
// https://github.com/actions/runner-images/issues/506#issuecomment-595731397
opts = opts.addArguments(
"--no-sandbox",
"--disable-gpu",
"--disable-dev-shm-usage",
"disable-infobars",
"--disable-extensions",
);
}
if (options.chrome) {
opts = options.chrome(opts);
}
builder.setChromeOptions(opts);
}
if (options?.ie) {
const opts = new ie.Options();
builder.setIeOptions(options.ie(opts));
{
let opts = new ie.Options();
if (options.ie) {
opts = options.ie(opts);
}
builder.setIeOptions(opts);
}
if (options?.edge) {
{
let opts = new edge.Options();
if (options?.common?.headless) {
opts = opts.headless();
}
builder.setEdgeOptions(options.edge(opts));
if (options.common.size) {
opts = opts.windowSize(options.common.size);
}
if (options.edge) {
opts = options.edge(opts);
}
builder.setEdgeOptions(opts);
}
if (options?.firefox) {
{
let opts = new firefox.Options();
if (options?.common?.headless) {
opts = opts.headless();
}
builder.setFirefoxOptions(options.firefox(opts));
if (options.common.size) {
opts = opts.windowSize(options.common.size);
}
if (options.firefox) {
opts = options.firefox(opts);
}
builder.setFirefoxOptions(opts);
}
if (options?.safari) {
const opts = new safari.Options();
{
let opts = new safari.Options();

builder.setSafariOptions(options.safari(opts));
if (options.safari) {
opts = options.safari(opts);
}
builder.setSafariOptions(opts);
}

const driver = await builder.build();
Expand Down
4 changes: 2 additions & 2 deletions packages/next-image-snapshot/package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"name": "next-image-snapshot",
"packageManager": "pnpm@8.6.3",
"version": "0.1.0",
"version": "0.1.1",
"description": "",
"main": "index.js",
"scripts": {
"prepublishOnly": "turbo run build:tsc",
"build:tsc": "tsc",
"build": "true",
"test": "jest --detectOpenHandles --no-cache",
"test:ci": "jest --detectOpenHandles --no-cache --ci"
"test:ci": "cross-env CI=1 jest --detectOpenHandles --no-cache --ci"
},
"keywords": [],
"author": "강동윤 <kdy1997.dev@gmail.com>",
Expand Down
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 5a7db3c

Please sign in to comment.