I'm developing a very simple typescript project and I added a very tiny test with mocha. I installed mocha sidebar on VS Code and all it's dependencies, but test are not showing in the left panel.
The strange is that when I press debug button, my test run without problem (?)
I want to distribute this package on NPM, and only distribute .js, .d.ts, js.map and d.ts.map files.
I think the problem is in my project.json, but I cannot figure what is it. The source code is here
The only change I needed was in the VS code workspace settings: Under extensions I pointed the 'mocha glob files'-setting to my test scripts
One thing that I notice from your repo is you have package.json, test folder and another src folder inside type-exception/src.
I can run the mocha sidebar plugin successfully.
My solution is to open the project in vscode from the type-exception/src folder not type-exception folder.
My file structure
My mocha sidebar
I also saw that you have correct vscode workspace settings that set mocha files to
{
"mocha.files.glob": "lib/test/**/*.js"
}
Hope it helps
I had the Testing view showing Jest tests and realised that for Mocha I needed to install another VSCode Extension called "Mocha Test Explorer": https://marketplace.visualstudio.com/items?itemName=hbenl.vscode-mocha-test-adapter
Once installed I created/edited a .vscode/settings.json file in my project folder and added the following clues to tell Mocha to find my tests under the tests folder:
{
"mochaExplorer.files": "tests/**/*.ts"
}
Related
I have a node.js project with some tests (it's my own test framework).
The structure of the project is the following:
app.js
tests
- test1.js
- test2.js
Inside the app.js file, I have a special setting that allows me to specify the path for running tests. If I run the following command from the terminal:
`node app.js` all tests from the tests folder will be run
If I run the following command from the terminal :
`node app.js ./tests/test1.js` - only the specific file will be run
I want to run these tests from IDE (I need to run all tests or the specific file) - from the Visual Studio Code or IntelliJ IDEA (by click on the file).
I've figured out how I can run all tests:
for IntelliJ IDEA I set up Node.js configuration and now I can run tests by click on the app.js file:
in Visual Studio Code, I can run all tests from the app.js file from IDE by clicking on Run command on the left panel
My question is: how can I run the specific file by click on it from IDE (clicks on test1.js/test2.js)? I want to click on the file with the test and imitate the same command as I run it from the terminal:
node app.js tests/test1.js
I know that if I'd used some test framework like Mocha I've could use the special plugins, but using an external test framework is not an option for me.
I figured out, that the best option for my task is would be to set up an NPM configuration for the project. The window for setting up the NPM configuration has some fields which should be filled:
package.json - path to your package.json
command - run
scripts - the name of the main script from the package.json file
environment - your environment variables (if you have it - they should be filled, because otherwise, the npm runner could not catch them from the '.env' file)
The most important field for my task is 'Arguments' - I fill it with the path to file that I want to run and then in my node.js app I'm able to access it via the proccess.argv array.
My projects uses a /server folder for my backend code and /react-ui for my client side code. There's a package.json in each folder. I can run test separately in the cmd line, but I would like to run both at the same time. I know about the multi projects feature of jest, but it doesn't seem to work with create-react-app. I'm trying to setup jest with babel as if I was not using create-react-app, but it seems like the wrong approach considering jest is already setup in CRA.
My current setup runs from the /server jest installation. With projects: ['<rootDir>', '<rootDir>/../react-ui']. The jest documentation isn't clear how I could direct it to run npm test in /react-ui
My only goal is to be able to watch both at the same time and I would like to not eject from CRA.
You can have (gulp) scripts on the main level that run each tests separately, but using same configs.
I'm setting up a lerna monorepo with jest, I'm using jest's projects like so: projects: ['<rootDir>/packages/*'].
Running tests work as expected, however, I'm not sure how can I run a specific project? Say I have:
/packages
jest.config.js
/core
jest.config.js
/blog
jest.config.js
Currently jest runs tests in both packages using their specific configs, however, I'm not sure how can I tell jest to just run tests in one of those packages?
Assuming you want to do this with Jest's projects property:
As of Jest v26.1.0, you can now run selected projects with Jest by doing the following:
jest --selectProjects myproj
This will find any "project" in your jest.config.js by it's displayName value.
See:
https://github.com/facebook/jest/issues/7542
https://github.com/facebook/jest/pull/8612
https://github.com/facebook/jest/releases/tag/v26.1.0
You can call jest with the name of a test that you want to run. You can also use just parts of the path to the test, or even a regular expression. So in your case, you could run tests in the core package like this:
jest packages/core
There is currently no clean way of doing it from the CLI (see https://github.com/facebook/jest/issues/6189), but you can use https://github.com/rogeliog/jest-watch-select-projects to achieve it in watch mode
I have made a Electron Application, mainly for my helpdesk colleagues at work.
What it does (Context):
It provides a simple gui with different "Tasks" it can do. Example:
For this I'm using a combination of:
Node with Electron
React
Node-Powershell
The Problem:
The app when I run it in Development Mode is running as it should. But after I build and package it with electron, the NPM package node-powershell can't find the .ps1 scripts anymore.
I think I already identified the problem, but I don't know what the solution to this problem is.
node-powershell needs a path to a script and an array of commands.
I have set it up like this:
const p1 = require('path').resolve();
const scriptPath = require('path').join(p1, 'src/PowershellScripts/AddMailboxPermissions.ps1');
And then ps.addCommand(scriptPath, commands); (node-powershell)
As said before this works fine in development mode with a webpack server, but when run after packaging I get this error:
C:\Users\Huberdo\Projekte\Powershell-SAS-App\Client\builds\basic-electron-react-boilerplate-win32-x64\src\PowershellScripts\GetRemoteMac.ps1 cannot be found.
The reason is because the packaging has following structure. The .ps1 files now have following path:
C:\Users\Huberdo\Projekte\Powershell-SAS-App\Client\builds\basic-electron-react-boilerplate-win32-x64\resources\app\src\PowershellScripts
So this is the main issue. How do I package this "the right way" so that it's actually working afterwards.
Infos:
I run this on a windows 10 x64 machine
package.json scripts:
"dev": "webpack-dev-server --hot --host 0.0.0.0 --config=./webpack.dev.config.js",
"build": "webpack --config webpack.build.config.js",
"package": "webpack --config webpack.build.config.js",
When I run it in dev mode it resolves the correct path and everything is working just fine
I hope someone of you can help me or guide me into the right direction.
Possible Idea:
Reference a completely other path and copy the ps1 files into another directory with a gulp task? Never used it. Could this be a possible solution? If yes how to best approach this?
Update
When I copy the src folder from C:\Users\Huberdo\Projekte\Powershell-SAS-App\Client\builds\basic-electron-react-boilerplate-win32-x64\resources\app into the root C:\Users\Huberdo\Projekte\Powershell-SAS-App\Client\builds\basic-electron-react-boilerplate-win32-x64 it's working again. So it's mainly a path issue and I don't know how to solve it.
Last but not least a direct link to the project on github:
https://github.com/dhuber666/Powershell-SAS-Tool
Here I call the ps1 script:
https://github.com/dhuber666/Powershell-SAS-Tool/blob/SendAs/src/components/scriptsComponents/AddMailboxPermissions.js
!Thank you!
I am doing something similar, but the approach I am using for the PowerShell scripts is to create them as PowerShell modules. Then you can just place them in one of the valid PSModule location and you should be good to go. And you could just write a powershell script to copy you modules to the correct location and copy the package to the desktop or where ever it needs to be.
A very simple module could be something like this:
In C:\Program Files\WindowsPowerShell\Modules create a folder called MyModuleTest. In this folder create a file called MyModuleTest.psm1. In this PSM1 file create a function e.g.
function Invoke-MyModuleTest {
Write-host "This is My Module"
}
Save the file, open a powershell console session and then if you run Invoke-MyModuleTest it will output to the console.
You can read more about modules here
You can also find some nice examples of more complex modules here
Once your have converted your script to modules you can just call them like any cmdlet, I currently don't have anything I can share.
I'm using jasmine-node to test my Meteor application and I want to use the auto-test feature so I don't have to rerun the tests all the time by myself.
My meteor application folder structure is like this:
server
foo.coffee
tests
foo.spec.coffee
And with the spec file I want to test code which is located in foo.coffee. I start jasmine-node with this args:
jasmine-node ./ --autotest --coffee --test-dir tests
And now I would assume that the autotest feature will react on all changes in the root folder but it just reacts on changes in the test folder. And I can't start it in the root folder because I get an error in the .meteor files (and I don't want to have jasmine testing/including the meteor code anyway).
So I want to have jasmine rerun the tests even if I change code in the server folder. How can I achieve that?
Use the --watch parameter along with --autotest and specify the directories that contain whatever files you want to have watched.