diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index fd026587..6bfed850 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -52,20 +52,22 @@ jobs: if: steps.cache-npm.outputs.cache-hit != 'true' run: npm ci - # Start Bee Factory environment - name: Start Bee Factory environment if: matrix.node-version != '18.x' run: npm run bee -- --verbose --detach - # Start Bee Factory environment for Node 18 - - name: Start Bee Factory environment for Node 18 + - name: Run unit and integration tests for node + if: matrix.node-version != '18.x' + run: npm run test:node -- --detectOpenHandles + + - name: Node 18 specific Bee Factory and tests run if: matrix.node-version == '18.x' env: NODE_OPTIONS: '--no-experimental-fetch' - run: npm run bee -- --verbose --detach + run: | + npm run bee -- --verbose --detach + npm run test:node -- --detectOpenHandles - - name: Run unit and integration tests for node - run: npm run test:node -- --detectOpenHandles - name: Debug workflow if failed if: failure() diff --git a/README.md b/README.md index d88b2024..320c4cd8 100644 --- a/README.md +++ b/README.md @@ -123,7 +123,15 @@ There are also browser tests by Puppeteer, which also provide integrity testing. npm run test:browser ``` The test HTML file which Puppeteer uses is the [test/testpage/testpage.html](test/testpage/testpage.html). -To open and manually test BeeJS with developer console, it is necessary to build the library first with `npm run compile:browser` (running the browser tests `npm run test:browser` also builds the library). +To open and manually test BeeJS with developer console, it is necessary to build the library first with `npm run build:browser` (running the browser tests `npm run test:browser` also builds the library). + +#### Node 18 + +In order to run tests on Node 18 you have to disable the experimental Node's Udici/Fetch implementation. Use the `NODE_OPTIONS` env. variable like this: + +```shell +$ export NODE_OPTIONS='--experimental-vm-modules --no-experimental-fetch' +``` ### Compile code diff --git a/jest.config.mjs b/jest.config.mjs index 664271af..906709bf 100644 --- a/jest.config.mjs +++ b/jest.config.mjs @@ -2,35 +2,6 @@ * For a detailed explanation regarding each configuration property and type check, visit: * https://jestjs.io/docs/en/configuration.html */ -import Glob from 'glob' -import * as Path from 'path' -import { dirname } from 'path' -import { fileURLToPath } from 'url' - -const __dirname = dirname(fileURLToPath(import.meta.url)) - -export async function getBrowserPathMapping () { - const browserSourceFiles = await new Promise((resolve, reject) => { - Glob.glob('src/**/*.browser.ts', (err, browserSourceCodes) => { - if (err) reject(err) - browserSourceCodes = browserSourceCodes.map(match => Path.resolve(__dirname, match)) - const codePathMapping = {} - browserSourceCodes.map(browserFullPath => { - const filePathArray = browserFullPath.split('.') - filePathArray.pop() - filePathArray.pop() //remove 'browser.ts' from '**/*.browser.ts' - const nodeFullPath = filePathArray.join('.') - const aliasNodeReference = `/${nodeFullPath.split('/').pop()}$` //keep the last bit of node file referencing e.g. '/file-source$' - - codePathMapping[aliasNodeReference] = browserFullPath - }) - - resolve(codePathMapping) - }) - }) - - return browserSourceFiles -} export default async () => { return { @@ -68,7 +39,6 @@ export default async () => { { displayName: 'dom:integration', testRegex: 'test/integration/.*\\.browser\\.spec\\.ts', - moduleNameMapper: await getBrowserPathMapping(), preset: 'jest-puppeteer', extensionsToTreatAsEsm: ['.ts'], transform: { diff --git a/package.json b/package.json index 629ec753..4d7cbac5 100644 --- a/package.json +++ b/package.json @@ -50,13 +50,14 @@ "build:node": "tsc && babel --no-babelrc --plugins \"babel-plugin-add-import-extension\" --out-dir dist/src/ dist/src/", "build:types": "tsc --emitDeclarationOnly --declaration --outDir dist/types", "build:browser": "esbuild src/index.ts --minify --bundle --format=esm --sourcemap --platform=browser --outfile=dist/index.browser.js", + "build:browser:nonminify": "esbuild src/index.ts --bundle --format=esm --sourcemap --platform=browser --outfile=dist/index.browser.js", "mock-ci": "npm run lint:check && npm run check:types && npm run test", - "test": "npm run build:browser && cross-env JEST_PUPPETEER_CONFIG=jest-puppeteer.config.cjs NODE_OPTIONS='--experimental-vm-modules --no-experimental-fetch' jest --no-cache --verbose --selectProjects=node:unit node:integration dom:integration", - "test:integration:browser": "npm run build:browser && cross-env JEST_PUPPETEER_CONFIG=jest-puppeteer.config.cjs NODE_OPTIONS='--experimental-vm-modules --no-experimental-fetch' jest --no-cache --verbose --selectProjects=dom:integration", - "test:integration:node": "cross-env NODE_OPTIONS='--experimental-vm-modules --no-experimental-fetch' jest --no-cache --verbose --selectProjects=node:integration", - "test:integration": "npm run build:browser && cross-env JEST_PUPPETEER_CONFIG=jest-puppeteer.config.cjs NODE_OPTIONS='--experimental-vm-modules --no-experimental-fetch' jest --no-cache --verbose --selectProjects=node:integration dom:integration", - "test:unit": "cross-env NODE_OPTIONS='--experimental-vm-modules --no-experimental-fetch' jest --no-cache --verbose --selectProjects=node:unit", - "test:node": "cross-env NODE_OPTIONS='--experimental-vm-modules --no-experimental-fetch' jest --no-cache --verbose --selectProjects=node:unit node:integration", + "test": "npm run build:browser:nonminify && cross-env JEST_PUPPETEER_CONFIG=jest-puppeteer.config.cjs NODE_OPTIONS='--experimental-vm-modules' jest --no-cache --verbose --selectProjects=node:unit node:integration dom:integration", + "test:integration:browser": "npm run build:browser:nonminify && cross-env JEST_PUPPETEER_CONFIG=jest-puppeteer.config.cjs NODE_OPTIONS='--experimental-vm-modules' jest --no-cache --verbose --selectProjects=dom:integration", + "test:integration:node": "cross-env NODE_OPTIONS='--experimental-vm-modules' jest --no-cache --verbose --selectProjects=node:integration", + "test:integration": "npm run build:browser:nonminify && cross-env JEST_PUPPETEER_CONFIG=jest-puppeteer.config.cjs NODE_OPTIONS='--experimental-vm-modules' jest --no-cache --verbose --selectProjects=node:integration dom:integration", + "test:unit": "cross-env NODE_OPTIONS='--experimental-vm-modules' jest --no-cache --verbose --selectProjects=node:unit", + "test:node": "cross-env NODE_OPTIONS='--experimental-vm-modules' jest --no-cache --verbose --selectProjects=node:unit node:integration", "test:browser": "npm run test:integration:browser", "check:types": "tsc --project tsconfig.test.json", "lint": "eslint --fix \"src/**/*.ts\" \"test/**/*.ts\" && prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",