From 61d67602059038f8ecdb17568622fde78aa7849f Mon Sep 17 00:00:00 2001 From: Jason Creviston Date: Mon, 7 Oct 2024 07:28:56 -0400 Subject: [PATCH] build: add vitest and tests --- index.js | 80 -------------------- package.json | 7 +- src/tests/all.spec.js | 165 ++++++++++++++++++++++++++++++++++++++++++ tsconfig.json | 2 +- 4 files changed, 170 insertions(+), 84 deletions(-) delete mode 100644 index.js create mode 100644 src/tests/all.spec.js diff --git a/index.js b/index.js deleted file mode 100644 index e253bbd..0000000 --- a/index.js +++ /dev/null @@ -1,80 +0,0 @@ -/* Testing. */ -import { closify } from './src/closify' -import { entify } from './src/entify' -import { minify } from './src/minify' -import { prettify } from './src/prettify' - -const uhtml = `
-
- -
- -
-
` - -const ehtml = `` - -const phtml = `
- - - - - - -
- - -
-
- -
- - -
-
- - -
-
` - -const chtml = `
- -

` - -const prettified_html = prettify(uhtml) -const entified_html = entify(ehtml, true) -const minified_html = minify(phtml) -const closified_html = closify(chtml) -const plain_text = prettify('This should boomerang as-is.') - -console.log('All pretty:') -console.log(prettified_html, '\n') -console.log('With entities:') -console.log(entified_html, '\n') -console.log('All minified:') -console.log(minified_html, '\n') -console.log('With self-closing:') -console.log(closified_html, '\n') -console.log('Plain text:') -console.log(plain_text) diff --git a/package.json b/package.json index 118dbe1..670fe3c 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "HTML formatter yo!. Prettify, minify, and more!", "scripts": { "check": "tsc", - "test": "bun index.js" + "test": "vitest" }, "exports": { ".": { @@ -18,7 +18,8 @@ "types" ], "devDependencies": { - "typescript": "^5.0.0" + "typescript": "^5.0.0", + "vitest": "^2.1.2" }, "types": "types/index.d.ts", "type": "module", @@ -26,7 +27,7 @@ "type": "git", "url": "git+https://github.com/j4w8n/htmlfy.git" }, - "keywords": [ "HTML", "format", "formatter", "prettier", "minifier", "prettify", "minify" ], + "keywords": ["HTML", "format", "formatter", "prettier", "minifier", "prettify", "minify"], "license": "MIT", "bugs": { "url": "https://github.com/j4w8n/htmlfy/issues" diff --git a/src/tests/all.spec.js b/src/tests/all.spec.js new file mode 100644 index 0000000..4d314bc --- /dev/null +++ b/src/tests/all.spec.js @@ -0,0 +1,165 @@ +import { closify } from '../closify.js' +import { entify } from '../entify.js' +import { minify } from '../minify.js' +import { prettify } from '../prettify.js' +import { expect, test } from 'vitest' + +const ugly_html = `
+
+ +
+ +
+
` + +const entify_html = `` + +const pretty_html = `
+ + + + + + +
+ + +
+
+ +
+ + +
+
+ + +
+
` + +const closify_html = `
+ +

` + +const config_html = `
+ +


` + + +test('Prettify', () => { + expect(prettify(ugly_html)).toBe( +`
+ + + + + + +
+ + +
+
+ +
+ + +
+
+ + +
+
` + ) +}) + +test('Prettify with HTML check', () => { + expect(prettify('No HTML')).toBe('No HTML') +}) + +test('Minify', () => { + expect(minify(pretty_html)).toBe( + `



` + ) +}) + +test('Minify with HTML check', () => { + expect(minify('No HTML', true)).toBe('No HTML') +}) + +test('Entify', () => { + expect(entify(entify_html)).toBe( + `` + ) +}) + +test('Entify with plain text', () => { + expect(entify('Plain text')).toBe('Plain text') +}) + +test('Entify with minify', () => { + expect(entify(entify_html, true)).toBe( + `` + ) +}) + +test('Closify', () => { + expect(closify(closify_html)).toBe( +`
+ +

` + ) +}) + +test('Closify with HTML check', () => { + expect(closify('No HTML', true)).toBe('No HTML') +}) + +test('Strict config', () => { + expect(prettify(config_html, { strict: true })).toBe( +`
+
+
+ +
+ +
+
` + ) +}) + +test('Tab size config', () => { + expect(prettify(config_html, { tab_size: 4 })).toBe( +`
+ + +
+
+ +
+ +
+
` + ) +}) diff --git a/tsconfig.json b/tsconfig.json index 093d3b1..927857e 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -12,5 +12,5 @@ "strict": true, "target": "esnext" }, - "include": [ "src/**/*", "index.js", "types/index.d.ts" ] + "include": [ "src/**/*", "src/tests/all.spec.js", "types/index.d.ts" ] }