globalTeardown works locally but fails on Kubernetes workload - jestjs

I'm trying to run a simple jest setup on kubernetes. Until now it works fine on my local workstation (WLS2 on WIN10).
PROBLEM: When I add a globalTeardown to my package.json, the function fails in my kubernetes workload, but works when executed locally. Both of the runs are invoked by npm run test
The log of the kubernetes workload prints this error:
[...] // Tests are executed as usual
Test Suites: 1 failed, 1 total
Tests: 2 failed, 1 passed, 3 total
Snapshots: 0 total
Time: 6.57s
📦 reporter is created on: /opt/app/public/report.html
node:events:505
throw er; // Unhandled 'error' event
^
Error: spawn /mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe ENOENT
at Process.ChildProcess._handle.onexit (node:internal/child_process:283:19)
at onErrorNT (node:internal/child_process:478:16)
at processTicksAndRejections (node:internal/process/task_queues:83:21)
Emitted 'error' event on ChildProcess instance at:
at Process.ChildProcess._handle.onexit (node:internal/child_process:289:12)
at onErrorNT (node:internal/child_process:478:16)
at processTicksAndRejections (node:internal/process/task_queues:83:21) {
errno: -2,
code: 'ENOENT',
syscall: 'spawn /mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe',
path: '/mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe',
spawnargs: [
'-NoProfile',
'-NonInteractive',
'–ExecutionPolicy',
'Bypass',
'-EncodedCommand',
'UwB0AGEAcgB0ACAAIgAvAG8AcAB0AC8AYQBwAHAALwBwAHUAYgBsAGkAYwAvAHIAZQBwAG8AcgB0AC4AaAB0AG0AbAAiAA=='
]
}
I have no idea how this can be connected to Powershell, as the used image is based in Ubuntu. Could it be an caused by using Rancher Desktop integrated to WSL2?
package.json
{
"name": "endpoint-testing",
"version": "1.0.0",
"description": "Test utility for testing endpoints of backends from a kubernetes cluster",
"main": "index.js",
"type": "module",
"scripts": {
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js --forceExit",
"watch": "node --experimental-vm-modules node_modules/jest/bin/jest.js --watch",
"run": "node --experimental-vm-modules index.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"axios": "^0.27.2",
"dotenv": "^16.0.1",
"express": "^4.18.1",
"express-fileupload": "^1.3.1",
"form-data": "^4.0.0",
"jest": "^28.1.0",
"jest-html-reporter": "^3.5.0",
"jest-html-reporters": "^3.0.7",
"jest-standard-reporter": "^2.0.0",
"supertest": "^6.2.3",
"winston": "^3.7.2"
},
"jest": {
"globalSetup": "./tests/setup.js",
"globalTeardown": "./tests/customTeardown.js",
"reporters": [
"jest-standard-reporter",
[
"jest-html-reporters",
{
"publicPath": "./public",
"filename": "report.html",
"openReport": true,
"inlineSource": true
}
]
]
}
}
./tests/customTeardown.js
export default async function () {
console.log("Done");
};

Update:
I found this not to happen, when using Kind instead of Rancher Desktop. So this seems to be an integration issue of Rancher Desktop.

Related

npm dev and npm run dev not working even after deleting and re-installing node-modules and package-lock.json

It's be a couple of weeks since I've worked on this specific project, and when I went back to it I can't get npm dev, which is what I had been using to run the server to work. I've also tried npm run dev and that doesn't work either. I keep getting an error stating:
> amos#1.0.0 dev
> cross-env NODE_ENV=dev nodemon src/index.js
node:events:371
throw er; // Unhandled 'error' event
^
Error: spawn nodemon ENOENT
at Process.ChildProcess._handle.onexit (node:internal/child_process:282:19)
at onErrorNT (node:internal/child_process:480:16)
at processTicksAndRejections (node:internal/process/task_queues:83:21)
Emitted 'error' event on ChildProcess instance at:
at Process.ChildProcess._handle.onexit (node:internal/child_process:288:12)
at onErrorNT (node:internal/child_process:480:16)
at processTicksAndRejections (node:internal/process/task_queues:83:21) {
errno: -2,
code: 'ENOENT',
syscall: 'spawn nodemon',
path: 'nodemon',
spawnargs: [ 'src/index.js' ]
}
I tried deleting node_modules and package-lock.json and re-installing them a couple of times. I have also tried to force clear the cache. I'm really not sure what else to try, and I would really appreciate any help or advice. Thank you!
package.json
{
"name": "amos",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"dev": "cross-env NODE_ENV=dev nodemon src/index.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"apollo-server-express": "^3.8.2",
"babel-cli": "^6.26.0",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"babel-preset-env": "^1.7.0",
"bcrypt": "^5.0.1",
"body-parser": "^1.20.0",
"braces": "^3.0.2",
"cross-env": "^7.0.3",
"express": "^4.18.1",
"graphql": "^16.5.0",
"graphql-tools": "^8.2.12",
"jsonwebtoken": "^8.5.1",
"mongoose": "^6.3.6"
}
}

WARNING: LoopBack connector "mongodb" is not installed

I m following a tutorial to create a react chat application with Loopback3 API but I m getting following Error when i try to run my application server ,I retried to install npm install loopback-connector-mongodb --save but still getting same issue. Do i need to install mongodb again? :-
WARNING: LoopBack connector "mongodb" is not installed as any of the following modules:
./connectors/mongodb
loopback-connector-mongodb
To fix, run:
npm install loopback-connector-mongodb --save
C:\Users\welcome\Desktop\ReactJS\chatServer\node_modules\loopback\lib\application.js:280
throw err;
^
Error: Cannot create data source "db":
WARNING: LoopBack connector "mongodb" is not installed as any of the following modules:
./connectors/mongodb
loopback-connector-mongodb
To fix, run:
npm install loopback-connector-mongodb --save
at DataSource.setup (C:\Users\welcome\Desktop\ReactJS\chatServer\node_modules\loopback-datasource-juggler\lib\datasource.js:457:26)
at new DataSource (C:\Users\welcome\Desktop\ReactJS\chatServer\node_modules\loopback-datasource-juggler\lib\datasource.js:138:8)
at Registry.createDataSource (C:\Users\welcome\Desktop\ReactJS\chatServer\node_modules\loopback\lib\registry.js:364:14)
at dataSourcesFromConfig (C:\Users\welcome\Desktop\ReactJS\chatServer\node_modules\loopback\lib\application.js:570:19)
at Function.app.dataSource (C:\Users\welcome\Desktop\ReactJS\chatServer\node_modules\loopback\lib\application.js:269:16)
at C:\Users\welcome\Desktop\ReactJS\chatServer\node_modules\loopback-boot\lib\executor.js:191:9
at C:\Users\welcome\Desktop\ReactJS\chatServer\node_modules\loopback-boot\lib\executor.js:282:5
at Array.forEach (<anonymous>)
at forEachKeyedObject (C:\Users\welcome\Desktop\ReactJS\chatServer\node_modules\loopback-boot\lib\executor.js:281:20)
at setupDataSources (C:\Users\welcome\Desktop\ReactJS\chatServer\node_modules\loopback-boot\lib\executor.js:181:3)
at execute (C:\Users\welcome\Desktop\ReactJS\chatServer\node_modules\loopback-boot\lib\executor.js:39:3)
at bootLoopBackApp (C:\Users\welcome\Desktop\ReactJS\chatServer\node_modules\loopback-boot\index.js:154:3)
at Object.<anonymous> (C:\Users\welcome\Desktop\ReactJS\chatServer\server\server.js:28:1)
at Module._compile (internal/modules/cjs/loader.js:1085:14)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
at Module.load (internal/modules/cjs/loader.js:950:32)
Emitted 'error' event on DataSource instance at:
at DataSource.setup (C:\Users\welcome\Desktop\ReactJS\chatServer\node_modules\loopback-datasource-juggler\lib\datasource.js:457:12)
at new DataSource (C:\Users\welcome\Desktop\ReactJS\chatServer\node_modules\loopback-datasource-juggler\lib\datasource.js:138:8)
[... lines matching original stack trace ...]
at Module.load (internal/modules/cjs/loader.js:950:32)
But Here is my package.json:-
{
"name": "chatServer",
"version": "1.0.0",
"main": "server/server.js",
"engines": {
"node": ">=6"
},
"scripts": {
"lint": "eslint .",
"start": "node .",
"posttest": "npm run lint"
},
"dependencies": {
"compression": "^1.0.3",
"cors": "^2.5.2",
"helmet": "^3.10.0",
"loopback": "^3.22.0",
"loopback-boot": "^2.6.5",
"loopback-component-explorer": "^6.2.0",
"loopback-connector-mongodb": "^6.0.1",
"serve-favicon": "^2.0.1",
"strong-error-handler": "^4.0.0",
"ws": "^7.5.3"
},
"devDependencies": {
"eslint": "^3.17.1",
"eslint-config-loopback": "^8.0.0"
},
"repository": {
"type": "",
"url": ""
},
"license": "UNLICENSED",
"description": "chatServer"
}
How do I deal with this?

when transpiling mocha test using ts-node i cannot find module 'tsconfig/register'

I have run both npm i ts-node and npm i ts-node --save-dev with no changes. ts-node works fine when I run it from the command line, but for some reason I cannot run mocha tests through test explorer. I get the error below:
error:
{ Error: Cannot find module 'tsconfig/register'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:581:15)
at Function.Module._load (internal/modules/cjs/loader.js:507:25)
at Module.require (internal/modules/cjs/loader.js:637:17)
at require (internal/modules/cjs/helpers.js:22:18)
at exports.requireOrImport (c:\Users\king\.vscode\extensions\hbenl.vscode-mocha-test-adapter-2.8.1\node_modules\mocha\lib\esm-utils.js:20:12)
at c:\Users\king\.vscode\extensions\hbenl.vscode-mocha-test-adapter-2.8.1\out\worker\bundle.js:5663:41
at Generator.next (<anonymous>)
at fulfilled (c:\Users\king\.vscode\extensions\hbenl.vscode-mocha-test-adapter-2.8.1\out\worker\bundle.js:90:58) code: 'MODULE_NOT_FOUND' }
package.json
{
"name": "appts",
"version": "1.1.1",
"description": "",
"main": "handler.js",
"scripts": {
"build:launchlocal": "cd serverless-site/ && npm start"
},
"mocha": {
"require": ["tsconfig/register"]
},
"author": "",
"license": "ISC",
"devDependencies": {
"#types/aws-lambda": "^8.10.40",
"#types/expect": "^24.3.0",
"#types/mocha": "^8.0.3",
"#types/validator": "^13.1.0",
"serverless-offline": "^5.12.1",
"serverless-plugin-typescript": "^1.1.9",
"serverless-s3-sync": "^1.10.4",
"serverless-step-functions": "^2.17.1",
"ts-mocha": "^7.0.0",
"ts-node": "^8.10.2"
},
"dependencies": {
.....omitted....
}
}
Turns out none of the package.json config options were working for me. I wound up implementing a .mocharc.json on the same level as my package.json which worked perfectly.
Example from this github repo (with more examples) copied here for posterity.
{
"extension": ["ts"],
"spec": "src/**/*.spec.ts",
"require": "ts-node/register"
}

Tensorflow JS & Electron Forge - Error importing tensorflow js after npm run make

I have built this little app with tensorflow js. I can run it perfectly on Windows 10 using the npm start, however after I successfully run npm run make it becomes impossible to import tensorflow. I get the following error:
Uncaught Error: The specified module could not be found. \\?\C:\Users\teste\AppData\Local\my-app\app-1.0.0\resources\app.asar.unpacked\node_modules\#tensorflow\tfjs-node\lib\napi-v5\tfjs_binding.node
at process.func (electron/js2c/asar.js:140)
at process.func [as dlopen] (electron/js2c/asar.js:140)
at Object.Module._extensions..node (internal/modules/cjs/loader.js:1016)
at Object.func (electron/js2c/asar.js:140)
at Object.func [as .node] (electron/js2c/asar.js:149)
at Module.load (internal/modules/cjs/loader.js:816)
at Module._load (internal/modules/cjs/loader.js:728)
at Module._load (electron/js2c/asar.js:717)
at Function.Module._load (electron/js2c/asar.js:717)
at Module.require (internal/modules/cjs/loader.js:853)
When I go down to C:\Users\teste\AppData\Local\my-app\app-1.0.0\resources\app.asar.unpacked\node_modules\#tensorflow\tfjs-node\lib\napi-v5\tfjs_binding.node the file is there and perfectly accessible
I'm running windows 10, node v12.13.0, electron 8.2.1 with electron forge
My package.json is:
{
"name": "my-app",
"productName": "my-app",
"version": "1.0.0",
"description": "My Electron application description",
"main": "src/index.js",
"scripts": {
"start": "electron-forge start",
"package": "electron-forge package",
"make": "electron-forge make",
"publish": "electron-forge publish",
"lint": "echo \"No linting configured\"",
"install": "electron-rebuild --pre-gyp-fix"
},
"keywords": [],
"author": "guzeda",
"license": "MIT",
"config": {
"forge": "./forge.config.js"
},
"dependencies": {
"#electron-forge/plugin-auto-unpack-natives": "^6.0.0-beta.50",
"#tensorflow/tfjs": "^1.5.1",
"#tensorflow/tfjs-node": "^1.5.1",
"electron-reload": "^1.5.0",
"electron-squirrel-startup": "^1.0.0",
"face-api.js": "^0.22.2",
"jquery": "^3.4.1",
"material-design-lite": "^1.3.0"
},
"devDependencies": {
"#electron-forge/cli": "^6.0.0-beta.50",
"#electron-forge/maker-deb": "^6.0.0-beta.50",
"#electron-forge/maker-rpm": "^6.0.0-beta.50",
"#electron-forge/maker-squirrel": "^6.0.0-beta.50",
"#electron-forge/maker-zip": "^6.0.0-beta.50",
"electron": "8.2.1",
"electron-rebuild": "^1.10.1"
}
}
My forge.config is:
module.exports = {
makers: [
{
name: '#electron-forge/maker-squirrel',
config: {
name: "my-app"
}
}
],
plugins: [
['#electron-forge/plugin-auto-unpack-natives']
],
packagerConfig:{asar:true}
}
I appreciate any help
I just found out the solution. That happened because the dll needs to be in the same folder as the buddings. The error message was very misleading.
At the end it was necessary to write some post install script to copy the correct dll to the folder and it worked perfectly
Just double checked your code - was to do with your folder structure.
Why are you using tensorflow.js instead of python et al, if i may ask?

gulp 4 spawn fails when building KSS

I'm trying to resurrect my automated KSS build process which died a year ago after I upgraded Node for another project.
KSS works fine when I run it directly via the command line ($ ./node_modules/kss/bin/kss --config kss-config.json)
But when I run it via gulp using node spawn I get the following error:
user#computer /c/users/user/Documents/projects/kss
$ gulp
[12:04:42] Using gulpfile C:\users\user\Documents\projects\kss\gulpfile.js
[12:04:42] Starting 'default'...
[12:04:42] Starting 'compileKss'...
[12:04:42] 'compileKss' errored after 3.21 ms
[12:04:42] Error: spawn ./node_modules/kss/bin/kss ENOENT
at Process.ChildProcess._handle.onexit (internal/child_process.js:264:19)
at onErrorNT (internal/child_process.js:456:16)
at processTicksAndRejections (internal/process/task_queues.js:80:21)
[12:04:42] 'default' errored after 6.78 ms
My gulp file looks like this:
'use strict'
/**
* Some useful links to help with understanding this file:
* * https://www.webstoemp.com/blog/switching-to-gulp4/
*/
const { series } = require('gulp')
const childProcess = require('child_process')
/**
* a Gulp task for compiling Sass files to CSS and creating source maps
*/
const compileKss = (gulpCallBack) => {
const kss = childProcess.spawn(
'./node_modules/kss/bin/kss',
[
'--config',
'./kss-config.json'
]
)
kss.on('exit', (code) => {
const errorMsg = (code === 0) ? null : 'ERROR: kss-node process exited with code: ' + code
gulpCallBack(errorMsg)
})
return kss
}
exports.default = series(compileKss)
and my kss config file looks like this:
{
"title": "KSS style guide",
"source": [
"./style-guide/css/"
],
"destination": "./style-guide/",
"homepage": "src/homepage.md",
"builder": "node_modules/michelangelo/kss_styleguide/custom-template",
"css": [],
"js": []
}
and my package.json looks like this:
{
"name": "KSS style-guide",
"description": "KSS style-guide",
"author": {},
"browserslist": [
"last 2 version",
"> 1%"
],
"bugs": {},
"contributors": [],
"dependencies": {},
"devDependencies": {
"acorn": "^7.1.0",
"browser-sync": "^2.26.7",
"compass-importer": "^0.4.1",
"concat": "^1.0.3",
"del": "^5.1.0",
"fancy-log": "^1.3.3",
"gulp": "^4.0.2",
"gulp-concat": "^2.6.1",
"gulp-plumber": "^1.2.1",
"gulp-sass": "^4.0.2",
"gulp-sass-lint": "^1.4.0",
"gulp-sourcemaps": "^2.6.5",
"gulp-terser": "^1.2.0",
"gulp-uglify": "^3.0.2",
"kss": "^3.0.0-beta.25",
"michelangelo": "^0.8.0",
"standard": "^14.3.1",
"terser": "^4.3.9"
},
"engines": {"node": ">=12"},
"engineStrict": true,
"repository": {},
"scripts": {},
"version": "0.0.1"
}
FYI: My system is using
Windows: 10 (10.0.16299)
Git Bash (mintty 3.0.6) (GNU bash, version 4.4.23(1)-release (x86_64-pc-msys))
Node: 12.13.0
Gulp: 4.0.2
kss-node: 3.0.0-beta.25

Resources