escss-estest
Advanced tools
Comparing version 1.4.18 to 1.4.19
type TYPES = 'undefined' | 'null' | 'array' | 'object' | 'boolean' | 'NaN' | 'number' | 'bigint' | 'string' | 'symbol' | 'function' | ||
/** | ||
* 100% function coverage for easier life. More: https://github.com/ESCSS-labs/ESCSS-ESTest | ||
* A runtime testing library inspired by TDD and TypeScript to achieve 100% coverage | ||
* ```js | ||
@@ -5,0 +5,0 @@ * ESTest(NaN, 'NaN') |
/** | ||
* escss-estest v1.4.18 | ||
* escss-estest v1.4.19 | ||
* (c) 2024 Mike Lee | ||
@@ -7,5 +7,3 @@ * @license AGPL-3.0-only OR Commercial (https://github.com/ESCSS-labs) | ||
/** Internal testing token */ | ||
let _typeToken = '' | ||
let _testToken = '' | ||
const TYPES = ['undefined', 'null', 'array', 'object', 'boolean', 'NaN', 'number', 'bigint', 'string', 'symbol', 'function'] | ||
@@ -87,15 +85,2 @@ | ||
/** | ||
* Only display in production to safeguard data during error situations. | ||
* @param {string | undefined} msg | ||
*/ | ||
function getErrorMsg(msg) { | ||
throw new Error( | ||
` | ||
🚫 Detailed information is hidden for security reasons in production. | ||
❗ ${msg} | ||
`, | ||
) | ||
} | ||
/** | ||
* 100% function coverage for easier life. demo: https://demo-estest-log-not-visible.netlify.app/ | ||
@@ -107,6 +92,11 @@ * @param {*} input | ||
function ESTest(input, type, errMsg = 'undefined error message') { | ||
if (process.env.NODE_ENV === 'production') getErrorMsg(errMsg) | ||
else { | ||
if (process.env.NODE_ENV === 'test') _typeToken = type | ||
if (process.env.NODE_ENV === 'production') { | ||
throw new Error( | ||
` | ||
🚫 Production hides details for security. View them in development. | ||
❗ ${msg} | ||
`, | ||
) | ||
} | ||
else { | ||
// development | ||
@@ -138,5 +128,8 @@ if (!TYPES.includes(type)) { | ||
} | ||
// internal testing purpose | ||
if (process.env.NODE_ENV === 'test') _testToken = type | ||
} | ||
} | ||
export { _typeToken, ESTest } | ||
export { _testToken, ESTest } |
{ | ||
"name": "escss-estest", | ||
"version": "1.4.18", | ||
"description": "100% function coverage for easier life.", | ||
"version": "1.4.19", | ||
"description": "A runtime testing library inspired by TDD and TypeScript to achieve 100% coverage.", | ||
"keywords": [ | ||
@@ -6,0 +6,0 @@ "escss", |
@@ -17,3 +17,3 @@ ![logo](https://github.com/ESCSS-labs/ESCSS/blob/main/assets/logo.png) | ||
ESCSS-ESTest helps you to achieve 100% coverage by taking the potential of TDD and TypeScript. | ||
ESCSS-ESTest is a runtime testing library inspired by TDD and TypeScript to achieve 100% coverage. | ||
@@ -34,3 +34,3 @@ ## Core Concept - Water Filter | ||
### Use Cases | ||
### Examples | ||
@@ -53,10 +53,11 @@ ```js | ||
### Pure vs Impure | ||
### General | ||
```js | ||
import { ESTest } from "escss-estest"; | ||
let isEnable = true; | ||
// Pure (input in {...}) | ||
function pureSum(a, b) { | ||
// Testing input in {...} | ||
function sum(a, b) { | ||
{ | ||
@@ -68,29 +69,9 @@ ESTest(a, "number"); | ||
if (!isEnable) return 0; | ||
if (!isEnable) return; | ||
return a + b; | ||
} | ||
// Impure | ||
function impureSum(a, b) { | ||
if (!isEnable) return 0; | ||
return a + b; | ||
} | ||
// NOTE: the "function" type check is unnecessary. | ||
function total(x) { | ||
{ | ||
ESTest(x, "number"); | ||
// If the function doesn't exist, it will return 'xxx is undefined.' | ||
// If the function exists, pureSum(a, b) will handle type check, so the "function" check is redundant. | ||
ESTest(pureSum, "function"); // not necessary. | ||
} | ||
return x + pureSum(1, 2); | ||
} | ||
``` | ||
### Error handling: async/await | ||
### async/await | ||
@@ -101,21 +82,20 @@ ```js | ||
async function getData() { | ||
const url = "https://jsonplaceholder.typicode.com/todos/99999"; // undefined api | ||
const response = await fetch(url); | ||
const json = await response.json(); | ||
const response = await fetch("https://jsonplaceholder.typicode.com/todos/1"); | ||
const data = await response.json(); | ||
{ | ||
ESTest(json, 'object') | ||
ESTest(json.userId, "number"); | ||
ESTest(json.id, "number"); | ||
ESTest(json.title, "string"); | ||
ESTest(json.completed, "boolean"); | ||
ESTest(data, 'object') | ||
ESTest(data.userId, "number"); | ||
ESTest(data.id, "number"); | ||
ESTest(data.title, "string"); | ||
ESTest(data.completed, "boolean"); | ||
} | ||
console.log(json); | ||
console.log(data); | ||
} | ||
getData(); // get error (undefined api from 99999) | ||
getData(); // pass: response data is as expected | ||
``` | ||
### Error handling: class | ||
### Class | ||
@@ -137,3 +117,3 @@ ```js | ||
new Animal("cat", "10"); // get error, "10" should be number | ||
new Animal("cat", 10); // pass: response data is as expected | ||
``` | ||
@@ -159,2 +139,8 @@ | ||
```javascript | ||
import { ESTest } from "escss-estest"; | ||
ESTest('Happy Coding!', 'string') // pass | ||
``` | ||
Nuxt 3 | ||
@@ -165,4 +151,10 @@ ```bash | ||
```vue | ||
<script setup> | ||
ESTest('Happy Coding!', 'string') // pass | ||
</script> | ||
``` | ||
## License | ||
[see](https://github.com/ESCSS-labs/ESCSS-ESTest?tab=License-1-ov-file) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
9004
136
153