PM2: ignore watch folder glob pattern - javascript

I want pm2 to stop watching folders which have a name like cache or tmp.
I tried a lot of manners in my app.json config file :
{"apps": [{
"name": "BSTAT",
"script": "./server/app.js",
"watch": true,
"ignore_watch": [
"HERE IS WHAT I HAVE TRIED ==>",
"*cache*",
"*/cache",
"cache/",
"*cache/*"
],
}]}
and also saw this question who doesn't seem to have an exemple of that case.
The only way that I find to resolve the problem was to put the exact path like server/my-module/cache
I can not bring myself to think this is not possible...that's why I request your help :)

you need a regex for this, e.g.:
ignore_watch : ['./**/*tests.js', ]
this pattern will ignore all files with name "tests.js" in all project folders

Related

How do I automatically check for '.only' calls accidentally left in Mocha specs?

I occasionally forget to remove .only calls from my Mocha specs before pushing spec changes. Doing so obviously affects test coverage, which requires addressing the failure(s). I'd like to catch these before I push changes, ideally as part of the linting process with ESLint and with minimal effort.
You're looking for the mocha/no-exclusive-tests rule, part of the eslint-plugin-mocha plugin. It fails if it finds any describe.only or it.only. Very useful!
From the docs:
This plugin requires ESLint 4.0.0 or later.
npm install --save-dev eslint-plugin-mocha
Then add a reference to this plugin and selected rules in your eslint config:
{
"plugins": [
"mocha"
],
"rules": {
"mocha/no-exclusive-tests": "error"
}
}
There is also a mocha/no-skipped-tests if you want to prevent it.skip or xit from being committed too. However, I find that .skip is sometimes valid, so I find it best to just prevent .only.
That plugin also has a ton of other useful checks, so be sure to read their docs!
You have a --forbid-only parameter to be passed when executing mocha which will make your tests fail.
You have also the --forbid-pending.
Here from the official doc:
--forbid-only causes test marked with only to fail the suite
--forbid-pending causes pending tests and test marked with skip to fail the suite
My solution was to use a simple bash script with the grep command, added to the package.json scripts section like so:
"scripts": {
"lint:only": "RESULT=\"$(grep -rHn '[.]only\\|[.]skip' spec/ --color=always)\"; if [ -n \"$RESULT\" ]; then printf \"Oops! You left a few things in your specs! \n\n${RESULT}\n\n\"; fi",
"lint": "eslint --ext js src config scripts bin config server; yarn lint:only"
...
}
In a nutshell, this checks the spec/ directory for anything matching .only or .skip and outputs the filename + line if anything offending is found. Color is added for clarity and the script is run as part of linting with ESLint and Yarn.
Another package doing just this is eslint-plugin-no-only-tests.
Alternatively, this can now be done by following built-in ESLint rules, but they will highlight the whole function body of the callback as error as well:
"no-restricted-syntax": [
"error",
{
"selector": "CallExpression[callee.object.type='Identifier'][callee.object.name='it'][callee.property.type='Identifier'][callee.property.name='only']",
"message": "Do not commit it.only. Use it instead."
},
{
"selector": "CallExpression[callee.object.type='Identifier'][callee.object.name='describe'][callee.property.type='Identifier'][callee.property.name='only']",
"message": "Do not commit describe.only. Use describe instead."
}
]
For an exclusion of fdescribe and fit the following can be used:
"no-restricted-globals": [
"error",
{
"name": "fdescribe",
"message": "Do not commit fdescribe. Use describe instead."
},
{
"name": "fit",
"message": "Do not commit fit. Use it instead."
},
]

JSDoc 3 conf.json include not working

I am trying to build a project using JSDoc-3.5.5. I am currently trying to run a test for errors using a small sample of the files for the project. I manually included a few files in my conf.json file but when I run the test the terminal tells me "there are no input files to process." My conf.json file is shown below. If anyone can help me get this to run I would be very appreciative.
{
"tags": {
"allowUnknownTags": true
},
"recurseDepth": 10,
"source": {
"include": [
"/home/cordonem/bitbucket/workdir/src/isl/primitives/analytics/isl_analytics_module.c",
"/home/cordonem/bitbucket/workdir/src/isl/primitives/analytics/isl_analytics_module.h",
"/home/cordonem/bitbucket/workdir/src/isl/primitives/analytics/isl_calculator.c",
"/home/cordonem/bitbucket/workdir/src/isl/primitives/analytics/isl_calculator.h",
"/home/cordonem/bitbucket/workdir/src/isl/primitives/analytics"
],
"includePattern": ".+\\.js(doc|x)?$",
"excludePattern": "(^|\\/|\\\\)_"
},
"plugins": [
"/home/cordonem/jsdoc-3.5.5/plugins/commentsOnly"
],
"templates": {
"cleverLinks": false,
"monospaceLinks": false,
"default": {
"outputSourceFiles": true
}
}
}
Also, as a side note, if anyone knows how to make JSDoc stop trying to read the Makefile that would be very helpful information as well, as the Makefile throws errors when I try to run the full project.
you forgot to add the input files that should be processed by jsdoc. Here is how i did this in my project through CLI:
I ran this commands from my project's root.
./node_modules/.bin/jsdoc ./src/app/ -r -c ./node_modules/jsdoc/conf.json.EXAMPLE
which is same as shown in here, please read the linked document to understand the meaning of everything.
conf.json is same as conf.json.EXAMPLE

Failing to resolve dependency for Ext.ux

I am using ExtJS 6.2
I have the following line in my app.json:
"requires": [
"font-awesome",
"ux"
],
I am trying to create a simple text view using LiveSearchGrid.js, so I have the following in my app_name=md_registry folder md_registry/app/view/main/ListTest.js:
Ext.define('md_registry.view.main.ListTest', {
extend: 'Ext.ux.LiveSearchGridPanel',
//xtype: 'row-expander-grid',
//store: 'Patients',
xtype: 'mainlisttest',
requires: [
'md_registry.store.Patients',
'Ext.ux.LiveSearchGridPanel'
],
When I try doing a sencha app build, I get the following compiler error:
Failed to resolve dependency Ext.ux.LiveSearchGridPanel for file md_registry.view.main.ListTest
I have verified that this file exists in the path:
md_registry/ext/packages/ux/classic/src
From everything I've read, specifying the above requires in my app.json should be sufficient, but it's obviously not.
You are right now creating a universal app, but not using the correct folders for your code. You should definitely look into either creating a classic-only app, or a universal app with correct folder structure. If you want to make a universal app, but not now, you can compile only classic.
The solution was completely unobvious:
Had to comment this out from the "builds" profile in app.json:
"modern": {
"toolkit": "modern",
"theme": "theme-triton",
"sass": {
"generated": {
"var": "modern/sass/save.scss",
"src": "modern/sass/save"
}
}
}
I hope this helps someone!

Using grunt to inject your dependencies

Here is my GruntFile
files: {
'../index.html':
[
[
'../node_modules/**/*.min.js',
],
[
'../js/test/test.js',
'../css/main.css'
]
]
}
The issue with this, is that every min.js file inside my node_modules is gonna be injected. However, I would only like to include the main file of each dependencies (which sometimes can be in node_modules//dist/ and sometimes directly at the root of dep.
Is there a way to specify, only include the "main file" of each dep ?
Let me know if it needs clarification
I think I understand what you are saying. If you only want to include a certain file just explicitly state it. I don't know if this was obvious but the * symbol is a catch all.
Example:
files: {
'../index.html':
[
[
'../node_modules/dist/first.min.js',
'../node_modules/dist/js/second.min.js' <-- usually the last one doesn't have a comma.
],
[
'../js/test/test.js',
'../css/main.css'
]
]
}

Visual Studio Chutzpah Running test on different projects with AMD modules

I have two projects under a solution, one is my main web project, say MyProject and the other serves for testing purposes, say MyProject.Tests.
Solution
MyProject
MyProject.Tests
I want to have my JavaScript headless tests running to the second one.
On the first project, all the javascript files are under the Scripts directory, like so:
Scripts/
Common.js
Libs/
jquery/
jquery.js
requirejs/
require.js
At the test project, I have my chutzpah.json file on root.
MyProject.Tests
chutzpah.json
Tests/
Specs/
spec.js
The file has this configuration:
{
"Framework": "jasmine",
"TestHarnessReferenceMode": "AMD",
"TestHarnessLocationMode": "SettingsFileAdjacent",
"Tests": [ { "Path": "Tests/Specs" } ],
"AMDBasePath": "../MyProject/Scripts",
"CodeCoverageExcludes": ["*Common.js"],
"References": [
{ "Path": "../MyProject/Scripts/Libs/requirejs/require.js" },
{ "Path": "../MyProject/Scripts/Common.js" }
]
}
But when I try to run the spec file I get an error.
Spec file:
define(["jquery"], function ($) {
//code here. Doesn't matter, the error is because of the jquery module
});
The error, is this:
Error: Error opening C:/Users/g.dyrrahitis/Documents/Visual Studio 2013/Projects/MySolution/MyProject.Tests/Scripts/Libs/jquery/jquery.js: The system cannot find the path specified.
The thing is that chutzpah tries to find my jquery module at the test project rather the main project, where it resides.
Why I'm getting this kind of behavior and how can I solve this please? I've been trying for hours to tackle this with no luck so far.
Note
*The names MySolution, MyProject, MyProject.Tests are used for clarity, rather than using the real names.
I've found it, the chutzpah file hadn't the right configuration options (as expected) for the test harness directory.
I needed the TestHarnessDirectory and TestHarnessLocationMode options to explicitly instruct it to look at my main project directory.
This now is the correct one:
{
"TestHarnessDirectory": "../MyProject",
"TestHarnessLocationMode": "Custom",
"TestHarnessReferenceMode": "AMD",
"Framework": "jasmine",
"Tests": [ { "Path": "JavaScript/Specs" } ],
"AMDBasePath": "../MyProject/Scripts",
"CodeCoverageExcludes": [ "*Common.js" ],
"References": [
{ "Path": "../MyProject/Scripts/Libs/requirejs/require.js" },
{ "Path": "../MyProject/Scripts/Common.js" }
]
}
Just needed to tell chutzpah that the harness location mode is custom, in order to provide a directory for it, which is the root of my main project.
Beware for the right configuration paths then, you may end up struggling for hours like me to find a solution. And read the documentation thoroughly (which I hadn't done).

Categories

Resources