Meteor import directory test files not eagerly loading - javascript

Meteor version 1.7.0.5
Using meteortesting:mocha
I have a very simple meteor react app. I added a test file in imports/startup/simple-schema.tests.js
describe('Todos_item', function () {
console.log('Todo');
});
I was running npm run test-app so it should be logged in console but that file actually doesn't run. But when I added this snippet to my tests/main.js Todo is logged in console. So am I missing something.
My directory tree
package.json
{
"name": "meteor-bootstrap",
"private": true,
"scripts": {
"start": "meteor run",
"test": "meteor test --once --driver-package meteortesting:mocha",
"test-app": "TEST_WATCH=1 meteor test --full-app --driver-package meteortesting:mocha",
"visualize": "meteor --production --extra-packages bundle-visualizer"
},
"dependencies": {
"#babel/runtime": "7.0.0-beta.55",
"meteor-node-stubs": "^0.4.1",
"react": "^16.4.2",
"react-dom": "^16.4.2",
"react-router-dom": "^4.3.1",
"simpl-schema": "^1.5.3"
},
"meteor": {
"mainModule": {
"client": "client/main.js",
"server": "server/main.js"
},
"testModule": "tests/main.js"
},
"engines": {
"node": "8.11.4"
}
}
Any help will be greatly appreciated. Thanks in advance.

New Meteor apps since 1.7 have eager loading turned off by default (which is causing your problem)
The behaviour is controlled by the meteor section in your package.json.
To restore the eager loading behaviour for tests, delete the testModule key-value pair from your package.json. It should look like this:
"meteor": {
"mainModule": {
"client": "client/main.js",
"server": "server/main.js"
}
},
If you want to restore pre-1.7 behaviour for all files, just delete the whole meteor section from package.json
If you don't want to use eager loading, you will need to import all of your test files from the tests/main.js file

Also one thing to add when with #Fred answer importing test files have to use require not import though I am not sure is it due to my node version or not I am using my node version v6.11.1

Related

Firebase Functions + monorepo - Deploying doesn't work + deps not installed locally

Looks like someone has the same problem here: https://github.com/firebase/firebase-functions/issues/1050
Problem
I have moved my project structure to a monorepo with the following structure:
/
|
| - node_modules/
|
| - packages/
| - - app/
| - - - - index.js
| - - - - package.json
| - - functions/
| - - - - src/
| - - - - - - helloWorld.function.js
| - - - - - - index.js
| - - - - package.json
|
| - .firebaserc
| - firebase.json
| - firestore.indexes.json
| - firestore.rules
| - package.json
| - yarn.lock
| - LICENSE.md
As far as I know, all code our functions depends on must be inside the functions directory. But... when I run yarn install, the node_modules of my functions are saved in the root node_modules folder.
Then, if I run firebase deploy from the root of my project, I get the error:
Error: Error occurred while parsing your function triggers.
The default Firebase app does not exist. Make sure you call initializeApp() before using any of the Firebase services.
Note: I haven't made any code change... before configuring the project to the monorepo structure, everything worked fine.
My attempt to solve this problem
I have tried to use nohoist when defining my workspaces inside my root package.json:
{
"private": true,
"name": "#company/project",
"version": "1.0.0",
"description": "Project monorepo",
"repository": "...",
"license": "MIT",
"author": {
"name": "Raul",
"email": "...
},
"scripts": {
"app": "yarn workspace #company/app start",
"documentation": "yarn workspace #company/documentation start",
"server": "yarn workspace #company/server start"
},
"workspaces": {
"packages": ["packages/*"],
"nohoist": ["**/#company/server"] <---- HERE
}
}
-Note: when I run yarn server the functions shell is started correctly.
But... for some reason, after reinstalling everything:
rm -rf node_modules (everywhere)
yarn cache clean
yarn install
The dependencies of the functions packages are installed in the root node_modules!
Any ideas?
This is how my functions node_modules looks like after installing the deps:
node_modules/
.bin/
eslint
eslint-config-prettier
firebase-functions
functions-framework
functions-framework-nodejs
image_size
uuid
qs/
uuid/
And these are the dependencies required (which are installed in the root package.json, which is not the behavior I expect):
"name": "#company/server",
...
"dependencies": {
"#google-cloud/functions-framework": "^3.1.1",
"#google-cloud/translate": "^6.3.1",
"#google-cloud/vision": "^2.4.2",
"#googlemaps/google-maps-services-js": "^3.3.3",
"axios": "^0.27.2",
"camelcase": "^6.3.0",
"dotenv": "^16.0.1",
"expo-server-sdk": "^3.6.0",
"firebase-admin": "^10.3.0",
"firebase-functions": "^3.21.2",
"glob": "^7.2.0",
"image-size": "^1.0.1",
"lodash": "^4.17.21",
"moment": "^2.29.3",
"qs": "^6.10.3",
"sharp": "^0.30.6",
"uuid": "^8.3.2"
},
"devDependencies": {
"eslint": "^8.3.0",
"eslint-config-google": "^0.14.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.25.3",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-promise": "^4.3.1",
"firebase-functions-test": "^0.2.0"
}
UPDATE
Instead of nohoisting in the root, I have placed this segment in the packages/functions/package.json:
workspaces: { nohoist: ["**"] }
and all the deps are installed locally!
But... when I do firebase deploy, same error. If instead of running the command from the root folder I do it from packages/functions/package.json the deployment is successful.
Why? What is happening?
This is my firebase.json file:
{
"functions": {
"predeploy": ["yarn --cwd \"$RESOURCE_DIR\" lint"],
"source": "packages/functions"
},
"firestore": {
"rules": "firestore.rules",
"indexes": "firestore.indexes.json"
}
}
Workaround (Not the correct solution, just a trick):
Instead of using nohoist to installing all the deps locally inside the packages/functions directory, what about excluding it from the yarn workspaces?
For this, update your root's package.json to:
"workspaces": [
"packages/app",
"packages/documentation"
]
(packages/functions is not included as a workspace.)
Test it:
Now, if you run (wherever you want in your project) firebase deploy, everything works fine... the deployment is successful and all our backend deps are installed locally (it is required, since all the cloud functions code must be inside the functions folder).
Also, this error is solved too!
Pros:
You can maintain the monorepository structure and deploy your cloud functions without problems.
Cons:
This is a tricky solution... when you run yarn install from the root of your project, packages/functions/package.json dependencies are not installed (as we have remove it from the workspace in order to install them locally.)
In order to solve this little issue, in your root package.json, write the following:
{
"scripts": {
...,
"postinstall": "cd path/to/your/functions && yarn install", // automatically executed after running `yarn install`
}
}
in my case:
{
"scripts": {
...,
"postinstall": "cd packages/functions && yarn install", // automatically executed after running `yarn install`
}
}

ESLint: Invalid Options when create-next-app

I'm creating a new Next.js application.
When i run yarn create-next-app and i start to write javascript code inside Visual Studio Code, the ESlint extension throw back an error every time i digit.
And, naturally, eslint doesn't work.
The error is:
ESLint: Invalid Options: - Unknown options: env, parserOptions, rules - 'parserOptions' has been removed. Please use the 'overrideConfig.parserOptions' option instead. - 'rules' has been removed. Please use the 'overrideConfig.rules' option instead.. Please see the 'ESLint' output channel for details.
This is the image for an immediate visual recognizing:
Eslint extension error on Visual Studio Code
This is my package.json file (the default package.json given by Next.js):
{
"name": "myApp",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
},
"dependencies": {
"next": "12.0.7",
"react": "17.0.2",
"react-dom": "17.0.2"
},
"devDependencies": {
"eslint": "8.4.1",
"eslint-config-next": "12.0.7"
}
}
Thank you for your help.
Solved on my own by wrapping the content of esling.options into overrideConfig in my settings.json vscode file, like this:
"eslint.options": {
"overrideConfig": {
"env": {
"browser": true,
"es6": true
},
"parserOptions": {
"ecmaVersion": 2019,
"sourceType": "module",
"ecmaFeatures": {
"jsx": true
}
},
"rules": {
"no-debugger": "off"
}
}
},
This may be obvious to most, but I wanted to add one caveat. The above config fix works, but make sure you do it at the user level as well as the workspace level. If the eslint.options json doesn't have the overrideConfig at the user level config it will continue to error. Sorry if this is obvious, but I just spent the last hour trying to understand why I was continuing to get the invalid options error despite adding the above solution until I realized I was making the change in the workspace only. Hopefully this can save someone a headache.
I was not able to find the exact cause of the problem, but I was able to fix the issue by completely reinstalling vscode. Use this guide to do a clean uninstall.

Editing package.js file

i'm having a hard time to understand how to run all of my .js files using package.js files
i have almost 2000.js scripts i need to run them one by one, i'm using a api made by gameflip
in the folder i found package.js, but i don't know how to use it ,
can anyone tell me how to do that ? thank you
here the script :
{
"name": "gfapi",
"version": "0.1.1",
"description": "Gameflip API",
"keywords": "Gameflip",
"homepage": "https://github.com/iJJi/gfapi",
"bugs": "https://github.com/iJJi/gfapi/issues",
"author": {
"name": "Eng-Shien Wu",
"email": "engshien.wu#ijji.com"
},
"license": "MIT",
"private": true,
"files": [
"index.js"
],
"repository": "iJJi/gfapi",
"engines": {
"node": ">=8.5.0"
},
"scripts": {
"bulk_listing": "node src/samples/bulk_listing.js",
"test": "ENVIRONMENT=mocha mocha src/test --recursive",
"docs": "jsdoc -c jsdoc_conf.js -d docs -P package.json index.js; docco -o docs/samples src/samples/*.js src/samples/*.rb"
},
"dependencies": {
"base-64": "^0.1.0",
"bluebird": "^3.5.0",
"bunyan": "^1.8.12",
"file-type": "^8.1.0",
"http-errors": "^1.6.2",
"node-rest-client-promise": "^3.1.1",
"promise-ratelimit": "^0.0.3",
"request": "^2.85.0",
"request-promise": "^4.2.2",
"speakeasy": "^2.0.0"
},
"devDependencies": {
"marked": "^0.3.19",
"docco": "^0.7.0",``
"jsdoc": "^3.5.5"
}
}
What you posted isn't a package.js (I don't even know if it exists), but a package.json. It's generated by NPM, the Node Package Manager. It's a list of all the project's dependencies. I think that what you're looking for are the npm scripts, they are in the script object of package.json.
npm run <script>
# For example :
npm run bulk_listing
npm run test
npm run docs
Each script will run its associated command in this package.json.
npm run bulk_listing
# Will do the same thing as:
node src/samples/bulk_listing.js
More about package.json.
The script I talked about below
If you want to run all the scripts, this should do the job :
const fileNames = ["path/to/fileA", "fileB"]; // I assume you have something to get all the files path. Isn't that npm run bulk_listing ?
fileNames.forEach(async (path, index) => {
// It's pretty much like 'node <path>'
await require(path);
// All the code here is executed AFTER the script has been launched
console.log(`LAUNCHED ${index} | ${path}`)
});

Meteor + LitElement (Polymer 3) issue with importing

I had an issue with importing the LitElement module into a Meteor project:
I'm starting a new test project with Meteor 1.7+ and am using LitElement for a few components.
I installed Meteor like so:
meteor create meteor-lithtml --release 1.7.1-beta.29 --bare
I installed like so:
meteor npm install --save #polymer/lit-element
My node_modules directory looks like so:
My package.json file:
{
"name": "myapp",
"private": true,
"scripts": {
"start": "meteor run"
},
"dependencies": {
"#babel/runtime": "^7.0.0-beta.56",
"#polymer/lit-element": "^0.5.2",
"#vaadin/router": "^1.0.0",
"meteor-node-stubs": "^0.4.1",
"redux": "^4.0.0"
},
"meteor": {
"mainModule": {
"client": "client/index.js",
"server": "server/index.js"
}
}
}
The typical way I see lit-element imported is not working...
Just adding an index.js file and importing the lit-element module generates errors. If I remove the import from the index.js file, the errors go away.
\\ client\index.js
import { LitElement, html } from '#polymer/lit-element';
The very first error:
Uncaught SyntaxError: Unexpected token {
modules.js?hash=182125a3fa97eaa24f6d313584ca593c3aed2103:984
Points to this location:
Expanding node_modules to look into this file:
Why am I getting the unexpected { token?
NOTE: I'm asking this question here just in case a Meteor user stumbles by with the same issue and needs help.
Just in case we have any more Meteor users stop by with an issue like this, here are the references to the explanation & solution:
explanation: https://forums.meteor.com/t/litelement-import-litelement-html/45042/8?u=aadams
solution: https://github.com/aadamsx/meteor-lithtml/pull/1

Require highcharts-browserify to use specific version of highcharts?

I'm working with highcharts-browserify. This is what my package.json file looks like:
{
"main": "index.js",
"scripts": {
"watch-index": "watchify index.js -o ../../static/js/index.js --debug --verbose",
"watch": "npm run watch-index",
"build-index": "browserify index.js | uglifyjs > ../../static/js/index.min.js",
"build": "npm run build-index"
},
"dependencies": {
"highcharts-browserify": "^0.1.5-4.1.7",
"jquery": "^1.11.3",
}
}
However, when I run npm run watch, the compiled file has v4.0.4 of Highcharts in it, not the latest version (v4.1.7).
How can I make sure I've got the latest version?
I need to use the latest version because of this bug in x-axis labels in v4.0.4 of Highcharts: http://jsfiddle.net/5z8rf83y/7/
The highcharts-browserify library currently uses v 4.0.4.
https://github.com/soldair/highcharts-browserify/blob/master/highcharts.js#L2
You could open a ticket to have it updated, or fix it and submit a pull request.
Also, you can by pass using this library, and use browserify-shim which would look like this -
{
"browserify": {
"transform": [
"browserify-shim"
]
},
"browserify-shim": {
"Highcharts": {
"depends": ["HighchartsAdapter:HighchartsAdapter"],
"exports": "Highcharts"
},
"HighchartsAdapter": {"exports":"HighchartsAdapter"}
},
"browser": {
"Highcharts": "./bower_components/highcharts-release/highcharts.src.js",
"HighchartsAdapter": "./bower_components/highcharts-release/adapters/standalone-framework.src.js"
}
}

Categories

Resources