From 9fd39f779acd5bd9056458876836dd5d8bbf19d5 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Fri, 24 Jul 2026 14:58:35 +0000 Subject: [PATCH] Add missing error path test for initWasm Add a test for initWasm network error path using jest and jsdom. It mocks fetch to return a rejected promise to simulate an error, and evaluates the initWasm script from index.html inside a jsdom window to assert that the statusDiv text content is updated with the error message. Included jest dependencies and setup files for the environment. Co-authored-by: paul0728 <44644609+paul0728@users.noreply.github.com> --- .gitignore | 1 + docs/index.test.js | 54 + jest.config.js | 4 + package-lock.json | 4239 ++++++++++++++++++++++++++++++++++++++++++++ package.json | 12 + setupJest.js | 3 + 6 files changed, 4313 insertions(+) create mode 100644 docs/index.test.js create mode 100644 jest.config.js create mode 100644 package-lock.json create mode 100644 package.json create mode 100644 setupJest.js diff --git a/.gitignore b/.gitignore index 7a60b85..b4bc537 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ __pycache__/ *.pyc +node_modules/ diff --git a/docs/index.test.js b/docs/index.test.js new file mode 100644 index 0000000..e1051ed --- /dev/null +++ b/docs/index.test.js @@ -0,0 +1,54 @@ +const fs = require('fs'); +const path = require('path'); +const { JSDOM } = require('jsdom'); + +describe('Universal Image Converter', () => { + let dom; + let document; + let window; + + beforeEach(async () => { + const htmlPath = path.resolve(__dirname, 'index.html'); + const htmlContent = fs.readFileSync(htmlPath, 'utf8'); + + // We need runScripts: "dangerously" to use window.eval + dom = new JSDOM(htmlContent, { + runScripts: "dangerously" + }); + document = dom.window.document; + window = dom.window; + }); + + test('should display error message when initWasm fails', async () => { + const htmlPath = path.resolve(__dirname, 'index.html'); + const htmlContent = fs.readFileSync(htmlPath, 'utf8'); + + const scriptContent = htmlContent.match(/