From e5b0a2613e72f1910c767c3e861d6bead30f8ca2 Mon Sep 17 00:00:00 2001 From: Arve Knudsen Date: Sat, 8 Apr 2023 14:03:07 +0200 Subject: [PATCH] Rewrite tests in TypeScript Signed-off-by: Arve Knudsen --- .mocharc.json | 5 + package-lock.json | 155 ++++++++++++++++++ package.json | 2 + test/{boolattrs.js => boolattrs.ts} | 4 +- ...-react-tests.js => html-to-react-tests.ts} | 101 ++++++------ tsconfig.json | 11 ++ 6 files changed, 224 insertions(+), 54 deletions(-) create mode 100644 .mocharc.json rename test/{boolattrs.js => boolattrs.ts} (90%) rename test/{html-to-react-tests.js => html-to-react-tests.ts} (88%) create mode 100644 tsconfig.json diff --git a/.mocharc.json b/.mocharc.json new file mode 100644 index 0000000..cabd44f --- /dev/null +++ b/.mocharc.json @@ -0,0 +1,5 @@ +{ + "extension": ["ts"], + "spec": "test/**/*-tests.ts", + "require": "ts-node/register" +} diff --git a/package-lock.json b/package-lock.json index 64eab0a..38dca00 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15,12 +15,14 @@ "react": "^18.0" }, "devDependencies": { + "@types/mocha": "^10.0.1", "coveralls": "^3.1.0", "eslint": "^8.1", "mocha": "^10.0", "mocha-lcov-reporter": "^1.2.0", "nyc": "^15.1.0", "react-dom": "^18.0", + "ts-node": "^10.9.1", "typescript": "^5.0.3" } }, @@ -407,6 +409,28 @@ "node": ">=6.9.0" } }, + "node_modules/@cspotcode/source-map-support": { + "version": "0.8.1", + "resolved": "https://registry.npmjs.org/@cspotcode/source-map-support/-/source-map-support-0.8.1.tgz", + "integrity": "sha512-IchNf6dN4tHoMFIn/7OE8LWZ19Y6q/67Bmf6vnGREv8RSbBVb9LPJxEcnwrcwX6ixSvaiGoomAUvu4YSxXrVgw==", + "dev": true, + "dependencies": { + "@jridgewell/trace-mapping": "0.3.9" + }, + "engines": { + "node": ">=12" + } + }, + "node_modules/@cspotcode/source-map-support/node_modules/@jridgewell/trace-mapping": { + "version": "0.3.9", + "resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.9.tgz", + "integrity": "sha512-3Belt6tdc8bPgAtbcmdtNJlirVoTmEb5e2gC94PnkwEW9jI6CAHUeoG85tjWP5WquqfavoMtMwiG4P926ZKKuQ==", + "dev": true, + "dependencies": { + "@jridgewell/resolve-uri": "^3.0.3", + "@jridgewell/sourcemap-codec": "^1.4.10" + } + }, "node_modules/@eslint-community/eslint-utils": { "version": "4.4.0", "resolved": "https://registry.npmjs.org/@eslint-community/eslint-utils/-/eslint-utils-4.4.0.tgz", @@ -689,6 +713,43 @@ "node": ">= 8" } }, + "node_modules/@tsconfig/node10": { + "version": "1.0.9", + "resolved": "https://registry.npmjs.org/@tsconfig/node10/-/node10-1.0.9.tgz", + "integrity": "sha512-jNsYVVxU8v5g43Erja32laIDHXeoNvFEpX33OK4d6hljo3jDhCBDhx5dhCCTMWUojscpAagGiRkBKxpdl9fxqA==", + "dev": true + }, + "node_modules/@tsconfig/node12": { + "version": "1.0.11", + "resolved": "https://registry.npmjs.org/@tsconfig/node12/-/node12-1.0.11.tgz", + "integrity": "sha512-cqefuRsh12pWyGsIoBKJA9luFu3mRxCA+ORZvA4ktLSzIuCUtWVxGIuXigEwO5/ywWFMZ2QEGKWvkZG1zDMTag==", + "dev": true + }, + "node_modules/@tsconfig/node14": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/@tsconfig/node14/-/node14-1.0.3.tgz", + "integrity": "sha512-ysT8mhdixWK6Hw3i1V2AeRqZ5WfXg1G43mqoYlM2nc6388Fq5jcXyr5mRsqViLx/GJYdoL0bfXD8nmF+Zn/Iow==", + "dev": true + }, + "node_modules/@tsconfig/node16": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/@tsconfig/node16/-/node16-1.0.3.tgz", + "integrity": "sha512-yOlFc+7UtL/89t2ZhjPvvB/DeAr3r+Dq58IgzsFkOAvVC6NMJXmCGjbptdXdR9qsX7pKcTL+s87FtYREi2dEEQ==", + "dev": true + }, + "node_modules/@types/mocha": { + "version": "10.0.1", + "resolved": "https://registry.npmjs.org/@types/mocha/-/mocha-10.0.1.tgz", + "integrity": "sha512-/fvYntiO1GeICvqbQ3doGDIP97vWmvFt83GKguJ6prmQM2iXZfFcq6YE8KteFyRtX2/h5Hf91BYvPodJKFYv5Q==", + "dev": true + }, + "node_modules/@types/node": { + "version": "18.15.11", + "resolved": "https://registry.npmjs.org/@types/node/-/node-18.15.11.tgz", + "integrity": "sha512-E5Kwq2n4SbMzQOn6wnmBjuK9ouqlURrcZDVfbo9ftDDTFt3nk7ZKK4GMOzoYgnpQJKcxwQw+lGaBvvlMo0qN/Q==", + "dev": true, + "peer": true + }, "node_modules/acorn": { "version": "8.8.2", "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.8.2.tgz", @@ -710,6 +771,15 @@ "acorn": "^6.0.0 || ^7.0.0 || ^8.0.0" } }, + "node_modules/acorn-walk": { + "version": "8.2.0", + "resolved": "https://registry.npmjs.org/acorn-walk/-/acorn-walk-8.2.0.tgz", + "integrity": "sha512-k+iyHEuPgSw6SbuDpGQM+06HQUa04DZ3o+F6CSzXMvvI5KMvnaEqXe+YVe555R9nn6GPt404fos4wcgpw12SDA==", + "dev": true, + "engines": { + "node": ">=0.4.0" + } + }, "node_modules/aggregate-error": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/aggregate-error/-/aggregate-error-3.1.0.tgz", @@ -803,6 +873,12 @@ "integrity": "sha512-Xg+9RwCg/0p32teKdGMPTPnVXKD0w3DfHnFTficozsAgsvq2XenPJq/MYpzzQ/v8zrOyJn6Ds39VA4JIDwFfqw==", "dev": true }, + "node_modules/arg": { + "version": "4.1.3", + "resolved": "https://registry.npmjs.org/arg/-/arg-4.1.3.tgz", + "integrity": "sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==", + "dev": true + }, "node_modules/argparse": { "version": "1.0.10", "resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.10.tgz", @@ -1138,6 +1214,12 @@ "node": ">=6" } }, + "node_modules/create-require": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/create-require/-/create-require-1.1.1.tgz", + "integrity": "sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==", + "dev": true + }, "node_modules/cross-spawn": { "version": "7.0.3", "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz", @@ -2411,6 +2493,12 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/make-error": { + "version": "1.3.6", + "resolved": "https://registry.npmjs.org/make-error/-/make-error-1.3.6.tgz", + "integrity": "sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==", + "dev": true + }, "node_modules/mime-db": { "version": "1.52.0", "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", @@ -3501,6 +3589,58 @@ "node": ">=0.8" } }, + "node_modules/ts-node": { + "version": "10.9.1", + "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-10.9.1.tgz", + "integrity": "sha512-NtVysVPkxxrwFGUUxGYhfux8k78pQB3JqYBXlLRZgdGUqTO5wU/UyHop5p70iEbGhB7q5KmiZiU0Y3KlJrScEw==", + "dev": true, + "dependencies": { + "@cspotcode/source-map-support": "^0.8.0", + "@tsconfig/node10": "^1.0.7", + "@tsconfig/node12": "^1.0.7", + "@tsconfig/node14": "^1.0.0", + "@tsconfig/node16": "^1.0.2", + "acorn": "^8.4.1", + "acorn-walk": "^8.1.1", + "arg": "^4.1.0", + "create-require": "^1.1.0", + "diff": "^4.0.1", + "make-error": "^1.1.1", + "v8-compile-cache-lib": "^3.0.1", + "yn": "3.1.1" + }, + "bin": { + "ts-node": "dist/bin.js", + "ts-node-cwd": "dist/bin-cwd.js", + "ts-node-esm": "dist/bin-esm.js", + "ts-node-script": "dist/bin-script.js", + "ts-node-transpile-only": "dist/bin-transpile.js", + "ts-script": "dist/bin-script-deprecated.js" + }, + "peerDependencies": { + "@swc/core": ">=1.2.50", + "@swc/wasm": ">=1.2.50", + "@types/node": "*", + "typescript": ">=2.7" + }, + "peerDependenciesMeta": { + "@swc/core": { + "optional": true + }, + "@swc/wasm": { + "optional": true + } + } + }, + "node_modules/ts-node/node_modules/diff": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/diff/-/diff-4.0.2.tgz", + "integrity": "sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==", + "dev": true, + "engines": { + "node": ">=0.3.1" + } + }, "node_modules/tunnel-agent": { "version": "0.6.0", "resolved": "https://registry.npmjs.org/tunnel-agent/-/tunnel-agent-0.6.0.tgz", @@ -3609,6 +3749,12 @@ "uuid": "dist/bin/uuid" } }, + "node_modules/v8-compile-cache-lib": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/v8-compile-cache-lib/-/v8-compile-cache-lib-3.0.1.tgz", + "integrity": "sha512-wa7YjyUGfNZngI/vtK0UHAN+lgDCxBPCylVXGp0zu59Fz5aiGtNXaq3DhIov063MorB+VfufLh3JlF2KdTK3xg==", + "dev": true + }, "node_modules/verror": { "version": "1.10.0", "resolved": "https://registry.npmjs.org/verror/-/verror-1.10.0.tgz", @@ -3775,6 +3921,15 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/yn": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/yn/-/yn-3.1.1.tgz", + "integrity": "sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q==", + "dev": true, + "engines": { + "node": ">=6" + } + }, "node_modules/yocto-queue": { "version": "0.1.0", "resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz", diff --git a/package.json b/package.json index b6b9456..2711baa 100644 --- a/package.json +++ b/package.json @@ -42,12 +42,14 @@ "react": "^18.0" }, "devDependencies": { + "@types/mocha": "^10.0.1", "coveralls": "^3.1.0", "eslint": "^8.1", "mocha": "^10.0", "mocha-lcov-reporter": "^1.2.0", "nyc": "^15.1.0", "react-dom": "^18.0", + "ts-node": "^10.9.1", "typescript": "^5.0.3" }, "volta": { diff --git a/test/boolattrs.js b/test/boolattrs.ts similarity index 90% rename from test/boolattrs.js rename to test/boolattrs.ts index bffa847..4dd6b6f 100644 --- a/test/boolattrs.js +++ b/test/boolattrs.ts @@ -1,5 +1,3 @@ -'use strict'; - // Boolean HTML attributes, in the case React expects. const booleanAttrs = [ 'allowFullScreen', @@ -29,4 +27,4 @@ const booleanAttrs = [ 'truespeed', ]; -module.exports = booleanAttrs; +export {booleanAttrs}; diff --git a/test/html-to-react-tests.js b/test/html-to-react-tests.ts similarity index 88% rename from test/html-to-react-tests.js rename to test/html-to-react-tests.ts index e452e1e..65873ca 100644 --- a/test/html-to-react-tests.js +++ b/test/html-to-react-tests.ts @@ -1,11 +1,10 @@ -'use strict'; -const assert = require('assert'); -const React = require('react'); -const ReactDOMServer = require('react-dom/server'); +import {equal, strictEqual, deepStrictEqual, ok} from 'assert'; +import * as React from 'react'; +import * as ReactDOMServer from 'react-dom/server'; -const Parser = require('..').Parser; -const ProcessNodeDefinitions = require('..').ProcessNodeDefinitions; -const booleanAttrs = require('./boolattrs'); +import {Parser} from '..'; +import {ProcessNodeDefinitions} from '..'; +import {booleanAttrs} from './boolattrs'; describe('Html2React', () => { const parser = new Parser(); @@ -17,7 +16,7 @@ describe('Html2React', () => { const reactComponent = parser.parse(htmlInput); const reactHtml = ReactDOMServer.renderToStaticMarkup(reactComponent); - assert.equal(reactHtml, htmlInput); + equal(reactHtml, htmlInput); }); it('should return a valid HTML string with nested elements', () => { @@ -26,7 +25,7 @@ describe('Html2React', () => { const reactComponent = parser.parse(htmlInput); const reactHtml = ReactDOMServer.renderToStaticMarkup(reactComponent); - assert.equal(reactHtml, htmlInput); + equal(reactHtml, htmlInput); }); it('should return a valid HTML string with inline styles', () => { @@ -37,7 +36,7 @@ describe('Html2React', () => { const reactComponent = parser.parse(htmlInput); const reactHtml = ReactDOMServer.renderToStaticMarkup(reactComponent); - assert.equal(reactHtml, htmlInput); + equal(reactHtml, htmlInput); }); it('should return a valid HTML string with inline image in style', () => { @@ -48,7 +47,7 @@ describe('Html2React', () => { const reactComponent = parser.parse(htmlInput); const reactHtml = ReactDOMServer.renderToStaticMarkup(reactComponent); - assert.equal(reactHtml, htmlInput); + equal(reactHtml, htmlInput); }); it('should return a valid HTML string with empty inline styles', () => { @@ -58,7 +57,7 @@ describe('Html2React', () => { const reactComponent = parser.parse(htmlInput); const reactHtml = ReactDOMServer.renderToStaticMarkup(reactComponent); - assert.equal(reactHtml, htmlExpected); + equal(reactHtml, htmlExpected); }); it('should return a valid HTML string with custom properties in inline styles', () => { @@ -67,7 +66,7 @@ describe('Html2React', () => { const reactComponent = parser.parse(htmlInput); const reactHtml = ReactDOMServer.renderToStaticMarkup(reactComponent); - assert.equal(reactHtml, htmlInput); + equal(reactHtml, htmlInput); }); it('should return a valid HTML string with data attributes', () => { @@ -76,7 +75,7 @@ describe('Html2React', () => { const reactComponent = parser.parse(htmlInput); const reactHtml = ReactDOMServer.renderToStaticMarkup(reactComponent); - assert.equal(reactHtml, htmlInput); + equal(reactHtml, htmlInput); }); it('should return a valid HTML string with aria attributes', () => { @@ -85,7 +84,7 @@ describe('Html2React', () => { const reactComponent = parser.parse(htmlInput); const reactHtml = ReactDOMServer.renderToStaticMarkup(reactComponent); - assert.equal(reactHtml, htmlInput); + equal(reactHtml, htmlInput); }); it('should return a valid HTML string with a class attribute', () => { @@ -94,7 +93,7 @@ describe('Html2React', () => { const reactComponent = parser.parse(htmlInput); const reactHtml = ReactDOMServer.renderToStaticMarkup(reactComponent); - assert.equal(reactHtml, htmlInput); + equal(reactHtml, htmlInput); }); it('should return a valid HTML string with a for attribute', () => { @@ -103,7 +102,7 @@ describe('Html2React', () => { const reactComponent = parser.parse(htmlInput); const reactHtml = ReactDOMServer.renderToStaticMarkup(reactComponent); - assert.equal(reactHtml, htmlInput); + equal(reactHtml, htmlInput); }); it('should return a valid HTML string with a react camelCase attribute', () => { @@ -112,7 +111,7 @@ describe('Html2React', () => { const reactComponent = parser.parse(htmlInput); const reactHtml = ReactDOMServer.renderToStaticMarkup(reactComponent); - assert.equal(reactHtml, htmlInput); + equal(reactHtml, htmlInput); }); it('should handle dashed attributes', () => { @@ -121,7 +120,7 @@ describe('Html2React', () => { const reactComponent = parser.parse(input); const reactHtml = ReactDOMServer.renderToStaticMarkup(reactComponent); - assert.equal(reactHtml, input); + equal(reactHtml, input); }); // FIXME: See lib/process-node-definitions.js -> processDefaultNode() @@ -131,7 +130,7 @@ describe('Html2React', () => { const reactComponent = parser.parse(htmlInput); const reactHtml = ReactDOMServer.renderToStaticMarkup(reactComponent); - assert.equal(reactHtml, htmlInput); + equal(reactHtml, htmlInput); }); // FIXME: If / when React implements HTML comments, this test can be removed @@ -142,7 +141,7 @@ describe('Html2React', () => { const reactComponent = parser.parse(htmlInput); const reactHtml = ReactDOMServer.renderToStaticMarkup(reactComponent); - assert.equal(reactHtml, htmlExpected); + equal(reactHtml, htmlExpected); }); it('should parse br elements without warnings', () => { @@ -152,14 +151,14 @@ describe('Html2React', () => { const reactComponent = parser.parse(htmlInput); const reactHtml = ReactDOMServer.renderToStaticMarkup(reactComponent); - assert.equal(reactHtml, htmlExpected); + equal(reactHtml, htmlExpected); }); it('should not generate children for br tags', () => { const htmlInput = '
'; const reactComponent = parser.parse(htmlInput); - assert.strictEqual((reactComponent.props.children || []).length, 0); + strictEqual((reactComponent.props.children || []).length, 0); }); it('should parse void elements with all attributes and no warnings', () => { @@ -168,7 +167,7 @@ describe('Html2React', () => { const reactComponent = parser.parse(htmlInput); const reactHtml = ReactDOMServer.renderToStaticMarkup(reactComponent); - assert.equal(reactHtml, htmlInput); + equal(reactHtml, htmlInput); }); // Covers issue #9 @@ -178,7 +177,7 @@ describe('Html2React', () => { const reactComponent = parser.parse(htmlInput); const reactHtml = ReactDOMServer.renderToStaticMarkup(reactComponent); - assert.equal(reactHtml, htmlInput); + equal(reactHtml, htmlInput); }); it('should generate keys for sequence items', () => { @@ -192,7 +191,7 @@ describe('Html2React', () => { const keys = children.map((child) => { return child.key; }); - assert.deepStrictEqual(keys, ['0', '1', ]); + deepStrictEqual(keys, ['0', '1', ]); }); it('should parse br elements without warnings', () => { @@ -202,7 +201,7 @@ describe('Html2React', () => { const reactComponent = parser.parse(htmlInput); const reactHtml = ReactDOMServer.renderToStaticMarkup(reactComponent); - assert.equal(reactHtml, htmlExpected); + equal(reactHtml, htmlExpected); }); it('should parse src elements with all attributes but without warnings', () => { @@ -211,7 +210,7 @@ describe('Html2React', () => { const reactComponent = parser.parse(htmlInput); const reactHtml = ReactDOMServer.renderToStaticMarkup(reactComponent); - assert.equal(reactHtml, htmlInput); + equal(reactHtml, htmlInput); }); it('should decode character entities in text nodes', () => { @@ -220,7 +219,7 @@ describe('Html2React', () => { const reactComponent = parser.parse(htmlInput); const reactHtml = ReactDOMServer.renderToStaticMarkup(reactComponent); - assert.equal(reactHtml, htmlInput); + equal(reactHtml, htmlInput); }); it('should not generate children for childless elements', () => { @@ -228,7 +227,7 @@ describe('Html2React', () => { const reactComponent = parser.parse(htmlInput); - assert.strictEqual((reactComponent.props.children || []).length, 0); + strictEqual((reactComponent.props.children || []).length, 0); }); it('should fill in the key name with boolean attribute', () => { @@ -238,7 +237,7 @@ describe('Html2React', () => { const reactComponent = parser.parse(htmlInput); const reactHtml = ReactDOMServer.renderToStaticMarkup(reactComponent); - assert.equal(reactHtml, htmlExpected); + equal(reactHtml, htmlExpected); }); it('should decode attribute values to avoid React re-encoding them', () => { @@ -247,7 +246,7 @@ describe('Html2React', () => { const reactComponent = parser.parse(htmlInput); const reactHtml = ReactDOMServer.renderToStaticMarkup(reactComponent); - assert.equal(reactHtml, htmlInput); + equal(reactHtml, htmlInput); }); it('should handle spaces in inline styles', () => { @@ -255,7 +254,7 @@ describe('Html2React', () => { const reactComponent = parser.parse(htmlInput); - assert.equal(reactComponent.props.style.textAlign, 'center'); + equal(reactComponent.props.style.textAlign, 'center'); }); it('should handle doctype directives', () => { @@ -265,7 +264,7 @@ describe('Html2React', () => { const reactComponent = parser.parse(htmlInput); const reactHtml = ReactDOMServer.renderToStaticMarkup(reactComponent); - assert.equal(reactHtml, '
'); + equal(reactHtml, '
'); }); it('should handle free text nodes', () => { @@ -274,7 +273,7 @@ describe('Html2React', () => { const reactComponent = parser.parse(htmlInput); const reactHtml = ReactDOMServer.renderToStaticMarkup(reactComponent); - assert.equal(reactHtml, 'text
text'); + equal(reactHtml, 'text
text'); }); it('should handle onclick attributes', function () { @@ -282,8 +281,8 @@ describe('Html2React', () => { const reactElem = parser.parse(htmlInput); - assert.strictEqual(typeof reactElem.props.onClick, 'function'); - assert.strictEqual(String(reactElem.props.onClick), String(Function(`alert('hello!')`))); + strictEqual(typeof reactElem.props.onClick, 'function'); + strictEqual(String(reactElem.props.onClick), String(Function(`alert('hello!')`))); }); it('should handle inputs with empty value attribute', function () { @@ -291,7 +290,7 @@ describe('Html2React', () => { const reactElem = parser.parse(htmlInput); - assert.strictEqual(reactElem.props.value, ''); + strictEqual(reactElem.props.value, ''); }); it('should handle boolean attributes with implicit value', function () { @@ -300,7 +299,7 @@ describe('Html2React', () => { const reactElem = parser.parse(htmlInput); - assert.strictEqual(reactElem.props[attr], attr); + strictEqual(reactElem.props[attr], attr); }); }); }); @@ -313,7 +312,7 @@ describe('Html2React', () => { const reactComponent = parser.parse(htmlInput); const reactHtml = ReactDOMServer.renderToStaticMarkup(reactComponent); - assert.equal(reactHtml, htmlExpected); + equal(reactHtml, htmlExpected); }); it('should handle invalid style tag', () => { @@ -323,7 +322,7 @@ describe('Html2React', () => { const reactComponent = parser.parse(htmlInput); const reactHtml = ReactDOMServer.renderToStaticMarkup(reactComponent); - assert.equal(reactHtml, htmlExpected); + equal(reactHtml, htmlExpected); }); }); @@ -347,7 +346,7 @@ describe('Html2React', () => { processingInstructions); // With only 1

element, nothing is rendered - assert.equal(reactComponent, false); + equal(reactComponent, false); }); it('should return a single

element within a div of

and

as siblings', @@ -368,7 +367,7 @@ describe('Html2React', () => { const reactComponent = parser.parseWithInstructions(htmlInput, isValidNode, processingInstructions); const reactHtml = ReactDOMServer.renderToStaticMarkup(reactComponent); - assert.equal(reactHtml, htmlExpected); + equal(reactHtml, htmlExpected); }); it('should replace the children of an element if configured so', () => { @@ -401,7 +400,7 @@ describe('Html2React', () => { const reactComponent = parser.parseWithInstructions(htmlInput, isValidNode, processingInstructions); const reactHtml = ReactDOMServer.renderToStaticMarkup(reactComponent); - assert.equal(reactHtml, htmlExpected); + equal(reactHtml, htmlExpected); }); it('should return capitalized content for all

elements', () => { @@ -435,7 +434,7 @@ describe('Html2React', () => { const reactComponent = parser.parseWithInstructions(htmlInput, isValidNode, processingInstructions); const reactHtml = ReactDOMServer.renderToStaticMarkup(reactComponent); - assert.equal(reactHtml, htmlExpected); + equal(reactHtml, htmlExpected); }); it('should return false in case of invalid node', () => { @@ -447,7 +446,7 @@ describe('Html2React', () => { const reactComponent = parser.parseWithInstructions(htmlInput, () => { return false; }, processingInstructions); - assert.equal(reactComponent, false); + equal(reactComponent, false); }); it('should generate only valid children', () => { @@ -465,7 +464,7 @@ describe('Html2React', () => { return true; }, processingInstructions); - assert.equal(reactComponent.props.children.length, 2); + equal(reactComponent.props.children.length, 2); }); it('should not affect unhandled whitespace', () => { @@ -473,7 +472,7 @@ describe('Html2React', () => { const reactComponent = parser.parse(htmlInput); - assert.equal(reactComponent.props.children.length, 5); + equal(reactComponent.props.children.length, 5); }); }); @@ -546,7 +545,7 @@ describe('Html2React', () => { processingInstructions, preprocessingInstructions); const reactHtml = ReactDOMServer.renderToStaticMarkup(reactComponent); - assert.strictEqual(reactHtml, htmlExpected); + strictEqual(reactHtml, htmlExpected); }); }); @@ -563,7 +562,7 @@ describe('Html2React', () => { const reactComponent = parser.parse(input); const reactHtml = ReactDOMServer.renderToStaticMarkup(reactComponent); - assert(regExp.test(reactHtml), reactHtml + ' has expected attributes'); + ok(regExp.test(reactHtml), reactHtml + ' has expected attributes'); }); }); }); @@ -573,7 +572,7 @@ describe('Html2React', () => { const htmlInput = '
'; const elements = parser.parse(htmlInput); const output = elements.map(ReactDOMServer.renderToStaticMarkup).join(''); - assert.equal(htmlInput, output); + equal(htmlInput, output); }); }); }); diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..95df7f6 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,11 @@ +{ + "include": ["lib/**/*"], + "compilerOptions": { + "allowJs": true, + // Generate d.ts files + "declaration": true, + "emitDeclarationOnly": true, + "outDir": "types", + "declarationMap": true + } +}