Skip to content

Commit

Permalink
ci: no fetch only for node18 and nonminified browser code for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AuHau committed Oct 3, 2022
1 parent 68b31f7 commit 9ab9406
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 43 deletions.
14 changes: 8 additions & 6 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
30 changes: 0 additions & 30 deletions jest.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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: {
Expand Down
13 changes: 7 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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\"",
Expand Down

0 comments on commit 9ab9406

Please sign in to comment.