visual studio code clean task - javascript

I'm working in Visual Studio Code in Ubuntu on my Typescript project. And I'm wondering is there any possibility to execute some kind of 'clean' task.
Here's my tasks.json
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "0.1.0",
"tasks": [
{
"taskName": "tsc",
"command": "tsc",
"isShellCommand": true,
"isBackground": true,
"problemMatcher": "$tsc"
},
{
"taskName": "clean",
"linux": {
"command": "rm",
"args": [
"./src/*.js"
],
"isShellCommand": true
},
"isShellCommand": true,
"isBackground": true
}
]
}
And here's my project structure.
Executing task clean says there's no such files or directory, while executing 'pwd' instead of rm says that I'm in the root of my project.
Any suggestions how does this build system work? Maybe there's some special syntax for env variables in VS Code?

After VSCode 1.14, we have a new tasks manager in VSCode. I'm using .NET Core on ubuntu and I have a build and a clean tasks like this:
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "process",
"command": "dotnet",
"args": [
"build",
"MyProj.csproj"
],
"options": {
"cwd": "${workspaceFolder}/src/MyProj/"
},
"problemMatcher": "$msCompile"
},
{
"label": "clean",
"type": "shell",
"linux": {
"command": "rm",
"args": [
"-rfv",
"bin/*",
"obj/*"
]
},
"windows": {
"command": "del",
"args": [
"/S /Q",
"bin/*",
"obj/*"
]
},
"options": {
"cwd": "${workspaceFolder}/src/MyProj/"
},
"problemMatcher": []
}
]
}
Both tasks works as expected.

I have also been looking for this, but as far as I understand, it's not possible to have more than one task in tasks.json. You can have a tasks array, but that only contains different command line parameters for the same task. This example has the 'echo' task, and you can call it with different parameters. If you call the task 'hello' then 'echo Hello World' will be executed:
{
"version": "0.1.0",
"command": "echo",
"isShellCommand": true,
"args": [],
"showOutput": "always",
"echoCommand": true,
"suppressTaskName": true,
"tasks": [
{
"taskName": "hello",
"args": ["Hello World"]
},
{
"taskName": "bye",
"args": ["Good Bye"]
}
]
}

Have you tried using workspace variables? ${workspaceRoot} might be particular useful for you.

Related

Error: Problem validating fields in app.json. See https://docs.expo.io/workflow/configuration/ • should NOT have additional property 'nodeModulesPath

Trying to use expo publish in order to host my react native app and show other people but running into this error. It seems to indicate the need for the removal of a 'nodeModedulesPath' property from my app.json but ...well here is the structure. I'm not quite sure what needs to be removed or why, any help would be greatly appreciated.
{
"expo": {
"name": "new",
"slug": "new",
"version": "1.0.0",
"orientation": "portrait",
"icon": "./assets/icon.png",
"userInterfaceStyle": "light",
"splash": {
"image": "./assets/splash.png",
"resizeMode": "contain",
"backgroundColor": "#9CB2A5"
},
"updates": {
"fallbackToCacheTimeout": 0
},
"assetBundlePatterns": [
"**/*"
],
"ios": {
"supportsTablet": true
},
"android": {
"adaptiveIcon": {
"foregroundImage": "./assets/adaptive-icon.png",
"backgroundColor": "#9CB2A5"
}
},
"web": {
"favicon": "./assets/favicon.png"
},
"plugins": [
[
"expo-notifications",
{
"icon": "./assets/icon.png",
"color": "#ffffff",
"sounds": [
"./local/assets/notification-sound.wav",
"./local/assets/notification-sound-other.wav"
]
}
]
],
"extra": {
"eas": {
"projectId": "027e8e01-7c7e-4212-8812-a49f5db4f826"
}
}
}
}
I tried finding the nodeModulesPath, there is no string with those characters in the entire project directory, and the configuration workflow shown in expo's documentation doesn't exactly explain what would cause this error.

Typescript debugging with Visual Studio Code

I'm trying to bind breakpoints in my code, but I'm getting this from the visual code:
"This breakpoint was initially set in:
C:\workspace\N3urons\order-service\src\entities\Order\OrderController.ts line 595 column 1
We couldn't find a corresponding source location, but found some other files with the same name:
file:///C:/workspace/N3urons/order-service/src/entities/Order/OrderController.ts
C:/workspace/N3urons/order-service/src/entities/Order/OrderController.ts
If this is the same file, you may need to adjust your build tool to correct the paths."
I'm coding on Windows and Visual Studio doesn't find the file, but finds matching files with these slashes.
Could someone help me with this?
My launch.json looks like this:
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "attach",
"name": "Node: Nodemon",
"processId": "${command:PickProcess}",
"restart": true,
"protocol": "inspector"
},
{
"name": "Docker: Attach to Node",
"type": "node",
"request": "attach",
"port": 9231,
"address": "localhost",
"localRoot": "${workspaceFolder}",
"remoteRoot": "/usr/src/service",
"sourceMapPathOverrides": {
"/usr/src/service/*": "${workspaceRoot}/*"
},
"protocol": "inspector",
"restart": true
}
]
}

PM2 Common Settings For All Processes in JSON File

I am currently starting multiple Node.js processes using pm2. These processes are defined in a JSON file, which is used by running
pm2 start pm2.json
As you can see from the JSON file below, there is a lot of repetition. For example, making a change to the error_file location or setting the variable time to true involves a lot of repetition, which can be tedious with 10-20 such scripts defined in the JSON file.
Is it possible to simplfy the JSON file by setting time variable only once in the file and have it apply to all processes?
Also, is it possible to use a template to define error_file and out_file, such as "../logs/${name}-error.log"?
Example pm2.json
{
"apps": [
{
"name": "foo-a",
"script": "./foo/a.js",
"args": "-e apple",
"error_file": "../logs/foo-a-error.log",
"out_file": "../logs/foo-a-out.log",
"time": true
},
{
"name": "foo-b",
"script": "./foo/b.js",
"args": "-e banana",
"error_file": "../logs/foo-b-error.log",
"out_file": "../logs/foo-b-out.log",
"time": true
}, {
"name": "bar-c",
"script": "./bar/c.js",
"args": "-e cranberry",
"error_file": "../logs/bar-c-error.log",
"out_file": "../logs/bar-c-out.log",
"time": true
},
...
You can use js file instead json file, it will allow you to create and use common variable/function for repetition part.
const time = true
module.exports = {
"apps": [
{
"name": "foo-a",
"script": "./foo/a.js",
"args": "-e apple",
"error_file": "../logs/foo-a-error.log",
"out_file": "../logs/foo-a-out.log",
"time": time
},
{
"name": "foo-b",
"script": "./foo/b.js",
"args": "-e banana",
"error_file": "../logs/foo-a-error.log",
"out_file": "../logs/foo-a-out.log",
"time": time
}, {
"name": "bar-c",
"script": "./bar/c.js",
"args": "-e cranberry",
"error_file": "../logs/bar-c-error.log",
"out_file": "../logs/bar-c-out.log",
"time": time
},
...

Jest "No tests found" after update VSCode to 1.32.1

I'm using debugging jest with vscode config, here is launch.json configurations:
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Jest Current File",
"program": "${workspaceFolder}/node_modules/.bin/jest",
"args": [
"${relativeFile}"
],
"env": {
"cross-env": "1",
"NODE_PATH": "./src",
"__PLATFORM__": " WEB",
},
"runtimeArgs": [
],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"windows": {
"program": "${workspaceFolder}/node_modules/jest/bin/jest",
}
}
]
}
This configurations worked properly until I updated VSCode to 1.32.1. Now when I run Jest current file, the console prints out like this:
Debugger attached.
No tests found
In D:\workspace\my-project
747 files checked.
testMatch: - 747 matches
testPathIgnorePatterns: \\node_modules\\ - 747 matches
testRegex: (\\__tests__\\.*|(\.|\\)(test))\.js?$ - 15 matches
Pattern: src\utils\storage\my-file-name.test.js - 0 matches
Waiting for the debugger to disconnect...
Any help would be appreciated, thanks in advance.
After install old version VSCode (1.30.2), I saw the output:
Test Suites: 1 passed, 1 total
Tests: 9 passed, 9 total
Snapshots: 0 total
Time: 4.866s
Ran all test suites matching /src\\utils\\storage\\my-file-name.test.js/i.
Waiting for the debugger to disconnect...
Difference is Pattern:
v1.30.2: /src\\utils\\storage\\my-file-name.test.js/i.
v1.32.1: src\utils\storage\my-file-name.test.js
VSCode change their ${relativeFile}'s seperator from \\ to \, this is why jest couldn't find out test file
For those who are being stuck, just change "${relativeFile}" to "${fileBasenameNoExtension}" in launch.json configuration:
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Jest Current File",
"program": "${workspaceFolder}/node_modules/.bin/jest",
"args": [
"./${fileBasename}"
],
"env": {
"cross-env": "1",
"NODE_PATH": "./src",
"__PLATFORM__": " WEB",
},
"runtimeArgs": [
],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"windows": {
"program": "${workspaceFolder}/node_modules/jest/bin/jest",
}
}
]
}
Better use --runTestsByPath ${relativeFile}, which always works.

Unexpected end of JSON input when using cucumber-html-reporter with Nightwatch-Cucumber

I use Nightwatch-Cucumber to automate my end2end tests and want to create a cucumber html report after test execution with cucumber-html-reporter, but I get an error while report generation by cucumber-html-reporter:
Unable to parse cucumberjs output into json: 'reports/cucumber.json' SyntaxError: reports/cucumber.json: Unexpected end of JSON input
at JSON.parse (<anonymous>)
at Object.readFileSync (/Users/GRme/projects/e2e-web-tests/node_modules/jsonfile/index.js:69:17)
And I don't know why my generated cucumber.json is invalid.
I use the following versions:
"cucumber-html-reporter": "^2.0.0",
"nightwatch": "^0.9.16",
"nightwatch-cucumber": "^7.1.10",
This is my config in nightwatch.conf.js:
require('nightwatch-cucumber')({
cucumberArgs: [
'--tags', '#run',
'--require', 'timeout.js',
'--require', 'hooks.js',
'--require', 'features/step_definitions',
'--format', 'pretty',
'--format', 'json:reports/cucumber.json',
'features']
});
And this is the hooks.js, where my cucumber html report generation is executed:
const {client} = require('nightwatch-cucumber');
const {defineSupportCode} = require('cucumber');
var reporter = require('cucumber-html-reporter');
var options = {
theme: 'bootstrap',
jsonFile: 'reports/cucumber.json',
output: 'reports/cucumber_report.html',
reportSuiteAsScenarios: true,
launchReport: false,
//ignoreBadJsonFile: true,
name: 'NIKITA end2end tests',
brandTitle: 'NIKITA end2end tests',
storeScreenShots: true,
metadata: {
// "App Version": "0.0.1",
// "Test Environment": "AAT",
// "Browser": "Chrome XXX",
// "Platform": "Mac OS X",
}
};
defineSupportCode(({Before, After}) => {
Before(function() {
client.maximizeWindow();
});
After(function() {
reporter.generate(options);
});
});
My generated and apparently invalid cucumber.json looks like this:
[
{
"keyword": "Feature",
"line": 1,
"name": "only a test feature",
"tags": [],
"uri": "/Users/GRme/projects/e2e-web-tests/features/testFeature.feature",
"elements": [
{
"keyword": "Scenario",
"line": 4,
"name": "only a test Scenario",
"tags": [
{
"line": 3,
"name": "#run"
}
],
"id": "only-a-test-feature;only-a-test-scenario",
"steps": [
{
"arguments": [],
"keyword": "Before",
"result": {
"status": "passed",
"duration": 1
},
"hidden": true,
"match": {
"location": "/Users/GRme/projects/e2e-web-tests/hooks.js:24"
}
},
{
"arguments": [],
"keyword": "When ",
"name": "\"1\" seconds waiting",
"result": {
"status": "passed",
"duration": 2615
},
"line": 5,
"match": {
"location": "/Users/GRme/projects/e2e-web-tests/features/step_definitions/abstractStepDefinition.js:10"
}
},
{
"arguments": [],
"keyword": "After",
"result": {
"status": "passed",
"duration": 4
},
"hidden": true,
"match": {
"location": "/Users/GRme/projects/e2e-web-tests/hooks.js:28"
}
}
]
}
],
"id": "only-a-test-feature"
}
]
Generating the Cucumber Html Report via Jenkins with the Cucumber Reports Plugin runs successful.
So, how can I solve my problem and which framework (Nightwatch-Cucumber or cucumber-html-reporter) is the reason? And what is the invalid part of my generated cucumber.json?
Try to generate cucumber html report in a separate step of test execution. For example if you are using npm script use a separate npm script to generate the report. The problem with your approach is that in Cucumber.js global After hook the report is not created yet. That's why you are getting such an error. I suggest to use a separate node.js script to run cucumber-html-reporter.
I solved the problem by using Event Handler. I put the Cucumber report generation in such a Event Handler function for the event AfterFeatures and it works perfect for me.
More information you can find here.

Categories

Resources