I am going through setting up chutzpah and Jasmine for unit testing my project in typescript.
I have installed Jasmine using npm but I am quite confused how to include chutzpah in visual studio code.
I went to this GitHub but nothing is clear to me:-
https://github.com/mmanela/chutzpah
Also, I downloaded files for visual studio code from below sources:-
https://marketplace.visualstudio.com/items?itemName=vs-publisher-2795.ChutzpahTestRunnerContextMenuExtension
https://marketplace.visualstudio.com/items?itemName=vs-publisher-2795.ChutzpahTestAdapterfortheTestExplorer
When I try to load above-downloaded files as an extension in visual code I get the error:-
extension/package.json not found inside zip.
How to include or install chutzpah in my project and then use the chutzpah.json file?
Thanks in advance.
First from command line go to you project location and do:
npm init
this will create package.json
Than:
chuzpah.json you can create manually and run at first from Visual Studio with right click, if you installed plugin properly, you will see run Unit tests option.
Seting up chutzpah.json is tricky part.
here is template for setup:
{
"Framework": "qunit|jasmine|mocha",
"FrameworkVersion": "",
"EnableTestFileBatching": "true|false",
"InheritFromParent": "true|false",
"InheritFromPtah": "<Path to another chutzpah.json>",
"IgnoreResourceLoadingErrors": "true|false"
"TestFileTimeout": "<Timeout in milliseconds>",
"TestHarnessLocationMode": "TestFileAdjacent|SettingsFileAdjacent|Custom",
"TestHarnessDirectory": "<Path to a folder>",
"TestHarnessReferenceMode": "Normal|AMD",
"RootReferencePathMode":"DriveRoot|SettingsFileDirectory",
"CodeCoverageIncludes": [],
"CodeCoverageExcludes": [],
"CodeCoverageIgnores": [],
"CodeCoverageExecutionMode": "Manual|Always|Never",
"CodeCoverageSuccessPercentage": <Number from 0 to 100>,
"CodeCoverageTimeout": <Timeout in milliseconds>
"References": [],
"Tests": [],
"CustomTestHarnessPath": "<Path to custom test harness file>",
"Compile": <A compile configuration object>,
"Server": <A server configuration object>,
"TestPattern": "<Regex test name pattern>",
"AMDBaseUrl": "<Path to same location that your Require.js config baseurl points to>",
"AMDAppDirectory": "<The root folder for your AMD paths>",
"UserAgent": "<Custom user agent to use during testing>",
"Transforms": [],
"EnableTracing": true|false,
"TraceFilePath": "<Path to log file. Defaults to %temp%/chutzpah.log>",
"Parallelism": "<Max degree of parallelism for Chutzpah. Defaults to number of CPUs>",
"BrowserArguments": <A map of browser name (keys) to corresponding browser arguments (values), i.e.; { 'chrome': '--allow-file-access-from-files' }.>
}
After all, you can use commang line and Chutzpah runner to run you unit test as part of CI
Related
So I want to run an e2e test using jest. I'm using nx monorepo architecture, and I have all my assets in a library folder and also nestjs microservices for my backend. I have all my proto files for my microservices in the library, and when I want to load them in my microservices, I do it like this :
protoPath: join(__dirname, 'assets-shared/job.proto'),
and in my workspace.json in my build i change the assets-shared like this:
"targets": {
"build": {
"options": {
"assets": [
{
"input": "libs/backend/shared/src/lib/assets",
"glob": "**/*",
"output": "assets-shared"
}
]
},
all is good, but when I run the test and when it wants to import and give value to it, it doesn't change it, and I have this error which is trying in its folder and not the library folder
ENOENT: no such file or directory, open '/home/dev/Project/apps/backend/api/src/modules/product/assets-shared/job.proto'
I tried the moduleNameMapper to give the libs folder to it manually but no avail.
moduleNameMapper: {
'^.+\\.(proto)$':
'<rootDir>/libs/backend/shared/src/lib/assets/$1',
// '^assets-shared(.*)': '/libs/backend/shared/src/lib/assets/$1',
},
non of these two worked
Have you considered publishing the libraries to a private npm repository or something like artifactory e.g. #my-company/assets
The approach you are trying may work locally, but for a ci/cd pipeline it would be much better to have a versioned artifact in npm or artifactory
I have a small project (but issue also appears on the one created by npx create-react-app my-app). I use VsCode and developing inside container (https://code.visualstudio.com/docs/remote/containers) . Dockerfile is very minimal:
ARG VARIANT="16-bullseye"
FROM mcr.microsoft.com/vscode/devcontainers/javascript-node:0-${VARIANT}
devcontainer.json has, almost, just defaults:
{
"name": "Node.js",
"build": {
"dockerfile": "Dockerfile",
"args": { "VARIANT": "16-bullseye" }
},
"settings": {},
"extensions": [
"dbaeumer.vscode-eslint"
],
"remoteUser": "node"
}
To debug, I run npm start , then I (for the 1st time) i click on Debug URl.
On macOS everything works, including file monitoring, so when I change js file, npm is recompiling instantly.
On Windows 11 however, the last part doesn't work - I need to stop and start npm manually, to have changes implement.
I've even tried to remove .vscode directory from my profile - no change here...
Any idea what is going on? Why it does work on macOS and doesn't work on Windows ?
I have the same extensions on both systems...I just can't find what is going on with Windows machine...
EDIT: the issue seems to be related to "Remote Development" extension for vscode . Issue is present only when using this extension on Windows. So I've opened a bug there: https://github.com/microsoft/vscode-remote-release/issues/6633
I am trying to use Jasmine, via NodeJs and Chutzpah to test the javascript in my project. This is in Visual Studio
The Jasmine test looks like
/// <reference path ='../../net5.Ui/wwwroot/Shared/Javascript/helpers.js' />
describe('Helpers test', function () {
it('Test contains', function () {
const result = helpers.isMatch();
expect(result).toBe(true);
});
});
My javascript files all have a similar structure (a singleton approach)
const helpers = new function(){
this.isMatch = function(){ return true; }
}
Visual Studio is able to detect the tests.
Node version 14.15.4
UPDATE
(I have stripped some of my original post as it's no longer valuable)
I have even removed the <reference path> and replaced it with chutzpah.json at the root of the project with
{
"Framework": "jasmine",
"References": [
{
"Path": "../../net5.Ui/wwwroot/Shared/Javascript/",
"Include": "*.js",
"Exclude": "*app.js"
}
],
"Tests": [
{
"Path": "Tests/",
"Includes": [ "*Spec.js" ]
}
]
}
ES6 features are only partially implemented in IE 11, that is why you get those errors about Invalid character. Template literals $ that you refer to are not implemented. Check more about the compatibility here https://kangax.github.io/compat-table/es6/#ie11
Depending on how you have set up your testing environment, you can change the browser that runs those tests to a different one, like Chrome or Firefox. For example if you use Karma as your test runner, you need to install the npm plugin karma-chrome-launcher and configure karma.conf.js so it uses Chrome.
You haven't given details about your testing environment, but it looks like you are still setting it up, so you could continue using Jasmine as your testing framework and additionally use Karma as your test runner and the free Visual Studio plugin Chutzpah Test Adapter, which enables you to run JavaScript unit tests from the command line and from inside of Visual Studio.
This will require a bit of effort for setting it up from your side, however I there is a very detailed guide about how to integrate all these here.
Am having a small problem with opening/importing a react-native into Android studio.
If I open the project using the open a project dialog, it tells me that the project is not gradle enabled and it is such a pain to make and test code changes. Couldn't find out how to enable the project as a gradle project after the fact even after going through the material on the help site.
On the other hand, if I import using the import a gradle project dialog and select the build.gradle file, the project is imported, but I only see the files inside the android directory instead of the main project directory. But this method allows me to push changes easily to the emulator.
How can I fix my problem?
Thanks,
Just import android directory from Android Studio,
make changes to your app/build.gradle
add these codes before apply from: "../../node_modules/react-native/react.gradle"
project.ext.react = [
bundleAssetName: "index.android.bundle",
entryFile: "index.android.js",
bundleInDebug: false,
bundleInRelease: true,
root: "../../",
jsBundleDirDebug: "$buildDir/intermediates/assets/debug",
jsBundleDirRelease: "$buildDir/intermediates/assets/release",
resourcesDirDebug: "$buildDir/intermediates/res/merged/debug",
resourcesDirRelease: "$buildDir/intermediates/res/merged/release",
inputExcludes: ["android/", "ios/"],
nodeExecutableAndArgs: ["node"],
extraPackagerArgs: []
]
Now create task for "react-native start" to your gradle
task startReactNative(type: Exec) {
workingDir "../../"
commandLine 'cmd', '/c', 'react-native', 'start'
println "Working Directory for React is: $workingDir"
standardOutput = new ByteArrayOutputStream()
ext.output = {
println "React-Native Output: " + standardOutput.toString()
return standardOutput.toString()
}
}
You can run your app as usual, after app installed to your device, run startReactNative task in order to activate Hot Reload
I'm using Chutzpah, with Jasmine, to unit test a number of AMD modules using Require.js.
My unit test project is separate to both the modules under test and the require.js config file.
I'm using chutzpah.json to connect these together, as such:
{
"Framework": "jasmine",
"TestHarnessReferenceMode": "AMD",
"TestHarnessLocationMode": "SettingsFileAdjacent",
"EnableTestFileBatching": true,
"AMDBasePath": "matches baseUrl path in require.js config file",
"References" : [
{"Path" : "path to require.js" },
{ "Path": "path to require.js config file" }
],
"Tests" : [
{"Path": "Specs"}
]
}
The tests run okay as expected.
The issue is that somewhere in the magic of resolving dependencies, I'm getting errors that a number of the css files cannot be located. These are relative paths and I'm guessing that because I'm initiating the test from a separate project it cannot correctly identify the base path.
As I say this isn't an issue running tests locally, but would cause an issue when integrating with a CI build.
Has anybody experienced this before and know of a workaround?