From 98380cda89d3d8476f598c271cf0fbef1b5c3631 Mon Sep 17 00:00:00 2001 From: zvictor Date: Fri, 15 Jul 2022 19:38:19 +0200 Subject: [PATCH] kill process after command finishes - fix #27 --- commands/build.js | 1 + commands/deploy-functions.js | 2 ++ commands/deploy-indexes.js | 2 ++ commands/deploy-roles.js | 2 ++ commands/deploy-schemas.js | 1 + commands/deploy.js | 2 ++ commands/pull-schema.js | 2 ++ commands/reset.js | 2 ++ tests/testUtils.js | 4 +++- utils.js | 11 +++++++++-- 10 files changed, 26 insertions(+), 3 deletions(-) diff --git a/commands/build.js b/commands/build.js index 0d36c3a..dbc806f 100755 --- a/commands/build.js +++ b/commands/build.js @@ -215,5 +215,6 @@ if (process.argv[1] === fileURLToPath(import.meta.url)) { ) console.log(`The sdk has been saved at ${location}`) + process.exit(0) })() } diff --git a/commands/deploy-functions.js b/commands/deploy-functions.js index d1b435d..6816c5b 100755 --- a/commands/deploy-functions.js +++ b/commands/deploy-functions.js @@ -77,5 +77,7 @@ if (process.argv[1] === fileURLToPath(import.meta.url)) { `User-defined function(s) created or updated:`, refs.map((x) => x.name) ) + + process.exit(0) })() } diff --git a/commands/deploy-indexes.js b/commands/deploy-indexes.js index 8aee19a..5c62b6a 100755 --- a/commands/deploy-indexes.js +++ b/commands/deploy-indexes.js @@ -71,5 +71,7 @@ if (process.argv[1] === fileURLToPath(import.meta.url)) { `User-defined index(es) created or updated:`, refs.map((x) => x.name) ) + + process.exit(0) })() } diff --git a/commands/deploy-roles.js b/commands/deploy-roles.js index fdcb9be..4e6cac6 100755 --- a/commands/deploy-roles.js +++ b/commands/deploy-roles.js @@ -71,5 +71,7 @@ if (process.argv[1] === fileURLToPath(import.meta.url)) { `User-defined role(s) created or updated:`, refs.map((x) => x.name) ) + + process.exit(0) })() } diff --git a/commands/deploy-schemas.js b/commands/deploy-schemas.js index 364a601..1750172 100755 --- a/commands/deploy-schemas.js +++ b/commands/deploy-schemas.js @@ -71,5 +71,6 @@ if (process.argv[1] === fileURLToPath(import.meta.url)) { } console.log(await main(inputPath)) + process.exit(0) })() } diff --git a/commands/deploy.js b/commands/deploy.js index 4331560..14c2275 100755 --- a/commands/deploy.js +++ b/commands/deploy.js @@ -71,6 +71,8 @@ if (process.argv[1] === fileURLToPath(import.meta.url)) { } await main(types) + console.log(`\n\nAll done! All deployments have been successful 🦆`) + process.exit(0) })() } diff --git a/commands/pull-schema.js b/commands/pull-schema.js index 38e5481..e43a4b1 100755 --- a/commands/pull-schema.js +++ b/commands/pull-schema.js @@ -76,5 +76,7 @@ if (process.argv[1] === fileURLToPath(import.meta.url)) { if (!outputPath) { console.log(schema) } + + process.exit(0) })() } diff --git a/commands/reset.js b/commands/reset.js index 75371d6..32acc93 100755 --- a/commands/reset.js +++ b/commands/reset.js @@ -86,6 +86,8 @@ if (process.argv[1] === fileURLToPath(import.meta.url)) { } await main(types) + console.log(`All reset operations have succeeded.`) + process.exit(0) })() } diff --git a/tests/testUtils.js b/tests/testUtils.js index e079af3..5eeb369 100644 --- a/tests/testUtils.js +++ b/tests/testUtils.js @@ -38,8 +38,10 @@ export const setupEnvironment = (name, options = {}) => { end(() => { deleteDatabase(dbName, process.env.TESTS_SECRET) delete process.env.BRAINYDUCK_CACHE + debug(`Deleted database ${timestamp}_${name}`) }) - debug(`Deleted database ${timestamp}_${name}`) + + afterAll(() => faunaClient().close()) } export const amountOfFunctionsCreated = () => faunaClient().query(q.Count(q.Functions())) diff --git a/utils.js b/utils.js index 30ca5bc..340c3b4 100644 --- a/utils.js +++ b/utils.js @@ -81,9 +81,15 @@ export const loadSecret = () => { return secret } +let _faunaClient + export const faunaClient = () => { + if (_faunaClient) { + return _faunaClient + } + const { FAUNA_DOMAIN, FAUNA_SCHEME, FAUNA_PORT } = process.env - const options = { secret: loadSecret() } + const options = { secret: loadSecret(), http2SessionIdleTime: 100 } if (FAUNA_DOMAIN) { options.domain = process.env.FAUNA_DOMAIN @@ -97,7 +103,8 @@ export const faunaClient = () => { options.port = process.env.FAUNA_PORT } - return new Client(options) + _faunaClient = new Client(options) + return _faunaClient } export const patternMatch = async (pattern, cwd = process.cwd()) =>