#nrwl/nest start the server every time I hit save - nestjs

I use NX Workspace with NestJS, and my issue is that every time I save something in the project, the entire program restarts without shutting down the previous app.
How could I restart the server?
This is the project.json file (inside the NestApp)
{
...
},
"configurations": {
"development": {
"optimization": true,
"extractLicenses": false,
"inspect": false
}
}
},
"serve": {
"executor": "#nrwl/js:node",
"options": {
"buildTarget": "server:build"
},
"configurations": {
"development": {
"buildTarget": "server:build:development"
},
}
},
},
"tags": []
}

Related

How to add base/baseHref to Nx/Vite manifest.json file

How can I prefix the file, css, and assets in a Vite manifest.json file with a CDN URL?
export default defineConfig({
base: 'https://my-cdn.com/',
build: {
manifest: true,
rollupOptions: {
input: '/path/to/main.js'
}
}
})
but the end result is:
{
"main.js": {
"file": "assets/main.4889e940.js",
"src": "main.js",
"isEntry": true,
"dynamicImports": [],
"css": ["assets/main.b82dbe22.css"],
"assets": ["assets/asset.0ab0f9cd.png"]
}
}
instead of:
{
"main.js": {
"file": "https://my-cdn.com/assets/main.4889e940.js",
"src": "main.js",
"isEntry": true,
"dynamicImports": [],
"css": ["https://my-cdn.com/assets/main.b82dbe22.css"],
"assets": ["https://my-cdn.com/assets/asset.0ab0f9cd.png"]
}
}
To achieve that, you need to add a base property with the URL or path in the project.json file under targets/build/options.
Here is an example project.json config file:
{
"name": "app",
"$schema": "node_modules/nx/schemas/project-schema.json",
"sourceRoot": "./src",
"projectType": "application",
"targets": {
"build": {
"executor": "#nrwl/vite:build",
"outputs": ["{options.outputPath}"],
"defaultConfiguration": "production",
"options": {
"outputPath": "dist/app",
"base": "https://my-cdn.com"
}
}
}
}
And if you are using vite without NX, then you can provide a base argument to the vite build command.
An example:
vite build --base="https://my-cdn.com"

Mongo client in Node doesn't receive connection response

I currently have a set of nodejs modules (containers) that connect to a local mongodb (also a container).
All modules works perfectly but with one of the I have the following problem:
https://i.stack.imgur.com/xuFqw.png
The connection seems to be accepted by mongo but the client doesn't receive the response and keeps waiting until it times out after 30 second (watch timestamps in the log)
The code of the client is the following:
async function connectToMongo() {
try {
const mongoUrl = 'mongodb://mongo:27017/LocalDB'
let result = await MongoClient.connect(mongoUrl, { useUnifiedTopology: true })
logger.info("Connected to Mongo DB")
return result
} catch (err) {
logger.error("Cannot connect to Mongo - " + err)
throw err
}
}
And is exactly the same as the other modules (that works).
Mongo is started without any settings or authentication.
I have tried using the following hostnames:
mongo : name of the container in which mongo is running
host.docker.internal : to address the host since the 27017 port of the container is binded to the host port
I honestly don't know what to try anymore...does anybody have an idea about what could be the problem?
UPDATE: as requested i'm adding info about how i'm starting the containers. Anyway I have omitted this part because they are started as Azure IoT Edge Modules. Anyway here is the infos from the deployment template:
"modules": {
"mongo": {
"settings": {
"image": "mongodb:0.0.1-replset-noauth",
"createOptions": "{\"HostConfig\":
{\"PortBindings\":{\"27017/tcp\":[{\"HostPort\":\"27017\"}]}}}"
},
"type": "docker",
"version": "1.0",
"status": "running",
"restartPolicy": "always"
},
"healthcheck": {
"settings": {
"image": "${MODULES.HealthCheck.debug}",
"createOptions": {
"HostConfig": {
"PortBindings": {
"9229/tcp": [
{
"HostPort": "9233"
}
]
}
}
}
},
"type": "docker",
"version": "1.0",
"env": {
"MONGO_CONTAINER_NAME": {
"value": "mongo"
},
"MONGO_SERVER_PORT": {
"value": "27017"
},
"DB_NAME": {
"value": "LocalDB"
}
},
"status": "running",
"restartPolicy": "always"
}
},
While this is the configuration of another module that perfectly works:
"shovel": {
"settings": {
"image": "${MODULES.Shovel.debug}",
"createOptions": {
"HostConfig": {
"PortBindings": {
"9229/tcp": [
{
"HostPort": "9229"
}
]
}
}
}
},
"type": "docker",
"version": "1.0",
"env": {
"MONGO_CONTAINER_NAME": {
"value": "mongo"
},
"MONGO_SERVER_PORT": {
"value": "27017"
},
"DB_NAME": {
"value": "LocalDB"
}
},
"status": "running",
"restartPolicy": "always"
},
(it's basically the same)
The modules are currently being launched using the IoT Simulator or on an IoT Edge device as Single Device deployments.

VSTS fabrikam-build-extension sample not working (Template)

Just tried the fabrikam-build-extension sample on TFS 2017 and VSTS. I can see the custom tasks modifying a build, but I'm unable to use the Template1 Template to create a build definition. Template1 isn't listed.
Anybody have a clue?
Yes, I can reproduce the issue. The two tasks can be add successfully. But the template1 can’t be added in VSTS build template.
But If I use the same content as template.json to create a build template by REST API, I can find it in build template.
PUT https://marinaliu.visualstudio.com/DefaultCollection/Git2/_apis/build/definitions/templates/myCustomTemplate?api-version=2.0
Application/json:
{
"id": "android",
"name": "My Custom Andriod Template",
"category": "Build",
"iconTaskId": "DF857559-8715-46EB-A74E-AC98B9178AA0",
"description": "Build your Android projects, run tests, sign and align Android App Package files. This template requires the Android SDK to be installed on the build agent.",
"template": {
"buildNumberFormat": "$(date:yyyyMMdd)$(rev:.r)",
"build": [{
"enabled": true,
"inputs": {
"wrapperScript": "$(Parameters.wrapperScript)",
"tasks": "$(Parameters.tasks)"
},
"task": {
"id": "8D8EEBD8-2B94-4C97-85AF-839254CC6DA4",
"versionSpec": "1.*"
}
},
{
"enabled": true,
"inputs": {
"files": "**/*.apk",
"jarsign": "false",
"zipalign": "false"
},
"task": {
"id": "80F3F6A0-82A6-4A22-BA7A-E5B8C541B9B9",
"versionSpec": "1.*"
}
},
{
"enabled": true,
"alwaysRun": true,
"inputs": {
"SourceFolder": "$(build.sourcesdirectory)",
"Contents": "**/*.apk",
"TargetFolder": "$(build.artifactstagingdirectory)"
},
"task": {
"id": "5bfb729a-a7c8-4a78-a7c3-8d717bb7c13c",
"versionSpec": "2.*"
}
},
{
"enabled": true,
"alwaysRun": true,
"inputs": {
"PathtoPublish": "$(build.artifactstagingdirectory)",
"ArtifactName": "drop",
"ArtifactType": "Container"
},
"task": {
"id": "2ff763a7-ce83-4e1f-bc89-0ae63477cebe",
"versionSpec": "1.*"
}
}
],
"options": [{
"definition": {
"id": "5D58CC01-7C75-450C-BE18-A388DDB129EC"
},
"enabled": true,
"inputs": {}
}],
"variables": {
"system.debug": {
"value": "false",
"allowOverride": true
}
},
"triggers": [],
"processParameters": {
"inputs": [{
"name": "wrapperScript",
"label": "{GradleWrapper}",
"defaultValue": "gradlew",
"required": true,
"type": "filePath"
},
{
"name": "tasks",
"label": "{GradleTasks}",
"defaultValue": "build",
"required": true,
"type": "string"
}
]
}
}
}
And the create an issue here, you can follow up.

Typescript project with Unit tests, problems running tests with Chutzpah

I have a project in Visual Studio that is using typescript and requirejs, and that is running QUnit tests with the help of Chutzpah.
Folderstructure in my project looks basically like this:
- chutzpah.json
- app/
- index.html
- js/
- config.js
- main.ts
- Module.ts
- tests/
- Test1.ts
up until now, I had requirejs configured so that in all my imports, I had to use
app/js/Module, for example, to load that one.
Tests were also running just fine.
Now, I have changed my requirejs config to use baseUrl of js inside the app folder, so I can use just "Module" for the import. application itself is running fine, but I cannot get the tests to work.
With my current chutzpah.json, it seems that it wants to load the test files from ../tests/, so for the Test1 example, it would want to load ../tests/Test1.js
This is my config.js:
require.config({
baseUrl: 'js',
paths: {
'swfJQ': '../libs/js/swfJQ'
},
shim: {
'swfJQ': {
"exports": "swfJQ"
}
}
});
This is my chutzpah.json:
{
"Framework": "qunit",
"TestHarnessReferenceMode": "AMD",
"TestHarnessLocationMode": "SettingsFileAdjacent",
"TypeScriptModuleKind": "AMD",
"Tests": [ { "Path": "tests", "Includes": [ "*Tests.ts" ] } ],
"AMDBaseUrl": "js",
"AMDAppDirectory": "app",
"References": [
{ "Path": "app/libs/js/jquery.js", "IsTestFrameworkFile": true },
{ "Path": "app/libs/require.js", "IsTestFrameworkFile": true },
{ "Path": "app/config.js" },
{ "Path": "require.d.ts", "IncludeInTestHarness": false },
{ "Path": "qunit.d.ts", "IncludeInTestHarness": false },
{ "Path": "tests", "IncludeInTestHarness": false, "Excludes": ["*.html"] },
{ "Path": "app/js", "IncludeInTestHarness": false }
],
"EnableCodeCoverage ": "true",
"CodeCoverageIncludes": [
"*app/js/*"
],
"CodeCoverageExcludes": [
"app/libs/*",
"tests/*"
]
}
This is one of the test files:
import Replay = require('../app/js/Module');
QUnit.module("Module tests");
test("Module.constructor", function (assert: QUnitAssert) { /* stuff */ }
I think the require('../app/js/Module') is more or less the culprit and will set the scope to ../, but if I write the code otherwise, the typescript compiler won't compile.
I guess this is probably something very easy I am missing, but I just can't pin it.
Maybe it is not a chutzpah problem I have, but my general Typescript setup should be different (so I don't have to use require('../app ... ') in my test files)?
Turned out this should have been quite easy:
I had to set the AMDBaseUrl in the Chutzpah config to "app/js", and removing the AMDAppDirectory property.
Can't believe I didn't try that before.
My chutzpah.json:
{
"Framework": "qunit",
"TestHarnessReferenceMode": "AMD",
"TestHarnessLocationMode": "SettingsFileAdjacent",
"TypeScriptModuleKind": "AMD",
"Tests": [ { "Path": "tests", "Includes": [ "*Tests.ts" ] } ],
"AMDBasePath": "app/js",
"References": [
{ "Path": "app/libs/js/jquery.js", "IsTestFrameworkFile": true },
{ "Path": "app/libs/js/kendo.ui.core.min.js", "IsTestFrameworkFile": true },
{ "Path": "app/libs/js/mediaelement-and-player.js", "IsTestFrameworkFile": true },
{ "Path": "app/libs/require.js", "IsTestFrameworkFile": true },
{ "Path": "app/libs/js/SCORM_API_wrapper.js" },
{ "Path": "require.d.ts", "IncludeInTestHarness": false },
{ "Path": "qunit.d.ts", "IncludeInTestHarness": false },
{ "Path": "tests", "IncludeInTestHarness": false, "Excludes": ["*.html"] },
{ "Path": "app/js", "IncludeInTestHarness": false }
],
"EnableCodeCoverage ": "true",
"CodeCoverageIncludes": [
"*app/js/*"
],
"CodeCoverageExcludes": [
"app/libs/*",
"tests/*"
]
}

Visual Studio Test Explorer does not discover jasmine tests

I have jasmine tests that run through the Chutzpah context menu extension (Run JS tests). However they do not get discovered by the Test Explorer and when I right-click and select Run Tests, the output from "Tests" gives me this:
System.ArgumentException: The directory name is invalid.
at System.IO.FileSystemWatcher..ctor(String path, String filter)
at Chutzpah.VS11.EventWatchers.TestFilesUpdateWatcher.AddWatch(String path)
at Chutzpah.VS2012.TestAdapter.ChutzpahTestContainerDiscoverer.UpdateTestContainersAndFileWatchers(IEnumerable`1 files, Boolean isAdd)
at Chutzpah.VS2012.TestAdapter.ChutzpahTestContainerDiscoverer.GetTestContainers()
at Chutzpah.VS2012.TestAdapter.ChutzpahTestContainerDiscoverer.get_TestContainers()
at Microsoft.VisualStudio.TestWindow.Controller.TestContainerDiscovererExtension.GetSortedContainers(ITestContainerDiscoverer discoverer)
at Microsoft.VisualStudio.TestWindow.Controller.TestContainerProvider.GetContainersFromDiscoverer(ITestContainerDiscoverer discoverer)
No tests found to run.
Here's my chutzpah.json file also:
{
"Framework": "jasmine",
"FrameworkVersion": "2",
"TestHarnessLocationMode": "SettingsFileAdjacent",
"References": [
{ "Path": "../../DIB.MemberCatalog/lib/dust/dust-full.js" },
{ "Path": "../../DIB.MemberCatalog/lib/dust-helpers/dust-helpers.js" },
{ "Path": "../../DIB.MemberCatalog/lib/harvey/harvey.js" },
{ "Path": "../../DIB.MemberCatalog/lib/hopscotch/js/hopscotch.js" },
{ "Path": "../../DIB.MemberCatalog/lib/jquery/jquery-1.11.1.js" },
{ "Path": "../../DIB.MemberCatalog/lib/jquery-ui/jquery-ui.js" },
{ "Path": "../../DIB.MemberCatalog/lib/jquery-validate/jquery.validate.js" },
{ "Path": "../../DIB.MemberCatalog/lib/knockout/knockout-3.1.0.js" },
{ "Path": "../../DIB.MemberCatalog/lib/knockout-mapping/knockout.mapping.js" },
{ "Path": "../../DIB.MemberCatalog/lib/knockout-validation/knockout.validation.js" },
{ "Path": "../../DIB.MemberCatalog/lib/lightbox/js/lightbox.js" },
{ "Path": "../../DIB.MemberCatalog/lib/respond/respond.js" },
{ "Path": "../../DIB.MemberCatalog/Scripts/jquery.qtip.min.js" },
{ "Path": "../../DIB.MemberCatalog/Scripts/json2.min.js" },
{ "Path": "../../DIB.MemberCatalog/Scripts/jquery.cookie.js" },
{ "Path": "../../DIB.MemberCatalog/Scripts/jquery.hoverIntent.min.js" },
{ "Path": "../../DIB.MemberCatalog/Scripts/jquery.lazyload.min.js" },
{ "Path": "../../DIB.MemberCatalog/Scripts/changecheck.js" },
{ "Path": "../../DIB.MemberCatalog/Scripts/stickytable.js" },
{ "Path": "../../DIB.MemberCatalog/Scripts/superalert.js" },
{ "Path": "../../DIB.MemberCatalog/Scripts/core.js" },
{ "Path": "prepare.js" },
{ "Path": "engine.js" }
],
"Tests": [
{ "Path": "tests" }
],
"CodeCoverageIncludes": [],
"CodeCoverageExcludes": []
}
Solution structure:
DIB.MemberCatalog
-Testing
- DIB.MemberCatalog.Tests.JS
- data
- lib
- jasmine-2.0.0
- (jasmine files, boot, console, jasmine)
- tests
- testfiles.js
- chutzpah.json
-DIB.MemberCatalog
- (more...)
I've scoured the internet and can't find a solution.
Solved by changing my test project name from DIB.MemberCatalog.Tests.JS to DIB.MemberCatalog.Tests.Client. Confusion happens when the project has the javascript file extension at the end of the project name.

Resources