From 5425097e810de1b0624cfabfd2abdec356415c08 Mon Sep 17 00:00:00 2001 From: Steven Lambert <2433219+straker@users.noreply.github.com> Date: Thu, 16 Nov 2023 16:04:18 -0700 Subject: [PATCH 1/5] fix(webdriverjs): fix default commonJs export --- .github/workflows/tests.yml | 12 ++++++------ packages/playwright/package.json | 2 ++ packages/playwright/test/commonjsTest.js | 11 +++++++++++ packages/playwright/test/esmTest.mjs | 7 +++++-- packages/puppeteer/package.json | 2 ++ packages/puppeteer/test/commonjsTest.js | 11 +++++++++++ packages/puppeteer/test/esmTest.mjs | 13 +++++++------ packages/react/package.json | 4 +++- packages/react/setupGlobals.mjs | 4 ---- packages/react/test/commonjsTest.js | 8 ++++++++ packages/react/{ => test}/esmTest.mjs | 6 ++++-- packages/react/test/setupGlobals.mjs | 2 ++ packages/reporter-earl/package.json | 4 +++- packages/reporter-earl/tests/commonjsTest.js | 6 ++++++ packages/reporter-earl/{ => tests}/esmTest.mjs | 3 ++- packages/webdriverio/package.json | 2 ++ packages/webdriverio/test/commonjsTest.js | 11 +++++++++++ packages/webdriverio/test/esmTest.mjs | 6 ++++-- packages/webdriverjs/example.js | 4 +++- packages/webdriverjs/package.json | 2 ++ packages/webdriverjs/src/index.ts | 6 ++++++ packages/webdriverjs/test/commonjsTest.js | 11 +++++++++++ packages/webdriverjs/test/esmTest.mjs | 7 +++++-- 23 files changed, 116 insertions(+), 28 deletions(-) create mode 100644 packages/playwright/test/commonjsTest.js create mode 100644 packages/puppeteer/test/commonjsTest.js delete mode 100644 packages/react/setupGlobals.mjs create mode 100644 packages/react/test/commonjsTest.js rename packages/react/{ => test}/esmTest.mjs (72%) create mode 100644 packages/react/test/setupGlobals.mjs create mode 100644 packages/reporter-earl/tests/commonjsTest.js rename packages/reporter-earl/{ => tests}/esmTest.mjs (60%) create mode 100644 packages/webdriverio/test/commonjsTest.js create mode 100644 packages/webdriverjs/test/commonjsTest.js diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index a897ab4a..44229ea7 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -41,7 +41,7 @@ jobs: working-directory: packages/puppeteer - run: npm run build --workspace=packages/puppeteer - run: npm run coverage --workspace=packages/puppeteer - - run: npm run test:esm --workspace=packages/puppeteer + - run: npm run test:export --workspace=packages/puppeteer cli: strategy: @@ -83,7 +83,7 @@ jobs: working-directory: packages/webdriverjs - run: npm run build --workspace=packages/webdriverjs - run: npm run coverage --workspace=packages/webdriverjs - - run: npm run test:esm --workspace=packages/webdriverjs + - run: npm run test:export --workspace=packages/webdriverjs webdriverio: strategy: @@ -105,7 +105,7 @@ jobs: working-directory: packages/webdriverio - run: npm run build --workspace=packages/webdriverio - run: npm run coverage --workspace=packages/webdriverio - - run: npm run test:esm --workspace=packages/webdriverio + - run: npm run test:export --workspace=packages/webdriverio reporter_earl: strategy: @@ -123,7 +123,7 @@ jobs: - run: npm ci - run: npm run build --workspace=packages/reporter-earl - run: npm run test --workspace=packages/reporter-earl - - run: npm run test:esm --workspace=packages/reporter-earl + - run: npm run test:export --workspace=packages/reporter-earl react: strategy: @@ -141,7 +141,7 @@ jobs: - run: npm ci - run: npm run build --workspace=packages/react - run: npm run test --workspace=packages/react - - run: npm run test:esm --workspace=packages/react + - run: npm run test:export --workspace=packages/react playwright: strategy: @@ -160,7 +160,7 @@ jobs: - run: npx playwright install --with-deps - run: npm run build --workspace=packages/playwright - run: npm run coverage --workspace=packages/playwright - - run: npm run test:esm --workspace=packages/playwright + - run: npm run test:export --workspace=packages/playwright wdio_globals_test: strategy: diff --git a/packages/playwright/package.json b/packages/playwright/package.json index 92439c88..b9f4d914 100644 --- a/packages/playwright/package.json +++ b/packages/playwright/package.json @@ -43,7 +43,9 @@ "prebuild": "rimraf dist", "build": "tsup src/index.ts --dts --format esm,cjs", "test": "mocha --timeout 60000 -r ts-node/register 'test/**.spec.ts'", + "test:export": "npm run test:esm && npm run test:commonjs", "test:esm": "node test/esmTest.mjs", + "test:commonjs": "node test/commonjsTest.js", "coverage": "nyc npm run test", "prepare": "npx playwright install && npm run build" }, diff --git a/packages/playwright/test/commonjsTest.js b/packages/playwright/test/commonjsTest.js new file mode 100644 index 00000000..399ed177 --- /dev/null +++ b/packages/playwright/test/commonjsTest.js @@ -0,0 +1,11 @@ +// ensure backwards compatibility of commonJs format +const defaultExport = require('../dist/index.js').default; +const { AxeBuilder } = require('../dist/index.js'); +const assert = require('assert'); + +assert(typeof defaultExport === 'function', 'default export is not a function'); +assert(typeof AxeBuilder === 'function', 'named export is not a function'); +assert( + defaultExport === AxeBuilder, + 'default and named export are not the same' +); diff --git a/packages/playwright/test/esmTest.mjs b/packages/playwright/test/esmTest.mjs index 0a2ffa4d..eb852e5a 100644 --- a/packages/playwright/test/esmTest.mjs +++ b/packages/playwright/test/esmTest.mjs @@ -1,5 +1,8 @@ +// ensure compatibility of ESM format import defaultExport from '../dist/index.mjs'; +import { AxeBuilder } from '../dist/index.mjs'; import assert from 'assert'; -const exportIsFunction = typeof defaultExport === 'function'; -assert(exportIsFunction, 'export is not a function'); +assert(typeof defaultExport === 'function', 'default export is not a function'); +assert(typeof AxeBuilder === 'function', 'named export is not a function') +assert(defaultExport === AxeBuilder, 'default and named export are not the same'); \ No newline at end of file diff --git a/packages/puppeteer/package.json b/packages/puppeteer/package.json index 24834a3a..9331a8c4 100644 --- a/packages/puppeteer/package.json +++ b/packages/puppeteer/package.json @@ -25,7 +25,9 @@ "scripts": { "build": "tsup src/index.ts --dts --format esm,cjs", "test": "mocha --timeout 60000 -r ts-node/register 'test/**.spec.ts'", + "test:export": "npm run test:esm && npm run test:commonjs", "test:esm": "node test/esmTest.mjs", + "test:commonjs": "node test/commonjsTest.js", "coverage": "nyc npm run test", "prepublishOnly": "npm run build" }, diff --git a/packages/puppeteer/test/commonjsTest.js b/packages/puppeteer/test/commonjsTest.js new file mode 100644 index 00000000..c051ef53 --- /dev/null +++ b/packages/puppeteer/test/commonjsTest.js @@ -0,0 +1,11 @@ +// ensure backwards compatibility of commonJs format +const defaultExport = require('../dist/index.js').default; +const { AxePuppeteer } = require('../dist/index.js'); +const assert = require('assert'); + +assert(typeof defaultExport === 'function', 'default export is not a function'); +assert(typeof AxePuppeteer === 'function', 'named export is not a function'); +assert( + defaultExport === AxePuppeteer, + 'default and named export are not the same' +); diff --git a/packages/puppeteer/test/esmTest.mjs b/packages/puppeteer/test/esmTest.mjs index f1d61ba2..5861801b 100644 --- a/packages/puppeteer/test/esmTest.mjs +++ b/packages/puppeteer/test/esmTest.mjs @@ -1,14 +1,15 @@ -import defaultExport, { AxePuppeteer } from '../dist/index.mjs'; +// ensure compatibility of ESM format +import defaultExport from '../dist/index.mjs'; +import { AxePuppeteer } from '../dist/index.mjs'; import assert from 'assert'; import puppeteer from 'puppeteer'; import { fileURLToPath, pathToFileURL } from 'url'; import { join } from 'path'; import { fixturesPath } from 'axe-test-fixtures'; -const exportIsFunction = typeof defaultExport === 'function'; -const exportIsSame = defaultExport === AxePuppeteer; -assert(exportIsFunction, 'export is not a function'); -assert(exportIsSame, 'default and named export is not the same'); +assert(typeof defaultExport === 'function', 'default export is not a function'); +assert(typeof AxePuppeteer === 'function', 'named export is not a function') +assert(defaultExport === AxePuppeteer, 'default and named export are not the same'); const options = {}; @@ -30,4 +31,4 @@ async function integrationTest() { await page.close(); await browser.close(); } -integrationTest(); +integrationTest(); \ No newline at end of file diff --git a/packages/react/package.json b/packages/react/package.json index a1bf841d..4dc39c53 100644 --- a/packages/react/package.json +++ b/packages/react/package.json @@ -28,7 +28,9 @@ "build": "tsup index.ts --dts --format esm,cjs", "prepare": "npm run build", "test": "tsc && npm run test:types && jest", - "test:esm": "node esmTest.mjs", + "test:export": "npm run test:esm && npm run test:commonjs", + "test:esm": "node test/esmTest.mjs", + "test:commonjs": "node test/commonjsTest.js", "test:types": "cd test && tsc" }, "keywords": [ diff --git a/packages/react/setupGlobals.mjs b/packages/react/setupGlobals.mjs deleted file mode 100644 index 62080241..00000000 --- a/packages/react/setupGlobals.mjs +++ /dev/null @@ -1,4 +0,0 @@ -global.window = {}; -global.document = {}; - -export default {}; diff --git a/packages/react/test/commonjsTest.js b/packages/react/test/commonjsTest.js new file mode 100644 index 00000000..b4732c0a --- /dev/null +++ b/packages/react/test/commonjsTest.js @@ -0,0 +1,8 @@ +// ensure backwards compatibility of commonJs format +global.window = {}; +global.document = {}; + +const defaultExport = require('../dist/index.js'); +const assert = require('assert'); + +assert(typeof defaultExport === 'function', 'export is not a function'); diff --git a/packages/react/esmTest.mjs b/packages/react/test/esmTest.mjs similarity index 72% rename from packages/react/esmTest.mjs rename to packages/react/test/esmTest.mjs index a3c3e891..f1ef59f7 100644 --- a/packages/react/esmTest.mjs +++ b/packages/react/test/esmTest.mjs @@ -1,8 +1,10 @@ +// ensure compatibility of ESM format + // in order to properly set global placeholders for `window` and `document` we have to // import a file that does that. // Setting them in this file will not work. -import _ from './setupGlobals.mjs'; -import defaultExport from './dist/index.mjs'; +import './setupGlobals.mjs'; +import defaultExport from '../dist/index.mjs'; import assert from 'assert'; const exportIsFunction = typeof defaultExport === 'function'; diff --git a/packages/react/test/setupGlobals.mjs b/packages/react/test/setupGlobals.mjs new file mode 100644 index 00000000..ce0265f4 --- /dev/null +++ b/packages/react/test/setupGlobals.mjs @@ -0,0 +1,2 @@ +global.window = {}; +global.document = {}; \ No newline at end of file diff --git a/packages/reporter-earl/package.json b/packages/reporter-earl/package.json index 775d87d0..df8368da 100644 --- a/packages/reporter-earl/package.json +++ b/packages/reporter-earl/package.json @@ -15,7 +15,9 @@ "scripts": { "start": "NODE_OPTIONS=--experimental-vm-modules jest --watch --env=jsdom", "test": "npm run build && npm run test:unit", - "test:esm": "node esmTest.mjs", + "test:export": "npm run test:esm && npm run test:commonjs", + "test:esm": "node tests/esmTest.mjs", + "test:commonjs": "node tests/commonjsTest.js", "test:unit": "NODE_OPTIONS=--experimental-vm-modules jest --collectCoverage", "build": "tsup src/axeReporterEarl.ts --dts --format esm,cjs", "prepublishOnly": "npm run build" diff --git a/packages/reporter-earl/tests/commonjsTest.js b/packages/reporter-earl/tests/commonjsTest.js new file mode 100644 index 00000000..6bf9a838 --- /dev/null +++ b/packages/reporter-earl/tests/commonjsTest.js @@ -0,0 +1,6 @@ +// ensure backwards compatibility of commonJs format +const defaultExport = require('../dist/axeReporterEarl.js').default; +const assert = require('assert'); + +const exportIsFunction = typeof defaultExport === 'function'; +assert(exportIsFunction, 'export is not a function'); diff --git a/packages/reporter-earl/esmTest.mjs b/packages/reporter-earl/tests/esmTest.mjs similarity index 60% rename from packages/reporter-earl/esmTest.mjs rename to packages/reporter-earl/tests/esmTest.mjs index 9addf7b8..b73557fc 100644 --- a/packages/reporter-earl/esmTest.mjs +++ b/packages/reporter-earl/tests/esmTest.mjs @@ -1,4 +1,5 @@ -import defaultExport from './dist/axeReporterEarl.mjs'; +// ensure compatibility of ESM format +import defaultExport from '../dist/axeReporterEarl.mjs'; import assert from 'assert'; const exportIsFunction = typeof defaultExport === 'function'; diff --git a/packages/webdriverio/package.json b/packages/webdriverio/package.json index 8c21a684..3eed32b4 100644 --- a/packages/webdriverio/package.json +++ b/packages/webdriverio/package.json @@ -29,7 +29,9 @@ "prebuild": "rimraf dist", "build": "tsup src/index.ts --dts --format esm,cjs", "test": "mocha --timeout 60000 -r ts-node/register 'test/**.spec.ts'", + "test:export": "npm run test:esm && npm run test:commonjs", "test:esm": "node test/esmTest.mjs", + "test:commonjs": "node test/commonjsTest.js", "coverage": "nyc npm run test", "prepare": "npm run build" }, diff --git a/packages/webdriverio/test/commonjsTest.js b/packages/webdriverio/test/commonjsTest.js new file mode 100644 index 00000000..399ed177 --- /dev/null +++ b/packages/webdriverio/test/commonjsTest.js @@ -0,0 +1,11 @@ +// ensure backwards compatibility of commonJs format +const defaultExport = require('../dist/index.js').default; +const { AxeBuilder } = require('../dist/index.js'); +const assert = require('assert'); + +assert(typeof defaultExport === 'function', 'default export is not a function'); +assert(typeof AxeBuilder === 'function', 'named export is not a function'); +assert( + defaultExport === AxeBuilder, + 'default and named export are not the same' +); diff --git a/packages/webdriverio/test/esmTest.mjs b/packages/webdriverio/test/esmTest.mjs index d0544c51..851855f2 100644 --- a/packages/webdriverio/test/esmTest.mjs +++ b/packages/webdriverio/test/esmTest.mjs @@ -1,12 +1,14 @@ import defaultExport from '../dist/index.mjs'; +import { AxeBuilder } from '../dist/index.mjs'; import assert from 'assert'; import * as webdriverio from 'webdriverio'; import { fileURLToPath, pathToFileURL } from 'url'; import { join } from 'path'; import { fixturesPath } from 'axe-test-fixtures'; -const exportIsFunction = typeof defaultExport === 'function'; -assert(exportIsFunction, 'export is not a function'); +assert(typeof defaultExport === 'function', 'default export is not a function'); +assert(typeof AxeBuilder === 'function', 'named export is not a function') +assert(defaultExport === AxeBuilder, 'default and named export are not the same'); async function integrationTest() { const path = join(fixturesPath, 'index.html'); diff --git a/packages/webdriverjs/example.js b/packages/webdriverjs/example.js index a5b3215c..21ffc50a 100644 --- a/packages/webdriverjs/example.js +++ b/packages/webdriverjs/example.js @@ -1,7 +1,9 @@ -const { AxeBuilder } = require('@axe-core/webdriverjs'); +const { AxeBuilder } = require('./dist/index'); const { Builder } = require('selenium-webdriver'); const chrome = require('selenium-webdriver/chrome'); +console.log(AxeBuilder); + (async () => { const driver = new Builder() .forBrowser('chrome') diff --git a/packages/webdriverjs/package.json b/packages/webdriverjs/package.json index 0fbdaf5b..6be01e67 100644 --- a/packages/webdriverjs/package.json +++ b/packages/webdriverjs/package.json @@ -49,7 +49,9 @@ "prebuild": "rimraf dist", "build": "tsup src/index.ts --dts --format esm,cjs", "test": "mocha --timeout 60000 -r ts-node/register 'test/**.spec.ts'", + "test:export": "npm run test:esm && npm run test:commonjs", "test:esm": "node test/esmTest.mjs", + "test:commonjs": "node test/commonjsTest.js", "coverage": "nyc npm run test", "prepare": "npm run build" }, diff --git a/packages/webdriverjs/src/index.ts b/packages/webdriverjs/src/index.ts index 8d035816..cc53278a 100644 --- a/packages/webdriverjs/src/index.ts +++ b/packages/webdriverjs/src/index.ts @@ -291,4 +291,10 @@ export default class AxeBuilder { } } +// ensure backwards compatibility with commonJs default export +if (typeof module === 'object') { + module.exports = AxeBuilder; + module.exports.AxeBuilder = AxeBuilder; +} + export { AxeBuilder }; diff --git a/packages/webdriverjs/test/commonjsTest.js b/packages/webdriverjs/test/commonjsTest.js new file mode 100644 index 00000000..bc81e7c7 --- /dev/null +++ b/packages/webdriverjs/test/commonjsTest.js @@ -0,0 +1,11 @@ +// ensure backwards compatibility of commonJs format +const defaultExport = require('../dist/index.js'); +const { AxeBuilder } = require('../dist/index.js'); +const assert = require('assert'); + +assert(typeof defaultExport === 'function', 'default export is not a function'); +assert(typeof AxeBuilder === 'function', 'named export is not a function'); +assert( + defaultExport === AxeBuilder, + 'default and named export are not the same' +); diff --git a/packages/webdriverjs/test/esmTest.mjs b/packages/webdriverjs/test/esmTest.mjs index 0a2ffa4d..eb852e5a 100644 --- a/packages/webdriverjs/test/esmTest.mjs +++ b/packages/webdriverjs/test/esmTest.mjs @@ -1,5 +1,8 @@ +// ensure compatibility of ESM format import defaultExport from '../dist/index.mjs'; +import { AxeBuilder } from '../dist/index.mjs'; import assert from 'assert'; -const exportIsFunction = typeof defaultExport === 'function'; -assert(exportIsFunction, 'export is not a function'); +assert(typeof defaultExport === 'function', 'default export is not a function'); +assert(typeof AxeBuilder === 'function', 'named export is not a function') +assert(defaultExport === AxeBuilder, 'default and named export are not the same'); \ No newline at end of file From 86974edd8520e77c53567806c0ba9d4b451f7ed5 Mon Sep 17 00:00:00 2001 From: Steven Lambert <2433219+straker@users.noreply.github.com> Date: Thu, 16 Nov 2023 16:45:01 -0700 Subject: [PATCH 2/5] fix react building on test --- packages/react/package.json | 2 +- packages/reporter-earl/jest.config.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/react/package.json b/packages/react/package.json index 4dc39c53..7a0d1d87 100644 --- a/packages/react/package.json +++ b/packages/react/package.json @@ -27,7 +27,7 @@ "scripts": { "build": "tsup index.ts --dts --format esm,cjs", "prepare": "npm run build", - "test": "tsc && npm run test:types && jest", + "test": "npm run test:types && jest", "test:export": "npm run test:esm && npm run test:commonjs", "test:esm": "node test/esmTest.mjs", "test:commonjs": "node test/commonjsTest.js", diff --git a/packages/reporter-earl/jest.config.js b/packages/reporter-earl/jest.config.js index 93f303c3..b6950a33 100755 --- a/packages/reporter-earl/jest.config.js +++ b/packages/reporter-earl/jest.config.js @@ -4,7 +4,7 @@ module.exports = { transform: { '\\.(ts|tsx)$': 'ts-jest' }, - testRegex: '/tests/.*\\.(ts|tsx|js)$', + testPathDirs: 'tests', testPathIgnorePatterns: ['/node_modules/', '/dist/', '/tests/utils.ts'], silent: false, coverageThreshold: { From 38918359d0a58499d301285ba31a77abc69a3bb2 Mon Sep 17 00:00:00 2001 From: Steven Lambert <2433219+straker@users.noreply.github.com> Date: Thu, 16 Nov 2023 17:05:30 -0700 Subject: [PATCH 3/5] fix now? --- .github/workflows/tests.yml | 4 ++++ packages/react/package.json | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 44229ea7..5565929f 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -141,6 +141,10 @@ jobs: - run: npm ci - run: npm run build --workspace=packages/react - run: npm run test --workspace=packages/react + # the tests builds the project using tsc and relies on `cache.ts` to be + # built and be it's own file. however we don't want that for the export + # test so we need to rebuild using tsup + - run: npm run build --workspace=packages/react - run: npm run test:export --workspace=packages/react playwright: diff --git a/packages/react/package.json b/packages/react/package.json index 7a0d1d87..4dc39c53 100644 --- a/packages/react/package.json +++ b/packages/react/package.json @@ -27,7 +27,7 @@ "scripts": { "build": "tsup index.ts --dts --format esm,cjs", "prepare": "npm run build", - "test": "npm run test:types && jest", + "test": "tsc && npm run test:types && jest", "test:export": "npm run test:esm && npm run test:commonjs", "test:esm": "node test/esmTest.mjs", "test:commonjs": "node test/commonjsTest.js", From 595a3cfd974bdcc41bbd9a24f6f387bd82b87739 Mon Sep 17 00:00:00 2001 From: Steven Lambert <2433219+straker@users.noreply.github.com> Date: Fri, 17 Nov 2023 08:32:00 -0700 Subject: [PATCH 4/5] revert example update --- .github/workflows/tests.yml | 1 - packages/webdriverjs/example.js | 4 +--- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 5565929f..5505215e 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -139,7 +139,6 @@ jobs: node-version: ${{ matrix.node }} cache: 'npm' - run: npm ci - - run: npm run build --workspace=packages/react - run: npm run test --workspace=packages/react # the tests builds the project using tsc and relies on `cache.ts` to be # built and be it's own file. however we don't want that for the export diff --git a/packages/webdriverjs/example.js b/packages/webdriverjs/example.js index 21ffc50a..a5b3215c 100644 --- a/packages/webdriverjs/example.js +++ b/packages/webdriverjs/example.js @@ -1,9 +1,7 @@ -const { AxeBuilder } = require('./dist/index'); +const { AxeBuilder } = require('@axe-core/webdriverjs'); const { Builder } = require('selenium-webdriver'); const chrome = require('selenium-webdriver/chrome'); -console.log(AxeBuilder); - (async () => { const driver = new Builder() .forBrowser('chrome') From bdb397551cfd8c501bd85dca7bdd6c109b56a7c6 Mon Sep 17 00:00:00 2001 From: Steven Lambert <2433219+straker@users.noreply.github.com> Date: Mon, 20 Nov 2023 13:13:32 -0700 Subject: [PATCH 5/5] support 4.7.3 --- packages/webdriverjs/src/index.ts | 1 + packages/webdriverjs/test/commonjsTest.js | 22 ++++++++++++++++++---- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/packages/webdriverjs/src/index.ts b/packages/webdriverjs/src/index.ts index cc53278a..c1aab37b 100644 --- a/packages/webdriverjs/src/index.ts +++ b/packages/webdriverjs/src/index.ts @@ -294,6 +294,7 @@ export default class AxeBuilder { // ensure backwards compatibility with commonJs default export if (typeof module === 'object') { module.exports = AxeBuilder; + module.exports.default = AxeBuilder; module.exports.AxeBuilder = AxeBuilder; } diff --git a/packages/webdriverjs/test/commonjsTest.js b/packages/webdriverjs/test/commonjsTest.js index bc81e7c7..b80f4fd6 100644 --- a/packages/webdriverjs/test/commonjsTest.js +++ b/packages/webdriverjs/test/commonjsTest.js @@ -1,11 +1,25 @@ // ensure backwards compatibility of commonJs format -const defaultExport = require('../dist/index.js'); +const implicitDefaultExport = require('../dist/index.js'); // support <4.7.3 +const explicitDefaultExport = require('../dist/index.js').default; // support 4.7.3+ const { AxeBuilder } = require('../dist/index.js'); const assert = require('assert'); -assert(typeof defaultExport === 'function', 'default export is not a function'); assert(typeof AxeBuilder === 'function', 'named export is not a function'); + +assert( + typeof implicitDefaultExport === 'function', + 'implicit default export is not a function' +); +assert( + implicitDefaultExport === AxeBuilder, + 'implicit default and named export are not the same' +); + +assert( + typeof explicitDefaultExport === 'function', + 'explicit default export is not a function' +); assert( - defaultExport === AxeBuilder, - 'default and named export are not the same' + explicitDefaultExport === AxeBuilder, + 'explicit default and named export are not the same' );