diff --git a/jest.config.js b/jest.config.js index 4a58ed0..77c19f9 100644 --- a/jest.config.js +++ b/jest.config.js @@ -9,4 +9,6 @@ module.exports = { // look for test.mjs files "**/?(*.)+(spec|test).?([cm])[tj]s?(x)", ], + // work around for https://github.com/nodejs/node/issues/35889#issuecomment-1129293091 + runner: "jest-light-runner", }; diff --git a/package-lock.json b/package-lock.json index 79da118..7b4abb2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,7 +16,6 @@ "unist-util-visit": "^2.0.3" }, "devDependencies": { - "@jest/globals": "^28.1.2", "eslint": "^8.18.0", "eslint-config-prettier": "^8.5.0", "eslint-plugin-node": "^11.1.0", @@ -24,6 +23,7 @@ "husky": "^8.0.1", "jest": "^28.1.2", "jest-image-snapshot": "^5.1.0", + "jest-light-runner": "^0.3.0", "lint-staged": "^13.0.3", "prettier": "^2.2.1", "puppeteer": "^16.0.0", @@ -48,6 +48,12 @@ "node": ">=6.0.0" } }, + "node_modules/@assemblyscript/loader": { + "version": "0.10.1", + "resolved": "https://registry.npmjs.org/@assemblyscript/loader/-/loader-0.10.1.tgz", + "integrity": "sha512-H71nDOOL8Y7kWRLqf6Sums+01Q5msqBW2KhDUTemh1tvY04eSkSXrK0uj/4mmY0Xr16/3zyZmsrxN7CKuRbNRg==", + "dev": true + }, "node_modules/@babel/code-frame": { "version": "7.18.6", "dev": true, @@ -2468,6 +2474,12 @@ "node": ">=0.10.0" } }, + "node_modules/eventemitter-asyncresource": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/eventemitter-asyncresource/-/eventemitter-asyncresource-1.0.0.tgz", + "integrity": "sha512-39F7TBIV0G7gTelxwbEqnwhp90eqCPON1k0NwNfwhgKn4Co4ybUbj2pECcXT0B3ztRKZ7Pw1JujUUgmQJHcVAQ==", + "dev": true + }, "node_modules/execa": { "version": "6.1.0", "dev": true, @@ -3115,6 +3127,29 @@ "url": "https://opencollective.com/unified" } }, + "node_modules/hdr-histogram-js": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/hdr-histogram-js/-/hdr-histogram-js-2.0.3.tgz", + "integrity": "sha512-Hkn78wwzWHNCp2uarhzQ2SGFLU3JY8SBDDd3TAABK4fc30wm+MuPOrg5QVFVfkKOQd6Bfz3ukJEI+q9sXEkK1g==", + "dev": true, + "dependencies": { + "@assemblyscript/loader": "^0.10.1", + "base64-js": "^1.2.0", + "pako": "^1.0.3" + } + }, + "node_modules/hdr-histogram-js/node_modules/pako": { + "version": "1.0.11", + "resolved": "https://registry.npmjs.org/pako/-/pako-1.0.11.tgz", + "integrity": "sha512-4hLB8Py4zZce5s4yd9XzopqwVv/yGNhV1Bl8NTmCq1763HeK2+EwVTv+leGeL13Dnh2wfbqowVPXCIO0z4taYw==", + "dev": true + }, + "node_modules/hdr-histogram-percentiles-obj": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/hdr-histogram-percentiles-obj/-/hdr-histogram-percentiles-obj-3.0.0.tgz", + "integrity": "sha512-7kIufnBqdsBGcSZLPJwqHT3yhk1QTsSlFsVD3kx5ixH/AlgBs9yM1q6DPhXZ8f8gtdqgh7N7/5btRLpQsS2gHw==", + "dev": true + }, "node_modules/html-escaper": { "version": "2.0.2", "dev": true, @@ -4004,6 +4039,39 @@ "node": "^12.13.0 || ^14.15.0 || ^16.10.0 || >=17.0.0" } }, + "node_modules/jest-light-runner": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/jest-light-runner/-/jest-light-runner-0.3.0.tgz", + "integrity": "sha512-v+2wCos0o/zW6OhJXETt0H9lX6j09A3heIWqDyh9KL9hXrq+2mavBdnngYaLfy4i75XjSNnHGY107u85YqnNmg==", + "dev": true, + "dependencies": { + "@jest/expect": "^28.0.2", + "jest-circus": "^28.0.0", + "jest-each": "^28.0.0", + "jest-mock": "^28.0.0", + "jest-snapshot": "^28.0.0", + "piscina": "^3.1.0", + "supports-color": "^9.2.1" + }, + "engines": { + "node": ">=12.20.0" + }, + "peerDependencies": { + "jest": "^27.0.0 || ^28.0.0" + } + }, + "node_modules/jest-light-runner/node_modules/supports-color": { + "version": "9.2.2", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-9.2.2.tgz", + "integrity": "sha512-XC6g/Kgux+rJXmwokjm9ECpD6k/smUoS5LKlUCcsYr4IY3rW0XyAympon2RmxGrlnZURMpg5T18gWDP9CsHXFA==", + "dev": true, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/chalk/supports-color?sponsor=1" + } + }, "node_modules/jest-matcher-utils": { "version": "28.1.3", "resolved": "https://registry.npmjs.org/jest-matcher-utils/-/jest-matcher-utils-28.1.3.tgz", @@ -5411,6 +5479,28 @@ "dev": true, "license": "MIT" }, + "node_modules/nice-napi": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/nice-napi/-/nice-napi-1.0.2.tgz", + "integrity": "sha512-px/KnJAJZf5RuBGcfD+Sp2pAKq0ytz8j+1NehvgIGFkvtvFrDM3T8E4x/JJODXK9WZow8RRGrbA9QQ3hs+pDhA==", + "dev": true, + "hasInstallScript": true, + "optional": true, + "os": [ + "!win32" + ], + "dependencies": { + "node-addon-api": "^3.0.0", + "node-gyp-build": "^4.2.2" + } + }, + "node_modules/node-addon-api": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-3.2.1.tgz", + "integrity": "sha512-mmcei9JghVNDYydghQmeDX8KoAm0FAiYyIcUt/N4nhyAipB17pllZQDOJD2fotxABnt4Mdz+dKTO7eftLg4d0A==", + "dev": true, + "optional": true + }, "node_modules/node-fetch": { "version": "2.6.7", "license": "MIT", @@ -5445,6 +5535,18 @@ "webidl-conversions": "^3.0.0" } }, + "node_modules/node-gyp-build": { + "version": "4.5.0", + "resolved": "https://registry.npmjs.org/node-gyp-build/-/node-gyp-build-4.5.0.tgz", + "integrity": "sha512-2iGbaQBV+ITgCz76ZEjmhUKAKVf7xfY1sRl4UiKQspfZMH2h06SyhNsnSVy50cwkFQDGLyif6m/6uFXHkOZ6rg==", + "dev": true, + "optional": true, + "bin": { + "node-gyp-build": "bin.js", + "node-gyp-build-optional": "optional.js", + "node-gyp-build-test": "build-test.js" + } + }, "node_modules/node-int64": { "version": "0.4.0", "dev": true, @@ -5736,6 +5838,20 @@ "node": ">= 6" } }, + "node_modules/piscina": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/piscina/-/piscina-3.2.0.tgz", + "integrity": "sha512-yn/jMdHRw+q2ZJhFhyqsmANcbF6V2QwmD84c6xRau+QpQOmtrBCoRGdvTfeuFDYXB5W2m6MfLkjkvQa9lUSmIA==", + "dev": true, + "dependencies": { + "eventemitter-asyncresource": "^1.0.0", + "hdr-histogram-js": "^2.0.1", + "hdr-histogram-percentiles-obj": "^3.0.0" + }, + "optionalDependencies": { + "nice-napi": "^1.0.2" + } + }, "node_modules/pixelmatch": { "version": "5.3.0", "dev": true, @@ -7159,6 +7275,12 @@ "@jridgewell/trace-mapping": "^0.3.9" } }, + "@assemblyscript/loader": { + "version": "0.10.1", + "resolved": "https://registry.npmjs.org/@assemblyscript/loader/-/loader-0.10.1.tgz", + "integrity": "sha512-H71nDOOL8Y7kWRLqf6Sums+01Q5msqBW2KhDUTemh1tvY04eSkSXrK0uj/4mmY0Xr16/3zyZmsrxN7CKuRbNRg==", + "dev": true + }, "@babel/code-frame": { "version": "7.18.6", "dev": true, @@ -8769,6 +8891,12 @@ "version": "2.0.3", "dev": true }, + "eventemitter-asyncresource": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/eventemitter-asyncresource/-/eventemitter-asyncresource-1.0.0.tgz", + "integrity": "sha512-39F7TBIV0G7gTelxwbEqnwhp90eqCPON1k0NwNfwhgKn4Co4ybUbj2pECcXT0B3ztRKZ7Pw1JujUUgmQJHcVAQ==", + "dev": true + }, "execa": { "version": "6.1.0", "dev": true, @@ -9186,6 +9314,31 @@ "space-separated-tokens": "^2.0.0" } }, + "hdr-histogram-js": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/hdr-histogram-js/-/hdr-histogram-js-2.0.3.tgz", + "integrity": "sha512-Hkn78wwzWHNCp2uarhzQ2SGFLU3JY8SBDDd3TAABK4fc30wm+MuPOrg5QVFVfkKOQd6Bfz3ukJEI+q9sXEkK1g==", + "dev": true, + "requires": { + "@assemblyscript/loader": "^0.10.1", + "base64-js": "^1.2.0", + "pako": "^1.0.3" + }, + "dependencies": { + "pako": { + "version": "1.0.11", + "resolved": "https://registry.npmjs.org/pako/-/pako-1.0.11.tgz", + "integrity": "sha512-4hLB8Py4zZce5s4yd9XzopqwVv/yGNhV1Bl8NTmCq1763HeK2+EwVTv+leGeL13Dnh2wfbqowVPXCIO0z4taYw==", + "dev": true + } + } + }, + "hdr-histogram-percentiles-obj": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/hdr-histogram-percentiles-obj/-/hdr-histogram-percentiles-obj-3.0.0.tgz", + "integrity": "sha512-7kIufnBqdsBGcSZLPJwqHT3yhk1QTsSlFsVD3kx5ixH/AlgBs9yM1q6DPhXZ8f8gtdqgh7N7/5btRLpQsS2gHw==", + "dev": true + }, "html-escaper": { "version": "2.0.2", "dev": true @@ -9699,6 +9852,29 @@ "pretty-format": "^28.1.1" } }, + "jest-light-runner": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/jest-light-runner/-/jest-light-runner-0.3.0.tgz", + "integrity": "sha512-v+2wCos0o/zW6OhJXETt0H9lX6j09A3heIWqDyh9KL9hXrq+2mavBdnngYaLfy4i75XjSNnHGY107u85YqnNmg==", + "dev": true, + "requires": { + "@jest/expect": "^28.0.2", + "jest-circus": "^28.0.0", + "jest-each": "^28.0.0", + "jest-mock": "^28.0.0", + "jest-snapshot": "^28.0.0", + "piscina": "^3.1.0", + "supports-color": "^9.2.1" + }, + "dependencies": { + "supports-color": { + "version": "9.2.2", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-9.2.2.tgz", + "integrity": "sha512-XC6g/Kgux+rJXmwokjm9ECpD6k/smUoS5LKlUCcsYr4IY3rW0XyAympon2RmxGrlnZURMpg5T18gWDP9CsHXFA==", + "dev": true + } + } + }, "jest-matcher-utils": { "version": "28.1.3", "resolved": "https://registry.npmjs.org/jest-matcher-utils/-/jest-matcher-utils-28.1.3.tgz", @@ -10611,6 +10787,24 @@ "version": "1.4.0", "dev": true }, + "nice-napi": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/nice-napi/-/nice-napi-1.0.2.tgz", + "integrity": "sha512-px/KnJAJZf5RuBGcfD+Sp2pAKq0ytz8j+1NehvgIGFkvtvFrDM3T8E4x/JJODXK9WZow8RRGrbA9QQ3hs+pDhA==", + "dev": true, + "optional": true, + "requires": { + "node-addon-api": "^3.0.0", + "node-gyp-build": "^4.2.2" + } + }, + "node-addon-api": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-3.2.1.tgz", + "integrity": "sha512-mmcei9JghVNDYydghQmeDX8KoAm0FAiYyIcUt/N4nhyAipB17pllZQDOJD2fotxABnt4Mdz+dKTO7eftLg4d0A==", + "dev": true, + "optional": true + }, "node-fetch": { "version": "2.6.7", "requires": { @@ -10632,6 +10826,13 @@ } } }, + "node-gyp-build": { + "version": "4.5.0", + "resolved": "https://registry.npmjs.org/node-gyp-build/-/node-gyp-build-4.5.0.tgz", + "integrity": "sha512-2iGbaQBV+ITgCz76ZEjmhUKAKVf7xfY1sRl4UiKQspfZMH2h06SyhNsnSVy50cwkFQDGLyif6m/6uFXHkOZ6rg==", + "dev": true, + "optional": true + }, "node-int64": { "version": "0.4.0", "dev": true @@ -10798,6 +10999,18 @@ "version": "4.0.5", "dev": true }, + "piscina": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/piscina/-/piscina-3.2.0.tgz", + "integrity": "sha512-yn/jMdHRw+q2ZJhFhyqsmANcbF6V2QwmD84c6xRau+QpQOmtrBCoRGdvTfeuFDYXB5W2m6MfLkjkvQa9lUSmIA==", + "dev": true, + "requires": { + "eventemitter-asyncresource": "^1.0.0", + "hdr-histogram-js": "^2.0.1", + "hdr-histogram-percentiles-obj": "^3.0.0", + "nice-napi": "^1.0.2" + } + }, "pixelmatch": { "version": "5.3.0", "dev": true, diff --git a/package.json b/package.json index cb8c328..97d0484 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,6 @@ "unist-util-visit": "^2.0.3" }, "devDependencies": { - "@jest/globals": "^28.1.2", "eslint": "^8.18.0", "eslint-config-prettier": "^8.5.0", "eslint-plugin-node": "^11.1.0", @@ -46,6 +45,7 @@ "husky": "^8.0.1", "jest": "^28.1.2", "jest-image-snapshot": "^5.1.0", + "jest-light-runner": "^0.3.0", "lint-staged": "^13.0.3", "prettier": "^2.2.1", "puppeteer": "^16.0.0", diff --git a/test/index.test.mjs b/test/index.test.mjs index 13130a1..9df5d85 100644 --- a/test/index.test.mjs +++ b/test/index.test.mjs @@ -8,10 +8,14 @@ import { launch } from "puppeteer"; import { toMatchImageSnapshot } from "jest-image-snapshot"; import remarkMermaidDataurl from "../index.js"; -import { jest, expect, describe, test } from "@jest/globals"; + +// wish-list, not supported in jest-light-runner +// see https://github.com/nicolo-ribaudo/jest-light-runner/issues/42 +// import { jest, expect, describe, test } from "@jest/globals"; expect.extend({ toMatchImageSnapshot }); -jest.setTimeout(30000); // 30 seconds since mermaid-cli is slow + +const timeout = 30000; // 30 seconds since mermaid-cli is slow /** * Renders a markdown file through `remark-markdown-dataurl`. @@ -84,70 +88,106 @@ async function testScreenshotSnapshot( } describe("test markdown files", () => { - test("should render basic.md without errors", async () => { - await renderWithRemark( - "test/fixtures/basic.in.md", - "test/fixtures/basic.out.md" - ); - }); - - test("should render basic.md visually", async () => { - await testScreenshotSnapshot("test/fixtures/basic.in.md"); - }); - - test("should render git graphs correctly", async () => { - await renderWithRemark( - "test/fixtures/gitgraph.in.md", - "test/fixtures/gitgraph.out.md" - ); - }); - - test("should render git graphs visually", async () => { - await testScreenshotSnapshot("test/fixtures/gitgraph.in.md"); - }); - - test("should render flowcharts visually", async () => { - await testScreenshotSnapshot("test/fixtures/flowchart.in.md"); - }); - - test("should render flowcharts correctly", async () => { - await renderWithRemark( - "test/fixtures/flowchart.in.md", - "test/fixtures/flowchart.out.md" - ); - }); - - test("should fail to render invalid mermaid visually", async () => { - await expect( - testScreenshotSnapshot("test/fixtures/invalid.in.md") - ).rejects.toThrow("Parse error"); - }); - - test("should use puppeteer config", async () => { - await expect( - renderWithRemark( + test( + "should render basic.md without errors", + async () => { + await renderWithRemark( + "test/fixtures/basic.in.md", + "test/fixtures/basic.out.md" + ); + }, + timeout + ); + + test( + "should render basic.md visually", + async () => { + await testScreenshotSnapshot("test/fixtures/basic.in.md"); + }, + timeout + ); + + test( + "should render git graphs correctly", + async () => { + await renderWithRemark( "test/fixtures/gitgraph.in.md", - "test/fixtures/should-never-happen.out.md", - { + "test/fixtures/gitgraph.out.md" + ); + }, + timeout + ); + + test( + "should render git graphs visually", + async () => { + await testScreenshotSnapshot("test/fixtures/gitgraph.in.md"); + }, + timeout + ); + + test( + "should render flowcharts visually", + async () => { + await testScreenshotSnapshot("test/fixtures/flowchart.in.md"); + }, + timeout + ); + + test( + "should render flowcharts correctly", + async () => { + await renderWithRemark( + "test/fixtures/flowchart.in.md", + "test/fixtures/flowchart.out.md" + ); + }, + timeout + ); + + test( + "should fail to render invalid mermaid visually", + async () => { + await expect( + testScreenshotSnapshot("test/fixtures/invalid.in.md") + ).rejects.toThrow("Parse error"); + }, + timeout + ); + + test( + "should use puppeteer config", + async () => { + await expect( + renderWithRemark( + "test/fixtures/gitgraph.in.md", + "test/fixtures/should-never-happen.out.md", + { + mermaidCli: { + puppeteerConfigFile: { + timeout: 1, // should fail + }, + }, + } + ) + ).rejects.toThrow("Timed out"); + }, + timeout + ); + + test( + "should use mermaid-cli to use forest theme", + async () => { + await testScreenshotSnapshot("test/fixtures/basic.in.md", { + remarkOptions: { mermaidCli: { - puppeteerConfigFile: { - timeout: 1, // should fail + configFile: { + theme: "forest", }, }, - } - ) - ).rejects.toThrow("TimeoutError"); - }); - - test("should use mermaid-cli to use forest theme", async () => { - await testScreenshotSnapshot("test/fixtures/basic.in.md", { - remarkOptions: { - mermaidCli: { - configFile: { - theme: "forest", - }, }, - }, - }); - }); + }); + }, + timeout + ); });