From 4f81d78646d6879ee564c49ae872c08958779971 Mon Sep 17 00:00:00 2001 From: Serban Ghita Date: Sat, 9 Dec 2023 23:03:50 +0200 Subject: [PATCH] Return of invalid form data is undefined Included back the test files into tsconfig Changed build/ paths. --- .github/workflows/test.yml | 2 +- build/{ => src}/FormToObject.d.ts | 4 ++-- build/{ => src}/dom.d.ts | 0 build/{ => src}/index.d.ts | 0 build/{ => src}/types.d.ts | 0 build/{ => src}/utils.d.ts | 0 build/test/e2e/smoke.test.d.ts | 1 + build/test/helpers.d.ts | 7 +++++++ build/test/integration/checkbox.test.d.ts | 1 + build/test/integration/complexForms.test.d.ts | 1 + build/test/integration/exceptions.test.d.ts | 1 + build/test/integration/input.test.d.ts | 1 + build/test/integration/radio.test.d.ts | 1 + build/test/integration/select.test.d.ts | 1 + build/test/integration/textarea.test.d.ts | 1 + build/test/integration/unexpected.test.d.ts | 1 + .../unit/checkForLastNumericKey.test.d.ts | 1 + build/test/unit/extend.test.d.ts | 1 + build/test/unit/getLastIntegerKey.test.d.ts | 1 + build/test/unit/getNextIntegerKey.test.d.ts | 1 + build/test/unit/getObjLength.test.d.ts | 1 + build/test/unit/isDomElementNode.test.d.ts | 1 + package-lock.json | 3 +-- package.json | 7 +++---- test/integration/exceptions.test.ts | 20 +++++++++---------- tsconfig.json | 5 ++++- 26 files changed, 43 insertions(+), 20 deletions(-) rename build/{ => src}/FormToObject.d.ts (90%) rename build/{ => src}/dom.d.ts (100%) rename build/{ => src}/index.d.ts (100%) rename build/{ => src}/types.d.ts (100%) rename build/{ => src}/utils.d.ts (100%) create mode 100644 build/test/e2e/smoke.test.d.ts create mode 100644 build/test/helpers.d.ts create mode 100644 build/test/integration/checkbox.test.d.ts create mode 100644 build/test/integration/complexForms.test.d.ts create mode 100644 build/test/integration/exceptions.test.d.ts create mode 100644 build/test/integration/input.test.d.ts create mode 100644 build/test/integration/radio.test.d.ts create mode 100644 build/test/integration/select.test.d.ts create mode 100644 build/test/integration/textarea.test.d.ts create mode 100644 build/test/integration/unexpected.test.d.ts create mode 100644 build/test/unit/checkForLastNumericKey.test.d.ts create mode 100644 build/test/unit/extend.test.d.ts create mode 100644 build/test/unit/getLastIntegerKey.test.d.ts create mode 100644 build/test/unit/getNextIntegerKey.test.d.ts create mode 100644 build/test/unit/getObjLength.test.d.ts create mode 100644 build/test/unit/isDomElementNode.test.d.ts diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index dd560c7..b341b6d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -28,7 +28,7 @@ jobs: cache: 'npm' - run: npm ci - run: npm run build - - run: npm run test:unit-and-acceptance + - run: npm run test - run: npm run test:e2e - name: Upload coverage reports to Codecov diff --git a/build/FormToObject.d.ts b/build/src/FormToObject.d.ts similarity index 90% rename from build/FormToObject.d.ts rename to build/src/FormToObject.d.ts index ba9b494..33d86e2 100644 --- a/build/FormToObject.d.ts +++ b/build/src/FormToObject.d.ts @@ -17,8 +17,8 @@ export declare class FormToObject { initForm(): boolean; initFormElements(): boolean; convertToObj(): any; - getNodeValues($domNode: HTMLFormField): string | false | FileList | string[] | null; - processSingleLevelNode($domNode: HTMLFormField, arr: Array, domNodeValue: string | number | boolean | FileList | string[], result: Record): string | number | boolean | FileList | string[] | undefined; + getNodeValues($domNode: HTMLFormField): string | false | string[] | FileList | null; + processSingleLevelNode($domNode: HTMLFormField, arr: Array, domNodeValue: string | number | boolean | FileList | string[], result: Record): string | number | boolean | string[] | FileList | undefined; processMultiLevelNode($domNode: HTMLFormField, arr: Array, value: string | number | boolean | FileList | string[], result: NodeResult): void; formElementHasSiblings($domNode: HTMLFormField): boolean; } diff --git a/build/dom.d.ts b/build/src/dom.d.ts similarity index 100% rename from build/dom.d.ts rename to build/src/dom.d.ts diff --git a/build/index.d.ts b/build/src/index.d.ts similarity index 100% rename from build/index.d.ts rename to build/src/index.d.ts diff --git a/build/types.d.ts b/build/src/types.d.ts similarity index 100% rename from build/types.d.ts rename to build/src/types.d.ts diff --git a/build/utils.d.ts b/build/src/utils.d.ts similarity index 100% rename from build/utils.d.ts rename to build/src/utils.d.ts diff --git a/build/test/e2e/smoke.test.d.ts b/build/test/e2e/smoke.test.d.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/build/test/e2e/smoke.test.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/build/test/helpers.d.ts b/build/test/helpers.d.ts new file mode 100644 index 0000000..f8b2330 --- /dev/null +++ b/build/test/helpers.d.ts @@ -0,0 +1,7 @@ +import { expect } from '@jest/globals'; +import { TestingLibraryMatchers } from '@testing-library/jest-dom/matchers'; +export declare function readIntegrationFixture(relativePath: string): string; +declare module 'expect' { + interface Matchers extends TestingLibraryMatchers { + } +} diff --git a/build/test/integration/checkbox.test.d.ts b/build/test/integration/checkbox.test.d.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/build/test/integration/checkbox.test.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/build/test/integration/complexForms.test.d.ts b/build/test/integration/complexForms.test.d.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/build/test/integration/complexForms.test.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/build/test/integration/exceptions.test.d.ts b/build/test/integration/exceptions.test.d.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/build/test/integration/exceptions.test.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/build/test/integration/input.test.d.ts b/build/test/integration/input.test.d.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/build/test/integration/input.test.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/build/test/integration/radio.test.d.ts b/build/test/integration/radio.test.d.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/build/test/integration/radio.test.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/build/test/integration/select.test.d.ts b/build/test/integration/select.test.d.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/build/test/integration/select.test.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/build/test/integration/textarea.test.d.ts b/build/test/integration/textarea.test.d.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/build/test/integration/textarea.test.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/build/test/integration/unexpected.test.d.ts b/build/test/integration/unexpected.test.d.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/build/test/integration/unexpected.test.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/build/test/unit/checkForLastNumericKey.test.d.ts b/build/test/unit/checkForLastNumericKey.test.d.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/build/test/unit/checkForLastNumericKey.test.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/build/test/unit/extend.test.d.ts b/build/test/unit/extend.test.d.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/build/test/unit/extend.test.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/build/test/unit/getLastIntegerKey.test.d.ts b/build/test/unit/getLastIntegerKey.test.d.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/build/test/unit/getLastIntegerKey.test.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/build/test/unit/getNextIntegerKey.test.d.ts b/build/test/unit/getNextIntegerKey.test.d.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/build/test/unit/getNextIntegerKey.test.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/build/test/unit/getObjLength.test.d.ts b/build/test/unit/getObjLength.test.d.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/build/test/unit/getObjLength.test.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/build/test/unit/isDomElementNode.test.d.ts b/build/test/unit/isDomElementNode.test.d.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/build/test/unit/isDomElementNode.test.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/package-lock.json b/package-lock.json index 0da5ae0..d2073b4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -34,8 +34,7 @@ "typescript": "^5.2.2", "wdio-wait-for": "^3.0.7", "webpack": "^5.74.0", - "webpack-cli": "^4.10.0", - "webpack-merge": "^5.10.0" + "webpack-cli": "^4.10.0" } }, "node_modules/@aashutoshrathi/word-wrap": { diff --git a/package.json b/package.json index 5184be5..e4c849c 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "homepage": "https://github.com/serbanghita/formToObject", "author": "Serban Ghita ", "main": "build/bundle/formToObject.min.js", - "types": "build/index.d.ts", + "types": "build/src/index.d.ts", "sideEffects": false, "repository": { "type": "git", @@ -26,7 +26,7 @@ "scripts": { "build": "webpack --mode production", "dev": "webpack --mode development -d inline-source-map --watch", - "test:unit-and-acceptance": "jest", + "test": "jest", "test:e2e": "wdio run ./wdio.conf.ts" }, "devDependencies": { @@ -55,7 +55,6 @@ "typescript": "^5.2.2", "wdio-wait-for": "^3.0.7", "webpack": "^5.74.0", - "webpack-cli": "^4.10.0", - "webpack-merge": "^5.10.0" + "webpack-cli": "^4.10.0" } } diff --git a/test/integration/exceptions.test.ts b/test/integration/exceptions.test.ts index 94a53a6..07ad0c9 100644 --- a/test/integration/exceptions.test.ts +++ b/test/integration/exceptions.test.ts @@ -4,33 +4,33 @@ import {readIntegrationFixture} from "../helpers"; describe('exceptions', () => { describe('An invalid or non existing selector', () => { - test('should return false if null is passed as argument', () => { + test('should return undefined if null is passed as argument', () => { // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore - expect(formToObject(null)).toBe(false); + expect(formToObject(null)).toBeUndefined(); }); - test('should return false if an empty string is passed as argument', () => { - expect(formToObject('')).toBe(false); + test('should return undefined if an empty string is passed as argument', () => { + expect(formToObject('')).toBeUndefined(); }); - test('should return false if undefined object is passed', () => { + test('should return undefined if undefined object is passed', () => { // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore - expect(formToObject(undefined)).toBe(false); + expect(formToObject(undefined)).toBeUndefined(); }); - test('should return false if the argument passed is invalid', () => { - expect(formToObject('newFormUndefined')).toBe(false); + test('should return undefined if the argument passed is invalid', () => { + expect(formToObject('newFormUndefined')).toBeUndefined(); }); }); describe('An empty HTML form', () => { - test('should return false if the form has no elements', () => { + test('should return undefined if the form has no elements', () => { document.body.innerHTML = readIntegrationFixture("other/exceptions/empty-form.html"); const $form = screen.queryByTestId('testForm') as HTMLFormElement; - expect(formToObject($form)).toBe(false); + expect(formToObject($form)).toBeUndefined(); }); }); }); diff --git a/tsconfig.json b/tsconfig.json index 835b844..36ec14d 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -15,7 +15,10 @@ "types": ["node", "jest", "mocha", "@testing-library/jest-dom"] }, "include": [ - "src/index.ts" + "src/index.ts", + "test/unit/*", + "test/integration/*", + "test/e2e/*" ], "exclude": [ "node_modules",