diff --git a/assert/package.json b/assert/package.json index 9881959..3d79d00 100644 --- a/assert/package.json +++ b/assert/package.json @@ -1,6 +1,6 @@ { "name": "@cgauge/assert", - "version": "0.8.2", + "version": "0.9.0", "description": "Extra assert library", "type": "module", "repository": { diff --git a/dtc-aws-plugin/package.json b/dtc-aws-plugin/package.json index ee3cb51..fbb24a1 100644 --- a/dtc-aws-plugin/package.json +++ b/dtc-aws-plugin/package.json @@ -1,6 +1,6 @@ { "name": "@cgauge/dtc-aws-plugin", - "version": "0.8.2", + "version": "0.9.0", "description": "AWS plugin for Declarative TestCases", "repository": { "type": "git", @@ -21,9 +21,9 @@ "@aws-sdk/client-sns": "^3.645.0", "@aws-sdk/lib-dynamodb": "^3.645.0", "@aws-sdk/util-dynamodb": "^3.645.0", - "@cgauge/assert": "^0.8.0", - "@cgauge/dtc": "^0.8.0", - "@cgauge/nock-aws": "^0.8.0" + "@cgauge/assert": "^0.9.0", + "@cgauge/dtc": "^0.9.0", + "@cgauge/nock-aws": "^0.9.0" }, "scripts": { "build": "rm -rf dist && tsc", diff --git a/dtc-graphql-plugin/package.json b/dtc-graphql-plugin/package.json index 2055b95..f21f0a5 100644 --- a/dtc-graphql-plugin/package.json +++ b/dtc-graphql-plugin/package.json @@ -1,6 +1,6 @@ { "name": "@cgauge/dtc-graphql-plugin", - "version": "0.8.2", + "version": "0.9.0", "description": "GraphQl plugin for Declarative TestCases", "repository": { "type": "git", @@ -15,8 +15,8 @@ "author": "Salam Suleymanov", "license": "LGPL-3.0-or-later", "dependencies": { - "@cgauge/assert": "^0.8.0", - "@cgauge/dtc": "^0.8.0", + "@cgauge/assert": "^0.9.0", + "@cgauge/dtc": "^0.9.0", "graphql-request": "^7.1.2" }, "scripts": { diff --git a/dtc-mysql-plugin/package.json b/dtc-mysql-plugin/package.json index b846328..193ba8b 100644 --- a/dtc-mysql-plugin/package.json +++ b/dtc-mysql-plugin/package.json @@ -1,6 +1,6 @@ { "name": "@cgauge/dtc-mysql-plugin", - "version": "0.8.2", + "version": "0.9.0", "description": "MySQL plugin for Declarative TestCases", "repository": { "type": "git", @@ -15,8 +15,8 @@ "author": "Abdala Cerqueira", "license": "LGPL-3.0-or-later", "dependencies": { - "@cgauge/assert": "^0.8.0", - "@cgauge/dtc": "^0.8.0", + "@cgauge/assert": "^0.9.0", + "@cgauge/dtc": "^0.9.0", "mysql2": "^3.11.0", "node-sql-parser": "^5.1.0" }, diff --git a/dtc-playwright-plugin/package.json b/dtc-playwright-plugin/package.json index 9fe29b0..f115d14 100644 --- a/dtc-playwright-plugin/package.json +++ b/dtc-playwright-plugin/package.json @@ -1,6 +1,6 @@ { "name": "@cgauge/dtc-playwright-plugin", - "version": "0.8.2", + "version": "0.9.0", "description": "Playwright plugin for Declarative TestCases", "repository": { "type": "git", @@ -15,8 +15,8 @@ "author": "Abdala Cerqueira", "license": "LGPL-3.0-or-later", "dependencies": { - "@cgauge/assert": "^0.8.0", - "@cgauge/dtc": "^0.8.0", + "@cgauge/assert": "^0.9.0", + "@cgauge/dtc": "^0.9.0", "@playwright/test": "^1.47.0" }, "scripts": { diff --git a/dtc/package.json b/dtc/package.json index d8bc571..a6cb75e 100644 --- a/dtc/package.json +++ b/dtc/package.json @@ -1,6 +1,6 @@ { "name": "@cgauge/dtc", - "version": "0.8.2", + "version": "0.9.0", "description": "Declarative TestCases", "repository": { "type": "git", @@ -18,7 +18,7 @@ "author": "Abdala Cerqueira", "license": "LGPL-3.0-or-later", "dependencies": { - "@cgauge/assert": "^0.8.0", + "@cgauge/assert": "^0.9.0", "cleye": "^1.3.2", "nock": "^14.0.0-beta.15" }, diff --git a/dtc/src/domain.ts b/dtc/src/domain.ts index 7d16b02..7eb46cc 100644 --- a/dtc/src/domain.ts +++ b/dtc/src/domain.ts @@ -1,6 +1,11 @@ export type Loader = (filePath: string) => Promise -export type Runner = (testCases: TestCaseExecution[], plugins: string[], args?: string[], config?: string) => Promise +export type Runner = ( + testCases: TestCaseExecution[], + plugins: string[], + args?: string[], + config?: string, +) => Promise export type GenericAttributes = { [key: string]: string | number | boolean | Record | Record[] @@ -11,11 +16,14 @@ export type TestCase = GenericAttributes & { debug?: boolean retry?: number delay?: number - timeout?: number + timeout?: number parameters?: Record | Record[] arrange?: Record act?: Record - assert?: unknown + assert?: { + exception?: unknown + [x: string]: unknown + } clean?: Record } diff --git a/dtc/src/plugins/function-call-plugin.ts b/dtc/src/plugins/function-call-plugin.ts index 4b6d30b..09d26e1 100644 --- a/dtc/src/plugins/function-call-plugin.ts +++ b/dtc/src/plugins/function-call-plugin.ts @@ -1,5 +1,6 @@ import extraAssert from '@cgauge/assert' import {isRecord} from '../utils.js' +import nodeAssert from 'node:assert' type FunctionCallAct = { import: string @@ -10,6 +11,7 @@ type FunctionCallAct = { const isFunctionCallAct = (v: unknown): v is FunctionCallAct => typeof v === 'object' && v !== null && 'import' in v let response: any +let exception: any export const act = async (args: unknown, basePath: string) => { if (!isFunctionCallAct(args)) { @@ -24,10 +26,18 @@ export const act = async (args: unknown, basePath: string) => { } /* c8 ignore end */ - response = await module[args.import].apply(null, args.arguments) + try { + response = await module[args.import].apply(null, args.arguments) + } catch (e) { + exception = e + } } -export const assert = (args: unknown) => { +export const assert = (args: {exception?: {name?: string}; [x: string]: unknown}) => { + if (args.exception?.name) { + nodeAssert.equal(args?.exception?.name, exception.name) + } + if (response && isRecord(args) && args) { extraAssert.objectContains(response, args) } diff --git a/dtc/test/fixtures/functions.js b/dtc/test/fixtures/functions.js index b53df51..6dec059 100644 --- a/dtc/test/fixtures/functions.js +++ b/dtc/test/fixtures/functions.js @@ -3,3 +3,7 @@ export const noArgs = () => true export const syncFunction = (args) => args export const asyncFunction = async (args) => args + +export const functionWithException = (__args) => { + throw new Error() +} diff --git a/dtc/test/plugins/function-call-plugin.test.ts b/dtc/test/plugins/function-call-plugin.test.ts index 494a937..56ec65c 100644 --- a/dtc/test/plugins/function-call-plugin.test.ts +++ b/dtc/test/plugins/function-call-plugin.test.ts @@ -5,23 +5,17 @@ import {fileURLToPath} from 'node:url' const __dirname = dirname(fileURLToPath(import.meta.url)) -test('It call a sync function without args', async () => { - await act({ - import: 'noArgs', - from: '../fixtures/functions.js', - }, __dirname) - - assert(true) -}) - test('It call a sync function with args', async () => { const args = {a: 'b'} - await act({ - import: 'syncFunction', - from: '../fixtures/functions.js', - arguments: [args], - }, __dirname) + await act( + { + import: 'syncFunction', + from: '../fixtures/functions.js', + arguments: [args], + }, + __dirname, + ) assert(args) }) @@ -29,11 +23,29 @@ test('It call a sync function with args', async () => { test('It call a async function with args', async () => { const args = {a: 'b'} - await act({ - import: 'asyncFunction', - from: '../fixtures/functions.js', - arguments: [args], - }, __dirname) + await act( + { + import: 'asyncFunction', + from: '../fixtures/functions.js', + arguments: [args], + }, + __dirname, + ) + + assert(args) +}) + +test('It call a sync function with exception', async () => { + const args = {exception: {name: 'Error'}} + + await act( + { + import: 'functionWithException', + from: '../fixtures/functions.js', + arguments: [args], + }, + __dirname, + ) assert(args) }) diff --git a/nock-aws/package.json b/nock-aws/package.json index 357d503..f24d3fb 100644 --- a/nock-aws/package.json +++ b/nock-aws/package.json @@ -1,6 +1,6 @@ { "name": "@cgauge/nock-aws", - "version": "0.8.2", + "version": "0.9.0", "description": "AWS Request mocker based on Nock", "repository": { "type": "git", diff --git a/package-lock.json b/package-lock.json index 667aeb1..f25f447 100644 --- a/package-lock.json +++ b/package-lock.json @@ -24,15 +24,15 @@ }, "assert": { "name": "@cgauge/assert", - "version": "0.8.2", + "version": "0.9.0", "license": "LGPL-3.0-or-later" }, "dtc": { "name": "@cgauge/dtc", - "version": "0.8.2", + "version": "0.9.0", "license": "LGPL-3.0-or-later", "dependencies": { - "@cgauge/assert": "^0.8.0", + "@cgauge/assert": "^0.9.0", "cleye": "^1.3.2", "nock": "^14.0.0-beta.15" }, @@ -42,7 +42,7 @@ }, "dtc-aws-plugin": { "name": "@cgauge/dtc-aws-plugin", - "version": "0.8.2", + "version": "0.9.0", "license": "LGPL-3.0-or-later", "dependencies": { "@aws-sdk/client-dynamodb": "^3.645.0", @@ -51,45 +51,45 @@ "@aws-sdk/client-sns": "^3.645.0", "@aws-sdk/lib-dynamodb": "^3.645.0", "@aws-sdk/util-dynamodb": "^3.645.0", - "@cgauge/assert": "^0.8.0", - "@cgauge/dtc": "^0.8.0", - "@cgauge/nock-aws": "^0.8.0" + "@cgauge/assert": "^0.9.0", + "@cgauge/dtc": "^0.9.0", + "@cgauge/nock-aws": "^0.9.0" } }, "dtc-graphql-plugin": { "name": "@cgauge/dtc-graphql-plugin", - "version": "0.8.2", + "version": "0.9.0", "license": "LGPL-3.0-or-later", "dependencies": { - "@cgauge/assert": "^0.8.0", - "@cgauge/dtc": "^0.8.0", + "@cgauge/assert": "^0.9.0", + "@cgauge/dtc": "^0.9.0", "graphql-request": "^7.1.2" } }, "dtc-mysql-plugin": { "name": "@cgauge/dtc-mysql-plugin", - "version": "0.8.2", + "version": "0.9.0", "license": "LGPL-3.0-or-later", "dependencies": { - "@cgauge/assert": "^0.8.0", - "@cgauge/dtc": "^0.8.0", + "@cgauge/assert": "^0.9.0", + "@cgauge/dtc": "^0.9.0", "mysql2": "^3.11.0", "node-sql-parser": "^5.1.0" } }, "dtc-playwright-plugin": { "name": "@cgauge/dtc-playwright-plugin", - "version": "0.8.2", + "version": "0.9.0", "license": "LGPL-3.0-or-later", "dependencies": { - "@cgauge/assert": "^0.8.0", - "@cgauge/dtc": "^0.8.0", + "@cgauge/assert": "^0.9.0", + "@cgauge/dtc": "^0.9.0", "@playwright/test": "^1.47.0" } }, "nock-aws": { "name": "@cgauge/nock-aws", - "version": "0.8.2", + "version": "0.9.0", "license": "LGPL-3.0-or-later", "dependencies": { "nock": "^14.0.0-beta.15" @@ -2836,7 +2836,7 @@ }, "yaml": { "name": "@cgauge/yaml", - "version": "0.8.2", + "version": "0.9.0", "license": "LGPL-3.0-or-later", "dependencies": { "js-yaml": "^4.1.0" diff --git a/yaml/package.json b/yaml/package.json index a939784..1893ee1 100644 --- a/yaml/package.json +++ b/yaml/package.json @@ -1,6 +1,6 @@ { "name": "@cgauge/yaml", - "version": "0.8.2", + "version": "0.9.0", "description": "YAML parser with extra tags", "repository": { "type": "git",