Openlayers 6 TypeError: URL.createObjectURL is not a function - jestjs

I have a question, after i update the openlayers from 5.3.1 to 6.3.1, when i run test, jest or mocha, both show the error "TypeError: URL.createObjectURL is not a function", what is the reason?
Mocha-Webpack:
TypeError: URL.createObjectURL is not a function
at eval (webpack:///./node_modules/ol/worker/webgl.js?:7:15)
Jest:
FAIL test/map.test.js
● Test suite failed to run
TypeError: URL.createObjectURL is not a function
> 1 | import {Vector as VectorLayer} from "ol/layer.js";
| ^

Related

TypeError: Cannot read properties of undefined (reading 'testTimeout')

The jest 0.29 test case is to test component snapshot. Here is the error:
FAIL src/components/post/piece/Itemdetail.test.js
● Test suite failed to run
TypeError: Cannot read properties of undefined (reading 'testTimeout')
at _callCircusHook (node_modules/jest-circus/build/run.js:237:57)
The error is complaining about a jest -circus module. This is confusing as the error is about a jest module. here is the line of code being complained:
const timeout = hook.timeout || (0, _state.getState)().testTimeout; //<<==run.js:237:57. _state is an import module.
How do I mock testTimeout for the jest-circus module to calm the error?
Here is the line of code causing the error:
global = {_smartContractObj:{wallet:"0x4k5jk43k6j5k4j5"}};
The error disappeared after the change (don't know why):
global._smartContractObj = {wallet:"0x4k5jk43k6j5k4j5"};

Jest Typescript error importing BabylonJS

I'm trying to launch a Jest test that just happens to import BabylonJS
I'm getting the error below.
export * from "./abstractScene.js";
^^^^^^
SyntaxError: Unexpected token 'export'
> 1 | import * as BABYLON from "#babylonjs/core";
| ^
2 |
3 | describe("Babylong tests2", () => {
4 | test("Should work please", () => {
When I created a CodeSandbox to test, it works GRRRR
https://codesandbox.io/s/jovial-cherry-svdug7?file=/test/babylon.test.ts
When I git clone and npm i && npm run test it fails with the above error
https://github.com/jtwigg/babylonjs-jest/
I'm having a lot of trouble getting traction with testing in a React app (failed with Mocha a million circular errors)
Any help would be appreciated.

TypeError: TextEncoder is not a constructor

I was trying to run tests using supertest in nodejs and I got this error message
ReferenceError: TextEncoder is not defined
Then i was advised to locate the file "node_modules/whatwg-url/lib/encoding.js" and add this lines of code at the top
const { TextEncoder, TextDecoder } = require("./utils");
After i did that, i started getting this message
TypeError: TextEncoder is not a constructor
please, i am using node version 17.4.0

Before test runs, fails on CCI pipeline: "TypeError: Cannot read property 'createEvent' of null"

I have tried researching other topics similar to this error message ( such as from here, here, here among others. ):
TypeError: Cannot read property 'createEvent' of null
In our test suit we have a lot of mocked network calls as a single mocking layer, but there is a throw new Error('unexpected URL') handler for missing calls.
Also, I have verified all of my ReactTesting findBy queries are correctly declared with async/await syntax. Sometimes the tests work, othertimes fails.
What is really curious, is the error happens ONLY in Circle CI before any tests run, it appears, based on the error message call stack:
#!/bin/bash -eo pipefail
yarn test:ci
yarn run v1.22.11
$ jest --ci --runInBand
/home/circleci/project/node_modules/react-dom/cjs/react-dom.development.js:3905
var evt = document.createEvent('Event');
^
TypeError: Cannot read property 'createEvent' of null
at Object.invokeGuardedCallbackDev (/home/circleci/project/node_modules/react-dom/cjs/react-dom.development.js:3905:26)
at invokeGuardedCallback (/home/circleci/project/node_modules/react-dom/cjs/react-dom.development.js:4056:31)
at flushPassiveEffectsImpl (/home/circleci/project/node_modules/react-dom/cjs/react-dom.development.js:23543:11)
at unstable_runWithPriority (/home/circleci/project/node_modules/react-dom/node_modules/scheduler/cjs/scheduler.development.js:468:12)
at runWithPriority$1 (/home/circleci/project/node_modules/react-dom/cjs/react-dom.development.js:11276:10)
at flushPassiveEffects (/home/circleci/project/node_modules/react-dom/cjs/react-dom.development.js:23447:14)
at Object.<anonymous>.flushWork (/home/circleci/project/node_modules/react-dom/cjs/react-dom-test-utils.development.js:992:10)
at Immediate.<anonymous> (/home/circleci/project/node_modules/react-dom/cjs/react-dom-test-utils.development.js:1003:11)
at processImmediate (internal/timers.js:464:21)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Exited with code exit status 1
CircleCI received exit code 1
I have not seen this error locally, even when running the same command as my Circle CI command.
Any ideas about this, other than unhandled
Can you try this. async() await and use expect() function and also catch the execption by new Error Object.
it("Should ...", async () => {
await myFn(async () => {
// some operations
expect(await element.length).toBe(10).toThrow(new Error("something went wrong!"))
});
});
Try adding expect(something...) to the tests, like mentioned here.
You should finish your test with some sort of an assertion.

Unable to connect to selenium chrome standalone driver

login --
× "before all" hook: codeceptjs.beforeSuite for "test something" in 6432ms
TypeError: Cannot convert undefined or null to object
-- FAILURES:
login
"before all" hook: codeceptjs.beforeSuite for "test something":
Cannot convert undefined or null to object
at Function.values ()
at SeleniumStandaloneLauncher.onPrepare (node_modules#wdio\selenium-standalone-service\build\launcher.js:80:22)
at async C:\Users\bachans\node_modules\codeceptjs\lib\plugin\wdio.js:218:11
FAIL | 0 passed, 1 failed // 6s
Run with --verbose flag to see complete NodeJS stacktrace
I see an issue with the URL you are using. It should be as shown in the image

Resources