From b5f15bbfbad2aca7400cad70c0623e9698bf3efc Mon Sep 17 00:00:00 2001 From: Salam Suleymanov Date: Tue, 26 Nov 2024 15:40:17 +0100 Subject: [PATCH] throw exeception if it throw by the function but not expected in test (#32) * throw exeception if it throw by the function but not expected in test * bump version --------- Co-authored-by: Ab <219340+abdala@users.noreply.github.com> --- assert/package.json | 2 +- dtc-aws-plugin/package.json | 2 +- dtc-graphql-plugin/package.json | 2 +- dtc-mysql-plugin/package.json | 2 +- dtc-playwright-plugin/package.json | 2 +- dtc/package.json | 2 +- dtc/src/plugins/function-call-plugin.ts | 6 +++++- dtc/test/plugins/function-call-plugin.test.ts | 20 +++++++++++++++++++ nock-aws/package.json | 2 +- type-guard/package.json | 2 +- yaml/package.json | 2 +- 11 files changed, 34 insertions(+), 10 deletions(-) diff --git a/assert/package.json b/assert/package.json index cc604f5..1cd7766 100644 --- a/assert/package.json +++ b/assert/package.json @@ -1,6 +1,6 @@ { "name": "@cgauge/assert", - "version": "0.10.2", + "version": "0.10.3", "description": "Extra assert library", "type": "module", "repository": { diff --git a/dtc-aws-plugin/package.json b/dtc-aws-plugin/package.json index 01a7a97..66392d5 100644 --- a/dtc-aws-plugin/package.json +++ b/dtc-aws-plugin/package.json @@ -1,6 +1,6 @@ { "name": "@cgauge/dtc-aws-plugin", - "version": "0.10.2", + "version": "0.10.3", "description": "AWS plugin for Declarative TestCases", "repository": { "type": "git", diff --git a/dtc-graphql-plugin/package.json b/dtc-graphql-plugin/package.json index e977251..478849c 100644 --- a/dtc-graphql-plugin/package.json +++ b/dtc-graphql-plugin/package.json @@ -1,6 +1,6 @@ { "name": "@cgauge/dtc-graphql-plugin", - "version": "0.10.2", + "version": "0.10.3", "description": "GraphQl plugin for Declarative TestCases", "repository": { "type": "git", diff --git a/dtc-mysql-plugin/package.json b/dtc-mysql-plugin/package.json index f1e85aa..6dfd3f7 100644 --- a/dtc-mysql-plugin/package.json +++ b/dtc-mysql-plugin/package.json @@ -1,6 +1,6 @@ { "name": "@cgauge/dtc-mysql-plugin", - "version": "0.10.2", + "version": "0.10.3", "description": "MySQL plugin for Declarative TestCases", "repository": { "type": "git", diff --git a/dtc-playwright-plugin/package.json b/dtc-playwright-plugin/package.json index 9caa386..cf49192 100644 --- a/dtc-playwright-plugin/package.json +++ b/dtc-playwright-plugin/package.json @@ -1,6 +1,6 @@ { "name": "@cgauge/dtc-playwright-plugin", - "version": "0.10.2", + "version": "0.10.3", "description": "Playwright plugin for Declarative TestCases", "repository": { "type": "git", diff --git a/dtc/package.json b/dtc/package.json index 7b5fcae..e1f11c7 100644 --- a/dtc/package.json +++ b/dtc/package.json @@ -1,6 +1,6 @@ { "name": "@cgauge/dtc", - "version": "0.10.2", + "version": "0.10.3", "description": "Declarative TestCases", "repository": { "type": "git", diff --git a/dtc/src/plugins/function-call-plugin.ts b/dtc/src/plugins/function-call-plugin.ts index 638cdcd..56d8317 100644 --- a/dtc/src/plugins/function-call-plugin.ts +++ b/dtc/src/plugins/function-call-plugin.ts @@ -50,7 +50,11 @@ export const assert = (args: unknown) => { } nodeAssert.equal(args.exception.name, exception.name) - } + } else { + if (exception) { + throw exception + } +} if (response) { extraAssert.objectContains(response, args) diff --git a/dtc/test/plugins/function-call-plugin.test.ts b/dtc/test/plugins/function-call-plugin.test.ts index 9766c28..5ef543c 100644 --- a/dtc/test/plugins/function-call-plugin.test.ts +++ b/dtc/test/plugins/function-call-plugin.test.ts @@ -2,6 +2,7 @@ import {test} from 'node:test' import {act, assert} from '../../src/plugins/function-call-plugin' import {dirname} from 'node:path' import {fileURLToPath} from 'node:url' +import nodeAssert from 'node:assert' const __dirname = dirname(fileURLToPath(import.meta.url)) @@ -53,3 +54,22 @@ test('It call a sync function with exception', async () => { assert(args) }) + +test('It call a sync function and throw exception if id does not exist in assert', async () => { + const args = {} + + await act( + { + import: 'functionWithException', + from: '../fixtures/functions.js', + arguments: [args], + }, + __dirname, + ) + + try { + assert(args) + } catch (e) { + nodeAssert.ok(true) + } +}) diff --git a/nock-aws/package.json b/nock-aws/package.json index 80e3a13..b56e70e 100644 --- a/nock-aws/package.json +++ b/nock-aws/package.json @@ -1,6 +1,6 @@ { "name": "@cgauge/nock-aws", - "version": "0.10.2", + "version": "0.10.3", "description": "AWS Request mocker based on Nock", "repository": { "type": "git", diff --git a/type-guard/package.json b/type-guard/package.json index d761d12..548ccde 100644 --- a/type-guard/package.json +++ b/type-guard/package.json @@ -1,6 +1,6 @@ { "name": "@cgauge/type-guard", - "version": "0.10.2", + "version": "0.10.3", "description": "Typescript type guards", "repository": { "type": "git", diff --git a/yaml/package.json b/yaml/package.json index 53bd923..16a510d 100644 --- a/yaml/package.json +++ b/yaml/package.json @@ -1,6 +1,6 @@ { "name": "@cgauge/yaml", - "version": "0.10.2", + "version": "0.10.3", "description": "YAML parser with extra tags", "repository": { "type": "git",