Add minimal base for tests

This commit is contained in:
Jorge Bucaran 2019-07-12 04:17:43 +09:00
parent 72c986fcf2
commit e29f99735b
No known key found for this signature in database
GPG Key ID: E54BA3C0E646DB30
3 changed files with 45 additions and 7 deletions

View File

@ -4,6 +4,8 @@
"version": "2.0.0-beta.22",
"main": "src/index.js",
"module": "src/index.js",
"unpkg": "src/index.js",
"browser": "src/index.js",
"license": "MIT",
"repository": "jorgebucaran/hyperapp",
"homepage": "https://github.com/jorgebucaran/hyperapp",
@ -20,7 +22,7 @@
"vdom"
],
"scripts": {
"test": "exit 0",
"test": "nyc -i esm -r lcov testmatrix test/*.test.js && nyc report",
"build": "export dir=${pkg:+lib/$pkg/} pkg=$npm_package_name$pkg; npm run bundle && npm run minify",
"bundle": "rollup -i ${dir}$npm_package_module -o ${dir}dist/$pkg.js --no-esModule -mf iife -n $pkg",
"minify": "terser ${dir}dist/$pkg.js -o ${dir}dist/$pkg.js -mc --source-map includeSources,url=$pkg.js.map",
@ -29,7 +31,11 @@
"message": "echo ${pkg:+@$npm_package_name/$pkg@}$(node -p \"require('./${pkg:+lib/$pkg/}package').version\")"
},
"devDependencies": {
"rollup": "*",
"terser": "^4.0.0"
"esm": "^3.2.25",
"nyc": "^14.1.1",
"testmatrix": "^0.1.2",
"jsdom": "15.1.1",
"rollup": "^1.16.7",
"terser": "^4.1.2"
}
}

View File

@ -5,7 +5,10 @@ var EMPTY_OBJ = {}
var EMPTY_ARR = []
var map = EMPTY_ARR.map
var isArray = Array.isArray
var defer = requestAnimationFrame || setTimeout
var defer =
typeof requestAnimationFrame === "undefined"
? setTimeout
: requestAnimationFrame
var createClass = function(obj) {
var out = ""
@ -373,7 +376,7 @@ var createVNode = function(name, props, children, node, key, type) {
}
var createTextVNode = function(value, node) {
return createVNode(value, EMPTY_OBJ, EMPTY_ARR, node, null, TEXT_NODE)
return createVNode(value, EMPTY_OBJ, EMPTY_ARR, node, undefined, TEXT_NODE)
}
var recycleNode = function(node) {
@ -384,7 +387,7 @@ var recycleNode = function(node) {
EMPTY_OBJ,
map.call(node.childNodes, recycleNode),
node,
null,
undefined,
RECYCLED_NODE
)
}
@ -416,7 +419,7 @@ export var h = function(name, props) {
return typeof name === "function"
? name(props, children)
: createVNode(name, props, children, null, props.key)
: createVNode(name, props, children, undefined, props.key)
}
export var app = function(props, enhance) {

29
test/h.test.js Normal file
View File

@ -0,0 +1,29 @@
import { h } from ".."
import { deepEqual } from "testmatrix"
export default {
h: [
{
name: "first test",
assert: deepEqual,
actual: h("h1", { id: "title" }, "hello"),
expected: {
name: "h1",
props: { id: "title" },
children: [
{
name: "hello",
props: {},
children: [],
node: undefined,
type: 3,
key: undefined
}
],
node: undefined,
type: undefined,
key: undefined
}
}
]
}