Skip to content

Commit

Permalink
Increase CLI tests timeout
Browse files Browse the repository at this point in the history
Exit CLI process when command finished
  • Loading branch information
chill117 committed Apr 18, 2024
1 parent 6fa2c54 commit 77d33ce
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 2 deletions.
11 changes: 10 additions & 1 deletion cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ program
}
const encoded = lnurl.encode(unencoded);
process.stdout.write(encoded);
process.exit();
});

program
Expand All @@ -41,6 +42,7 @@ program
}
const decoded = lnurl.decode(encoded);
process.stdout.write(decoded);
process.exit();
});

program
Expand Down Expand Up @@ -71,6 +73,7 @@ program
const { encoding, numBytes } = options;
options = { encoding, numBytes };
process.stdout.write(JSON.stringify(generateApiKey(options), null, 2));
process.exit();
});

program
Expand Down Expand Up @@ -265,7 +268,13 @@ program
}
delete options.configFile;
prepareGroupOptions(options, ['auth', 'lightning', 'store']);
createServer(options);
const server = createServer(options);
server.on('closed', () => {
process.exit();
});
['exit', 'SIGINT', 'SIGUSR1', 'SIGUSR2', 'SIGTERM'].forEach(event => {
process.on(event, () => server.close());
});
});

const prepareGroupOptions = function(options, groups) {
Expand Down
2 changes: 2 additions & 0 deletions test/unit/cli/decode.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ const assert = require('assert');

describe('CLI: decode [value]', function() {

this.timeout(5000);

it('prints decoded value', function() {
return this.helpers.cli('decode lnurl1dp68gurn8ghj7um9wfmxjcm99e3k7mf0v9cxj0m385ekvcenxc6r2c35xvukxefcv5mkvv34x5ekzd3ev56nyd3hxqurzepexejxxepnxscrvwfnv9nxzcn9xq6xyefhvgcxxcmyxymnserxfq5fns').then(result => {
assert.strictEqual(result, 'https://service.com/api?q=3fc3645b439ce8e7f2553a69e5267081d96dcd340693afabe04be7b0ccd178df');
Expand Down
2 changes: 2 additions & 0 deletions test/unit/cli/encode.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ const assert = require('assert');

describe('CLI: encode [value]', function() {

this.timeout(5000);

it('prints encoded value', function() {
return this.helpers.cli('encode https://service.com/api?q=3fc3645b439ce8e7f2553a69e5267081d96dcd340693afabe04be7b0ccd178df').then(result => {
assert.strictEqual(result, 'lnurl1dp68gurn8ghj7um9wfmxjcm99e3k7mf0v9cxj0m385ekvcenxc6r2c35xvukxefcv5mkvv34x5ekzd3ev56nyd3hxqurzepexejxxepnxscrvwfnv9nxzcn9xq6xyefhvgcxxcmyxymnserxfq5fns');
Expand Down
2 changes: 2 additions & 0 deletions test/unit/cli/generateApiKey.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ const { isHex } = require('lnurl-offline');

describe('CLI: generateApiKey [options]', function() {

this.timeout(5000);

it('prints new API key', function() {
return this.helpers.cli('generateApiKey').then(result => {
assert.notStrictEqual(result, '');
Expand Down
2 changes: 2 additions & 0 deletions test/unit/cli/generateNewUrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ const path = require('path');

describe('CLI: generateNewUrl [options]', function() {

this.timeout(5000);

let server;
before(function() {
server = this.helpers.createServer({
Expand Down
2 changes: 2 additions & 0 deletions test/unit/cli/help.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ const assert = require('assert');

describe('CLI: lnurl --help', function() {

this.timeout(5000);

it('prints help menu', function() {
return this.helpers.cli('--help').then(result => {
assert.ok(result.indexOf('Usage: cli [options] [command]') !== -1);
Expand Down
2 changes: 2 additions & 0 deletions test/unit/cli/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ const { spawn } = require('child_process');

describe('CLI: server [options]', function() {

this.timeout(5000);

let cliFilePath;
before(function() {
cliFilePath = this.helpers.cliFilePath;
Expand Down
2 changes: 1 addition & 1 deletion test/unit/lib/Server/close.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ describe('close([options])', function() {

afterEach(function() {
Object.entries(server.sockets).forEach(([id, socket], index) => {
socket.destroy();
socket && socket.destroy();
server.sockets[id] = null;
});
});
Expand Down

0 comments on commit 77d33ce

Please sign in to comment.