From a2def1e3a5200b06f2828e4c9d75338938f62a1c Mon Sep 17 00:00:00 2001 From: Mike Bland Date: Fri, 5 Jan 2024 17:09:17 -0500 Subject: [PATCH] Bump to v1.0.2, add .js extension to local imports MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit After installing v1.0.1 in a local copy of mbland/tomcat-servlet-testing-example, running the tests against jsdom broke with: ```text FAIL main.test.js [ main.test.js ] Error: Cannot find module '.../tomcat-servlet-testing-example/strcalc/src/main/frontend/node_modules/.pnpm/test-page-opener@1.0.1/node_modules/test-page-opener/lib/browser' imported from .../tomcat-servlet-testing-example/strcalc/src/main/frontend/node_modules/.pnpm/test-page-opener@1.0.1/node_modules/test-page-opener/index.js ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Serialized Error: { code: 'ERR_MODULE_NOT_FOUND', url: 'file:///.../tomcat-servlet-testing-example/strcalc/src/main/frontend/node_modules/.pnpm/test-page-opener@1.0.1/node_modules/test-page-opener/lib/browser' } ``` Running `pnpm link ../../../../../test-page-opener` and running the tests again worked, so I wouldn't've caught this before releasing v1.0.1, either. And apparently this is quite a thing, especially impacting TypeScript users: - https://www.google.com/search?q=node+import+requires+.js+extension - https://github.com/nodejs/node/issues/46006 - https://nodejs.org/docs/latest-v18.x/api/esm.html#import-specifiers So be it. --- index.js | 6 +++--- lib/browser.js | 2 +- lib/jsdom.js | 2 +- package.json | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index 31349f2..cc9c64f 100644 --- a/index.js +++ b/index.js @@ -4,9 +4,9 @@ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ -import BrowserPageOpener from './lib/browser' -import JsdomPageOpener from './lib/jsdom' -import { OpenedPage } from './lib/types' +import BrowserPageOpener from './lib/browser.js' +import JsdomPageOpener from './lib/jsdom.js' +import { OpenedPage } from './lib/types.js' /** * Enables tests to open an application's own page URLs both in the browser and diff --git a/lib/browser.js b/lib/browser.js index 2ed2557..86a9226 100644 --- a/lib/browser.js +++ b/lib/browser.js @@ -6,7 +6,7 @@ */ import { createCoverageMap } from 'istanbul-lib-coverage' -import { OpenedPage } from './types' +import { OpenedPage } from './types.js' /** * Returns the window and document from a browser-opened HTML file. diff --git a/lib/jsdom.js b/lib/jsdom.js index d5a2ca5..b503967 100644 --- a/lib/jsdom.js +++ b/lib/jsdom.js @@ -5,7 +5,7 @@ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ -import { OpenedPage } from './types' +import { OpenedPage } from './types.js' /** * Returns window and document objects from a jsdom-parsed HTML file. diff --git a/package.json b/package.json index 4b57092..5ebb767 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "test-page-opener", - "version": "1.0.1", + "version": "1.0.2", "description": "Enables an application's tests to open its own page URLs both in the browser and in Node.js using jsdom", "main": "index.js", "scripts": {