karma + gulp + jasmine + commonjs/browserify - karma-runner

I'm trying to get my karma jasmine unit testing back up running after introducing a bunch of commonJS (at least I guess that's what it's called) and starting to use package.json and upgrading all packages and get errors everywhere.
Running gulp test, I get
[04:01:55] Using gulpfile ~/workspace/thisapp/Gulpfile.js
[04:01:55] Starting 'test'...
[04:01:55] Starting Karma server...
/home/leo/workspace/thisapp/node_modules/karma/node_modules/di/lib/injector.js:9
throw error('No provider for "' + name + '"!');
^
Error: No provider for "framework:browserify"! (Resolving: framework:browserify)
at error (/home/leo/workspace/thisapp/node_modules/karma/node_modules/di/lib/injector.js:22:68)
at Object.parent.get (/home/leo/workspace/thisapp/node_modules/karma/node_modules/di/lib/injector.js:9:13)
at get (/home/leo/workspace/thisapp/node_modules/karma/node_modules/di/lib/injector.js:54:19)
at /home/leo/workspace/thisapp/node_modules/karma/lib/server.js:29:14
at Array.forEach (native)
at start (/home/leo/workspace/thisapp/node_modules/karma/lib/server.js:28:21)
at invoke (/home/leo/workspace/thisapp/node_modules/karma/node_modules/di/lib/injector.js:75:15)
at Object.exports.start (/home/leo/workspace/thisapp/node_modules/karma/lib/server.js:307:12)
at Object.<anonymous> (/home/leo/workspace/thisapp/node_modules/gulp-karma/lib/background.js:3:8)
at Module._compile (module.js:456:26)
with
frameworks : [ 'jasmine', 'browserify' ],
in my karma config and this (horribly) set of dependencies:
"browserify": "^10.2.3",
"browserify-shim": "^3.8.9",
"esmangle": "^1.0.1",
"gulp": "^3.9.0",
"gulp-browserify": "^0.5.1",
"gulp-cordova": "^0.1.2",
"gulp-if": "^1.2.5",
"gulp-jshint": "^1.11.0",
"gulp-karma": "0.0.4",
"gulp-replace": "^0.5.3",
"gulp-shell": "^0.4.2",
"gulp-sourcemaps": "^1.5.2",
"gulp-uglify": "^1.2.0",
"gulp-util": "^3.0.5",
"jasmine-core": "^2.3.4",
"karma": "^0.12.37",
"karma-browserify": "^4.2.1",
"karma-chrome-launcher": "^0.2.0",
"karma-commonjs": "0.0.13",
"karma-jasmine": "^0.3.6",
"karma-jasmine-html-reporter": "*",
"karma-phantomjs-launcher": "^0.2.0",
"phantomjs": "^1.9.17",
"vinyl-buffer": "^1.0.0",
"vinyl-source-stream": "^1.1.0"
Now my assumption would be that if karma-jasmine works, which it does (browserify was the latest addition, as the tests need some requires and karma-commonjs results in the same issues as karma-browserify), then karma-browserify should work equally.
But, for a very similar error of karma-jasmine not being found I had switched from karma to gulp-karma, as there I found the error and it was marked as fixed, which at least for karma-jasmine it is.
In the end I need karma with require and gulp would be nice to have but I'm lost.

You need to add it also to plugins of your karma config:
plugins : [
'karma-junit-reporter',
'karma-chrome-launcher',
'karma-firefox-launcher',
....
'karma-commonjs',
'karma-browserify'
],

Related

Installing React Native Firebase fails at compiling RingBuffer.swift

I am attempting to implement RNFB to my react-native project. for iOS the pods install just fine. However, when I run npm run iOS I get the following error and crash report:
❌ /Users/[Redacted]/Documents/GitHub/[Redacted]/ios/Pods/FirebaseCoreInternal/FirebaseCore/Internal/Sources/HeartbeatLogging/RingBuffer.swift:19:35: reference to generic type 'Array' requires arguments in <...>
case outOfBoundsPush(pushIndex: Array.Index, endIndex: Array.Index)
I was able to find this article that was very recent and it appears to be what I'm looking for but I have absolutely no idea what it says... google translate helps a little bit but I do not know enough to be able to infer a solution.
honestly I do not really even need anything related to heartbeat from firebase. I just need to use the Firebase Analytics and Google Analytics capabilities. But this package came with it and I don't see a way to tell it not to compile.
Regardless, I attempted to downgrade to a lower version of RNFB, I believe I it was version 15.4.0 -> 15.0.0 to see if maybe the new package was the problem but I still get the same errors.
I tried modifying the RingBuffer.swift file... but the file is read-only.
This issue is happening in other FirebaseCore/Internal files...
The following build commands failed:
CompileSwiftSources normal x86_64 com.apple.xcode.tools.swift.compiler
CompileSwift normal x86_64 /Users/[Redacted]/Documents/GitHub/[Redacted]/ios/Pods/FirebaseCoreInternal/[Redacted]/Internal/Sources/HeartbeatLogging/HeartbeatController.swift
CompileSwift normal x86_64 /Users/[Redacted]/Documents/GitHub/[Redacted]/ios/Pods/FirebaseCoreInternal/FirebaseCore/Internal/Sources/HeartbeatLogging/HeartbeatsBundle.swift
CompileSwift normal x86_64 /Users/[Redacted]/Documents/GitHub/[Redacted]/ios/Pods/FirebaseCoreInternal/FirebaseCore/Internal/Sources/HeartbeatLogging/HeartbeatsPayload.swift
CompileSwift normal x86_64 /Users/[Redacted]/Documents/GitHub/[Redacted]/ios/Pods/FirebaseCoreInternal/FirebaseCore/Internal/Sources/HeartbeatLogging/RingBuffer.swift
here is my package.json file
"main": "index.js",
"scripts": {
"android": "react-native run-android",
"ios": "react-native run-ios",
"web": "expo start --web",
"start": "react-native start",
"test": "jest",
"debug-build-android": "react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res",
"build-android": "./android/gradlew ./android/assembleRelease"
},
"dependencies": {
"#react-native-async-storage/async-storage": "^1.13.4",
"#react-native-community/masked-view": "0.1.10",
"#react-native-community/netinfo": "^5.9.9",
"#react-native-firebase/app": "^15.0.0",
"#react-navigation/bottom-tabs": "^5.11.2",
"#react-navigation/drawer": "^5.11.4",
"#react-navigation/native": "^5.8.10",
"#react-navigation/stack": "^5.12.8",
"axios": "^0.21.1",
"expo": "~40.0.0",
"expo-app-loading": "1.0.3",
"expo-asset": "~8.2.1",
"expo-blur": "~8.2.2",
"expo-file-system": "~9.3.0",
"expo-gl": "^9.2.0",
"expo-keep-awake": "~8.4.0",
"expo-screen-orientation": "^3.3.0",
"expo-splash-screen": "~0.8.1",
"expo-three": "^5.5.1",
"expo-updates": "~0.4.0",
"expo-web-browser": "~8.6.0",
"immutability-helper": "^3.1.1",
"lodash.throttle": "^4.1.1",
"react": "16.13.1",
"react-dom": "16.13.1",
"react-native": "~0.63.4",
"react-native-background-downloader": "^2.3.4",
"react-native-base64": "^0.2.1",
"react-native-elements": "3.4.1",
"react-native-fast-image": "^8.3.4",
"react-native-gesture-handler": "~1.8.0",
"react-native-maps": "^0.27.1",
"react-native-reanimated": "~1.13.0",
"react-native-render-html": "^5.0.1",
"react-native-safe-area-context": "^3.1.9",
"react-native-screens": "~2.15.0",
"react-native-toast-message": "1.4.9",
"react-native-unimodules": "~0.12.0",
"react-native-video": "^5.2.0",
"react-native-view-pdf": "^0.13.2",
"react-native-webview": "11.0.0",
"react-native-zip-archive": "^6.0.2",
"react-navigation-header-buttons": "^7.0.1",
"react-redux": "^7.2.2",
"react-three-fiber": "^5.3.21",
"realm": "^10.4.0",
"redux": "^4.0.5",
"redux-devtools-extension": "^2.13.9",
"redux-persist": "^6.0.0",
"redux-thunk": "^2.3.0",
"three": "0.123.0"
},
"devDependencies": {
"#babel/core": "~7.9.0",
"#testing-library/react-native": "^7.2.0",
"#types/jest": "^26.0.19",
"#types/lodash.throttle": "^4.1.6",
"#types/react": "^17.0.0",
"#types/react-native": "^0.63.40",
"#types/react-native-background-downloader": "^2.3.3",
"#types/react-native-base64": "^0.2.0",
"#types/react-native-video": "^5.0.10",
"#types/react-redux": "^7.1.14",
"#types/react-test-renderer": "^17.0.0",
"#types/redux-mock-store": "^1.0.3",
"#types/three": "^0.125.3",
"babel-jest": "^25.2.6",
"jest": "~25.2.6",
"jest-expo": "^42.1.0",
"react-test-renderer": "~16.13.1",
"redux-mock-store": "^1.5.4",
"ts-node": "^10.2.1",
"typescript": "^4.1.3"
},
"jest": {
"preset": "jest-expo"
},
"private": true,
"version": "1.0.1"
}
here is my pod file
$RNFirebaseAsStaticFramework = true #firebase requires static frameworkds
require_relative '../node_modules/react-native/scripts/react_native_pods'
require_relative '../node_modules/react-native-unimodules/cocoapods.rb'
require_relative '../node_modules/#react-native-community/cli-platform-ios/native_modules'
platform :ios, '11.0'
target '[Redacted]' do
use_unimodules!
config = use_native_modules!
use_react_native!(:path => config["reactNativePath"])
# react native firebase requires frameworks...
use_frameworks!
# Enables Flipper.
#
# Note that if you have use_frameworks! enabled, Flipper will not work and
# you should disable these next few lines.
# use_flipper!({ 'Flipper-Folly' => '2.5.3', 'Flipper' => '0.87.0', 'Flipper-RSocket' => '1.3.1' })
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '9.0'
config.build_settings['SWIFT_VERSION'] = '5.0'
end
end
flipper_post_install(installer)
end
end
Xcode Version : Version 13.4.1 (13F100)
some lines have been removed for anonymity.
I was able to fix this compilation error by overwriting the specified pod dependency .swift file with modifications to the following code block
//dependency errors at this point in the file
case outOfBoundsPush(pushIndex: Array.Index, endIndex: Array.Index)
//adding a type definition for the array fixes compilation error
case outOfBoundsPush(pushIndex: Array<Any>.Index, endIndex: Array<Any>.Index)
now if only I knew where to report the pod file discrepancy. Or if anyone would like to tell me why the pod file is packaged improperly for my compiler to understand?
Firebase's minimum supported Swift Version is 5.3 - so the override in the Podfile's post_install script may be the issue. Try deleting or updating config.build_settings['SWIFT_VERSION'] = '5.0'

Runtime error when using `mui-x-date-pickers` and `mui-x-data-grid`

I'm upgrading to MUI5. TS compiling passed but I got tons of console errors: Module not found: Can't resolve '#mui/material/unstable_composeClasses' and ./node_modules/#mui/lab/node_modules/#mui/x-date-pickers/CalendarPicker/calendarPickerClasses.js Module not found: Can't resolve '#mui/material/generateUtilityClass' in ...
I have these in my package.json file
"#mui/icons-material": "^5.8.4",
"#mui/lab": "^5.0.0-alpha.86",
"#mui/material": "^5.8.4",
"#mui/styles": "^5.8.4",
"#mui/utils": "^5.8.4",
"#mui/x-data-grid": "^5.12.2",
"#mui/x-date-pickers": "^5.0.0-alpha.6",
I don't know if this matters, my tsconfig.json has
"module": "esnext",
"target": "es6",
"lib": [
"es2020",
"dom"
],
Any help is appreciated!
This is a similar issue https://github.com/mui/material-ui/issues/30907
I finally resolved this by removing the config from webpack.

How to fix Error cannot find module 'core-js/es6'

I have been getting an error regardless of what I do. In fact I am building an app with mongoDB as a server using mongoose and babel-watch, but every time I run babel-watch I get this error:
Error cannot find module 'core-js/es6'
I have installed and reinstalled core.js using npm install core.js, however nothing changes. Please help.
These are the dependencies I have installed on my project:
"dependencies": {
"body-parser": "^1.19.0",
"core-js": "^2.6",
"cuid": "^2.1.6",
"express": "^4.17.1",
"limax": "^1.7.0",
"mongoose": "^5.6.9",
"node-gyp": "^5.0.3"
},
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-core": "^6.26.3",
"babel-loader": "^8.0.6",
"babel-polyfill": "^6.26.0",
"babel-preset-env": "^1.7.0",
"babel-preset-es2015": "^6.24.1",
"babel-preset-stage-0": "^6.24.1",
"babel-watch": "^7.0.0",
"nodemon": "^1.19.1"
}
}
Code error seen from terminal after running npm start
For core.js v3.9 import in App.tsx the next line: import "core-js/es";
Given that you are using core-js v2.6.9, your path should be core-js/library/es6 as the example shows you in the documentation here.

Error: Couldn't find preset "latest" relative to directory "/app"

Receiving an error within my Deis app; with the introduction of Helmet to the frontend middleware. The app is initially based on React Boilerplate and most of the suggestions I've run by, I've already implemented/explored within the source and am still producing this "phantom" error.
This only occurs on the Deis app instance; when reproducing the steps locally, there's zero issues with it completing the (production) build process.
Sure, I could remove helmet from the middleware, but, I'd rather not...
Error Output:
> pkg-name#0.0.1 start /app
> npm run start:production
> pkg-name#0.0.1 start:production /app
> npm run build && npm run start:prod
> pkg-name#0.0.1 build /app
> cross-env NODE_ENV=production webpack --config internals/webpack/webpack.prod.babel.js --color -p --progress
/app/node_modules/babel-register/node_modules/babel-core/lib/transformation/file/options/option-manager.js:328
throw e;
^
2017-10-27T15:50:48+00:00 deis-app-name[]:
Error: Couldn't find preset "latest" relative to directory "/app"
at /app/node_modules/babel-register/node_modules/babel-core/lib/transformation/file/options/option-manager.js:293:19
at Array.map (<anonymous>)
at OptionManager.resolvePresets (/app/node_modules/babel-register/node_modules/babel-core/lib/transformation/file/options/option-manager.js:275:20)
at OptionManager.mergePresets (/app/node_modules/babel-register/node_modules/babel-core/lib/transformation/file/options/option-manager.js:264:10)
at OptionManager.mergeOptions (/app/node_modules/babel-register/node_modules/babel-core/lib/transformation/file/options/option-manager.js:249:14)
at OptionManager.init (/app/node_modules/babel-register/node_modules/babel-core/lib/transformation/file/options/option-manager.js:368:12)
at compile (/app/node_modules/babel-register/lib/node.js:103:45)
at loader (/app/node_modules/babel-register/lib/node.js:144:14)
at Object.require.extensions.(anonymous function) [as .js] (/app/node_modules/babel-register/lib/node.js:154:7)
at Module.load (module.js:531:32)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! pkg-name#0.0.1 build: `cross-env NODE_ENV=production webpack --config internals/webpack/webpack.prod.babel.js --color -p --progress`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the pkg-name#0.0.1 build script.
Dependency object value/pair:
"dependencies": {
"babel-cli": "6.18.0",
"babel-core": "6.21.0",
"babel-eslint": "7.1.1",
"babel-loader": "6.2.10",
"babel-plugin-dynamic-import-node": "1.0.0",
"babel-plugin-react-intl": "2.2.0",
"babel-plugin-react-transform": "2.0.2",
"babel-plugin-transform-es2015-modules-commonjs": "6.18.0",
"babel-plugin-transform-react-constant-elements": "6.9.1",
"babel-plugin-transform-react-inline-elements": "6.8.0",
"babel-plugin-transform-react-remove-prop-types": "0.2.11",
"babel-preset-latest": "6.16.0",
"babel-preset-react": "6.16.0",
"babel-preset-react-hmre": "1.1.1",
"babel-preset-stage-0": "6.16.0",
"babel-polyfill": "6.20.0",
"basic-auth": "^2.0.0",
"bootstrap": "4.0.0-beta",
"chalk": "^1.1.3",
"cheerio": "0.22.0",
"circular-dependency-plugin": "2.0.0",
"classnames": "^2.2.5",
"compression": "1.6.2",
"cross-env": "3.1.3",
"css-loader": "0.26.1",
"dotenv": "^4.0.0",
"dotenv-safe": "^4.0.4",
"dotenv-webpack": "^1.5.4",
"eslint-import-resolver-webpack": "0.8.0",
"exports-loader": "0.6.3",
"express": "4.14.0",
"express-basic-auth": "^1.1.2",
"file-loader": "0.9.0",
"fontfaceobserver": "^2.0.13",
"helmet": "^3.9.0",
"html-loader": "0.4.4",
"html-webpack-plugin": "2.24.1",
"image-webpack-loader": "2.0.0",
"immutable": "3.8.1",
"imports-loader": "0.6.5",
"intl": "1.2.5",
"invariant": "2.2.2",
"ip": "1.1.4",
"lodash": "4.17.2",
"minimist": "1.2.0",
"moment": "2.18.0",
"ngrok": "2.2.4",
"nsp": "^2.8.1",
"offline-plugin": "4.5.2",
"query-string": "^5.0.1",
"react": "15.4.1",
"react-addons-test-utils": "15.4.1",
"react-dom": "15.4.1",
"react-helmet": "3.2.2",
"react-intl": "2.1.5",
"react-paginate": "^4.4.4",
"react-redux": "4.4.6",
"react-router": "3.0.0",
"react-router-redux": "4.0.6",
"react-router-scroll": "0.4.1",
"react-scroll": "^1.5.5",
"react-widgets": "^4.0.2",
"react-widgets-moment": "^4.0.2",
"reactstrap": "^5.0.0-alpha.3",
"redux": "3.6.0",
"redux-form": "^7.0.4",
"redux-immutable": "3.0.8",
"redux-saga": "0.14.0",
"redux-saga-routines": "^2.0.2",
"reselect": "2.5.4",
"rimraf": "2.5.4",
"sanitize.css": "4.1.0",
"snyk": "^1.45.0",
"style-loader": "0.13.1",
"styled-components": "1.1.2",
"svg-sprite-loader": "^3.4.0",
"url-loader": "0.5.7",
"warning": "3.0.0",
"webpack": "2.2.0-rc.3",
"webpack-dev-middleware": "1.9.0",
"webpack-hot-middleware": "2.15.0",
"whatwg-fetch": "2.0.1"
},
"devDependencies": {
"coveralls": "2.11.15",
"enzyme": "2.6.0",
"eslint": "3.11.1",
"eslint-config-airbnb": "13.0.0",
"eslint-config-airbnb-base": "10.0.1",
"eslint-plugin-import": "2.2.0",
"eslint-plugin-jsx-a11y": "2.2.3",
"eslint-plugin-react": "6.7.1",
"eslint-plugin-redux-saga": "0.1.5",
"eventsource-polyfill": "0.9.6",
"jest-cli": "18.0.0",
"lint-staged": "3.2.1",
"node-plop": "0.5.4",
"node-sass": "^4.5.3",
"null-loader": "0.1.1",
"plop": "1.7.3",
"pre-commit": "1.1.3",
"sass-loader": "^6.0.6",
"shelljs": "^0.7.5",
"sinon": "2.0.0-pre"
}
Runtime configuration:
webpack: 2.2.0-rc.3
babel core: 6.26.0
babel loader: 6.18.0
helmet: 3.9.0
Environment workflow:
Running on a Deis instance (kube & docker)
Environment variables:
NODE_ENV production
NODE_MODULES_CACHE false
NPM_CONFIG_PRODUCTION true
Additional resources:
https://github.com/babel/babel/issues/6558
https://github.com/babel/babel-loader#usage
https://github.com/react-boilerplate/react-boilerplate/pull/1236#issuecomment-305821664
BabelJs over Heroku: Couldn't find preset "env" relative to directory "/app"
https://devcenter.heroku.com/articles/nodejs-support#devdependencies
What I do - in development (on your local machine), I just install all the latest babel deps in a grandparent directory. Node.js will walk up the filesystem looking for its dependencies (node_modules). This way you don't have to install Babel for each project. This technique doesn't even need NODE_PATH or npm link, it just works like this:
$HOME/
projects/
node_modules/ # install all babel deps here
project-a/
project-b/
project-c/
or, even simpler, you can just install babel deps in $HOME/node_modules, and that will work too. Just an idea. This is just the way Node.js works - it walks up the filesystem all the way to $HOME, looking for node_modules/x, if it can't find it in $HOME/node_modules/x, then it fails.
I removed "latest" from presest array and the "prestes" equals ["react","stage-0"]

Babel preset env not targeting correct env

I may be confused as to what babel-preset-env actually does. My assumption is that it would transpile my code for my targeted browsers including any necessary polyfills. This doesn't appear to be the case in my code though...
My code:
import "babel-polyfill"
...
var k = Object.values({ x: 's' });
My babel settings:
"presets": [
[ "env", {
"useBuiltIns": true,
"targets": {
"browsers": ["last 2 versions", "IE 10"]
}
}]
]
The transpiled code still contains Object.values and IE 10 dies quietly (it does transpile - I can see the rest of the code changing - just seems to target wrong).
Package.json (some of these imports are not in use):
"core-js": "^2.5.1",
"opentype.js": "^0.7.2",
"svg.draggable.js": "^2.2.1",
"svg.js": "^2.6.3",
"babel-core": "^6.26.0",
"babel-loader": "^7.1.1",
"babel-plugin-transform-class-properties": "^6.24.1",
"babel-plugin-transform-es2015-destructuring": "^6.23.0",
"babel-plugin-transform-object-rest-spread": "^6.23.0",
"babel-polyfill": "^6.26.0",
"babel-preset-env": "^1.6.0",
"babel-preset-latest": "^6.24.1",
"babel-register": "^6.24.1",
"clean-webpack-plugin": "^0.1.16",
"compression-webpack-plugin": "^1.0.0",
"copy-webpack-plugin": "^4.0.1",
"imports-loader": "^0.7.1",
"mocha": "^3.5.0",
"webpack": "^3.4.1",
"webpack-dev-server": "^2.8.2",
"webpack-merge": "^4.1.0"
babel-preset-env in its default state only handles converting syntax, not polyfilling standard library functionality.
Sounds like you'll want useBuiltins: true in your config. You'll also need to follow the other instructions there by installing core-js and adding an import for babel-polyfill.
Alternatively you can just load babel-polyfill itself and not rely on babel-preset-env at all.