Skip to content

Commit

Permalink
add browser tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hipstersmoothie committed Mar 29, 2024
1 parent 44068b1 commit d80ad56
Show file tree
Hide file tree
Showing 111 changed files with 1,156 additions and 195 deletions.
1 change: 0 additions & 1 deletion TODO.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# TODO

- [ ] Browser tests
- [ ] Object APIs

## Guides
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"dev": "turbo run dev",
"lint": "turbo run lint",
"test": "turbo run test -- --watch=false",
"test:browser": "turbo run test:browser -- --watch=false",
"clean": "turbo run clean && rm -rf node_modules .turbo",
"format": "prettier --write \"**/*.{ts,tsx,md}\"",
"release": "turbo run build --filter=docs^... && changeset publish",
Expand Down
23 changes: 14 additions & 9 deletions packages/config-vitest/browser.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { defineConfig } from "vitest/config";
import { NodeGlobalsPolyfillPlugin } from "@esbuild-plugins/node-globals-polyfill";
import { createRequire } from "module";
import path from "path";
import { nodePolyfills } from "vite-plugin-node-polyfills";

const require = createRequire(import.meta.url);
const imagesFolder = path.join(
Expand All @@ -10,8 +10,15 @@ const imagesFolder = path.join(
);

export default defineConfig({
resolve: {
alias: {
pngjs: "pngjs/browser.js",
},
},
test: {
exclude: [
"**/.tshy-build",
"**/.tshy",
"**/*.node.test.ts",
"**/node_modules/**",
"**/dist/**",
Expand All @@ -27,13 +34,11 @@ export default defineConfig({
},
},
publicDir: imagesFolder,
optimizeDeps: {
include: ["@jimp/core"],
esbuildOptions: {
define: {
global: "globalThis",
plugins: [
nodePolyfills({
globals: {
Buffer: true,
},
plugins: [NodeGlobalsPolyfillPlugin({ buffer: true })],
},
},
}),
],
});
4 changes: 2 additions & 2 deletions packages/config-vitest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"repository": "jimp-dev/jimp",
"scripts": {
"lint": "eslint .",
"test": "vitest",
"dev": "tshy --watch"
},
"author": "Andrew Lisowski <[email protected]>",
Expand All @@ -19,7 +18,8 @@
},
"dependencies": {
"@esbuild-plugins/node-globals-polyfill": "^0.2.3",
"playwright": "^1.42.1"
"playwright": "^1.42.1",
"vite-plugin-node-polyfills": "^0.21.0"
},
"type": "module"
}
6 changes: 5 additions & 1 deletion packages/jimp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"scripts": {
"lint": "eslint .",
"test": "vitest",
"test:browser": "vitest --config vitest.config.browser.ts",
"build": "tshy",
"dev": "tshy --watch",
"clean": "rm -rf node_modules .tshy .tshy-build dist"
Expand Down Expand Up @@ -63,11 +64,14 @@
"devDependencies": {
"@jimp/config-eslint": "workspace:*",
"@jimp/config-typescript": "workspace:*",
"@jimp/config-vitest": "workspace:*",
"@jimp/test-utils": "workspace:*",
"eslint": "^8.57.0",
"tshy": "^1.12.0",
"typescript": "^5.4.2",
"vitest": "^1.4.0"
"@vitest/browser": "^1.4.0",
"vitest": "^1.4.0",
"vite-plugin-node-polyfills": "^0.21.0"
},
"tshy": {
"exclude": [
Expand Down
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
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
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
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
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
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
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
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
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.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect, test, describe } from "vitest";
import fs from "fs";

import "@jimp/test-utils/image-snapshot";
import { getTestImagePath } from "@jimp/test-utils";

import { Jimp, BlendMode } from "./index.js";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect, test, describe } from "vitest";
import "@jimp/test-utils";
import "@jimp/test-utils/image-snapshot";

import { getExifOrientation } from "@jimp/core";
import { Jimp, distance } from "./index.js";
Expand Down
3 changes: 3 additions & 0 deletions packages/jimp/vitest.config.browser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import config from "@jimp/config-vitest/browser";

export default config;
File renamed without changes
File renamed without changes
3 changes: 3 additions & 0 deletions packages/test-utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,9 @@ export function getTestImagePath(
| "rgb.tiff"
| "windows95.png"
| "windows95.bmp"
| "fillbytes.jpg"
| "hands.jpg"
| "hands_mx200_rp255.jpg"
) {
if (typeof window !== "undefined") {
return `/${name}`;
Expand Down
3 changes: 2 additions & 1 deletion plugins/js-bmp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"tshy": "^1.12.0",
"typescript": "^5.4.2",
"@vitest/browser": "^1.4.0",
"vitest": "^1.4.0"
"vitest": "^1.4.0",
"vite-plugin-node-polyfills": "^0.21.0"
},
"tshy": {
"exclude": [
Expand Down
17 changes: 17 additions & 0 deletions plugins/js-bmp/src/index.node.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { describe, expect, test } from "vitest";
import { createJimp } from "@jimp/core";
import { getTestImagePath } from "@jimp/test-utils";

import png from "@jimp/js-png";
import bmp from "./index.js";

const jimp = createJimp({ formats: [bmp, png] });

describe("BMP", () => {
test("uses correct colors for BMP", async function () {
const expectedImg = await jimp.read(getTestImagePath("windows95.png"));
const image = await jimp.read(getTestImagePath("windows95.bmp"));

expect(image.bitmap.data).toEqual(expectedImg.bitmap.data);
});
});
10 changes: 2 additions & 8 deletions plugins/js-bmp/src/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { describe, expect, test } from "vitest";
import { createJimp } from "@jimp/core";
import { getTestImagePath } from "@jimp/test-utils";

import png from "@jimp/js-png";
import bmp from "./index.js";
Expand All @@ -8,7 +9,7 @@ const jimp = createJimp({ formats: [bmp, png] });

describe("BMP", () => {
test("load BMP", async () => {
const image = await jimp.read(__dirname + "/images/windows95.bmp");
const image = await jimp.read(getTestImagePath("windows95.bmp"));

expect(image.getPixelColor(10, 10)).toBe(0xeff7f7ff);
expect(image.getPixelColor(150, 80)).toBe(0x73add6ff);
Expand All @@ -28,11 +29,4 @@ describe("BMP", () => {

expect(buffer.toString()).toMatch(/^BM/);
});

test("uses correct colors for BMP", async function () {
const expectedImg = await jimp.read(__dirname + "/images/windows95.png");
const image = await jimp.read(__dirname + "/images/windows95.bmp");

expect(image.bitmap.data).toEqual(expectedImg.bitmap.data);
});
});
6 changes: 5 additions & 1 deletion plugins/js-gif/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"scripts": {
"lint": "eslint .",
"test": "vitest",
"test:browser": "vitest --config vitest.config.browser.ts",
"build": "tshy",
"dev": "tshy --watch"
},
Expand All @@ -13,12 +14,15 @@
"devDependencies": {
"@jimp/config-eslint": "workspace:*",
"@jimp/config-typescript": "workspace:*",
"@jimp/config-vitest": "workspace:*",
"@jimp/test-utils": "workspace:*",
"@types/omggif": "^1.0.5",
"eslint": "^8.57.0",
"tshy": "^1.12.0",
"typescript": "^5.4.2",
"vitest": "^1.4.0"
"@vitest/browser": "^1.4.0",
"vitest": "^1.4.0",
"vite-plugin-node-polyfills": "^0.21.0"
},
"tshy": {
"exclude": [
Expand Down
3 changes: 3 additions & 0 deletions plugins/js-gif/vitest.config.browser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import config from "@jimp/config-vitest/browser";

export default config;
6 changes: 5 additions & 1 deletion plugins/js-jpeg/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"scripts": {
"lint": "eslint .",
"test": "vitest",
"test:browser": "vitest --config vitest.config.browser.ts",
"build": "tshy",
"dev": "tshy --watch"
},
Expand All @@ -13,11 +14,14 @@
"devDependencies": {
"@jimp/config-eslint": "workspace:*",
"@jimp/config-typescript": "workspace:*",
"@jimp/config-vitest": "workspace:*",
"@jimp/test-utils": "workspace:*",
"eslint": "^8.57.0",
"tshy": "^1.12.0",
"typescript": "^5.4.2",
"vitest": "^1.4.0"
"@vitest/browser": "^1.4.0",
"vitest": "^1.4.0",
"vite-plugin-node-polyfills": "^0.21.0"
},
"tshy": {
"exclude": [
Expand Down
4 changes: 1 addition & 3 deletions plugins/js-jpeg/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import jpeg from "./index.js";
const jimp = createJimp({ formats: [jpeg] });

describe("JPEG", () => {
const imagesDir = __dirname + "/images";

test("load JPG", async () => {
const image = await jimp.read(getTestImagePath("cops.jpg"));

Expand All @@ -18,7 +16,7 @@ describe("JPEG", () => {
});

test("load JPG with fill bytes", async () => {
const image = await jimp.read(imagesDir + "/fillbytes.jpg");
const image = await jimp.read(getTestImagePath("fillbytes.jpg"));

expect(image.getPixelColor(10, 10)).toBe(0xaeb8c3ff);
expect(image.getPixelColor(220, 190)).toBe(0x262b21ff);
Expand Down
3 changes: 3 additions & 0 deletions plugins/js-jpeg/vitest.config.browser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import config from "@jimp/config-vitest/browser";

export default config;
5 changes: 3 additions & 2 deletions plugins/js-png/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@
"@jimp/config-vitest": "workspace:*",
"@jimp/test-utils": "workspace:*",
"@types/pngjs": "^6.0.4",
"@vitest/browser": "^1.4.0",
"eslint": "^8.57.0",
"tshy": "^1.12.0",
"typescript": "^5.4.2",
"@vitest/browser": "^1.4.0",
"vitest": "^1.4.0"
"vitest": "^1.4.0",
"vite-plugin-node-polyfills": "^0.21.0"
},
"tshy": {
"exclude": [
Expand Down
3 changes: 1 addition & 2 deletions plugins/js-png/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// @ts-ignore
import { PNG, PNGOptions as PNGJSOptions } from "pngjs/browser.js";
import { PNG, PNGOptions as PNGJSOptions } from "pngjs";
import { Format } from "@jimp/types";
import { PNGFilterType, PNGColorType } from "./constants.js";

Expand Down
6 changes: 5 additions & 1 deletion plugins/js-tiff/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"scripts": {
"lint": "eslint .",
"test": "vitest",
"test:browser": "vitest --config vitest.config.browser.ts",
"build": "tshy",
"dev": "tshy --watch"
},
Expand All @@ -13,11 +14,14 @@
"devDependencies": {
"@jimp/config-eslint": "workspace:*",
"@jimp/config-typescript": "workspace:*",
"@jimp/config-vitest": "workspace:*",
"@jimp/test-utils": "workspace:*",
"eslint": "^8.57.0",
"tshy": "^1.12.0",
"typescript": "^5.4.2",
"vitest": "^1.4.0"
"@vitest/browser": "^1.4.0",
"vitest": "^1.4.0",
"vite-plugin-node-polyfills": "^0.21.0"
},
"tshy": {
"exclude": [
Expand Down
3 changes: 3 additions & 0 deletions plugins/js-tiff/vitest.config.browser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import config from "@jimp/config-vitest/browser";

export default config;
6 changes: 5 additions & 1 deletion plugins/plugin-blit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"scripts": {
"lint": "eslint .",
"test": "vitest",
"test:browser": "vitest --config vitest.config.browser.ts",
"build": "tshy",
"dev": "tshy --watch",
"clean": "rm -rf node_modules .tshy .tshy-build dist"
Expand All @@ -22,10 +23,13 @@
"@jimp/test-utils": "workspace:*",
"@jimp/config-eslint": "workspace:*",
"@jimp/config-typescript": "workspace:*",
"@jimp/config-vitest": "workspace:*",
"eslint": "^8.57.0",
"tshy": "^1.12.0",
"typescript": "^5.4.2",
"vitest": "^1.4.0"
"@vitest/browser": "^1.4.0",
"vitest": "^1.4.0",
"vite-plugin-node-polyfills": "^0.21.0"
},
"tshy": {
"exports": {
Expand Down
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
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 d80ad56

Please sign in to comment.