Comments (4)
I forgot to say but thank you for the v2, really good job ;)
from nestjs-console.
Hi, this is a really good question.
The best way to test commands with promise is to use the exitOverride
method of commander.
Calling command.exitOverride()
on a command will disable the normal process.exit(). Commander will throw a CommanderError instead.
Since process.exit is mocked, the one called from your command is ignored, and the default one called by commander will throw a CommanderError.
import { CommanderError } from 'commander';
// ...
it('should succeed and create the index', async () => {
try {
// override the normal exit of commander (cli is the root command)
const consoleService = app.get<ConsoleService>(ConsoleService);
consoleService.getCli().exitOverride();
boot([process.argv0, 'node', '01-actor-id-actor-type-index', 'update']);
} catch (e) {
// commander will throw a CommanderError on first exit
expect(e).toBeInstanceOf(CommanderError);
// expect(e.message).toBe('(outputHelp)');
// expect(e.code).toBe('commander.help');
// expect(e.exitCode).toBe(0);
expect(await snapsCollection.listIndexes().toArray()).toEqual([
{
v: 2,
key: {
_id: 1
},
name: '_id_',
ns: 'snapping.snaps'
},
{
v: 2,
key: {
actor_id: 1,
actor_type: 1
},
name: 'actor_id_1_actor_type_1',
ns: 'snapping.snaps',
background: true
}
]);
}
});
I did not test it in the v1 branch, but after reading your question i think it's really important to implement a better approach.
Maybe making the method boot returning a Promise would be a better solution. I will try it in the v2 branch.
from nestjs-console.
That would awesome, I did look over your v2 branch to see if it was already done but it wasn't :D
If you can architecture the code the way to run a specific command and get back to the starting point, that would be awesome, even to close all the connection that could be present and initiated from the container (forRoot connection for example, or maybe you app.close after the boot call? I didn't look over the source
from nestjs-console.
v2 is now published, promise and errors are tested.
from nestjs-console.
Related Issues (20)
- Update commander peerdependencies version HOT 2
- Examples doesn't work? HOT 2
- Documentation update for using opts HOT 5
- Support in nest v8 HOT 3
- _actionResults is undefined HOT 1
- Unable to add a global option HOT 2
- Unable to register commands in nestjs-console HOT 4
- CLI will _always_ throw an error even with empty promise handler HOT 3
- Can't read CLI options to configure the database HOT 3
- TypeError: parent.addCommand is not a function HOT 5
- Task Not Exiting HOT 2
- Support nestjs@9 HOT 2
- use enableShutdownHooks with nest-console
- ERROR [ExceptionHandler] undefined HOT 1
- Process.env issue HOT 3
- How to pass array of strings? HOT 1
- Example is slow? HOT 2
- Support for NestJs v10 HOT 2
- Module '"nestjs-console"' has no exported member 'createSpinner'. HOT 5
- What does this project do differently compared to nest-commander ? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nestjs-console.