1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-25 00:06:30 +02:00

Revert jest (#507)

* remove debugger

* switch back to mocha

* remove jest config from package.json

* remove old browser test support files

* remove unnecessary assert-json helper
This commit is contained in:
Ian Storm Taylor
2016-12-07 15:16:49 -08:00
committed by GitHub
parent a1638dd906
commit 1f60d4c9ab
9 changed files with 28 additions and 13670 deletions

View File

@@ -25,7 +25,7 @@
"babel-cli": "^6.10.1", "babel-cli": "^6.10.1",
"babel-core": "^6.9.1", "babel-core": "^6.9.1",
"babel-eslint": "^6.1.0", "babel-eslint": "^6.1.0",
"babel-jest": "^17.0.2", "babel-polyfill": "^6.16.0",
"babel-preset-es2015": "^6.9.0", "babel-preset-es2015": "^6.9.0",
"babel-preset-react": "^6.5.0", "babel-preset-react": "^6.5.0",
"babel-preset-stage-0": "^6.5.0", "babel-preset-stage-0": "^6.5.0",
@@ -102,7 +102,7 @@
"release:next": "np --tag=next", "release:next": "np --tag=next",
"start": "http-server ./examples", "start": "http-server ./examples",
"test": "npm-run-all build:test tests", "test": "npm-run-all build:test tests",
"tests": "jest", "tests": "mocha --compilers js:babel-core/register ./test/index.js",
"watch": "npm-run-all --parallel --print-label watch:lib watch:examples start", "watch": "npm-run-all --parallel --print-label watch:lib watch:examples start",
"watch:lib": "babel --watch --out-dir ./lib ./src", "watch:lib": "babel --watch --out-dir ./lib ./src",
"watch:examples": "watchify --debug --transform babelify ./examples/index.js -o ./examples/build.dev.js" "watch:examples": "watchify --debug --transform babelify ./examples/index.js -o ./examples/build.dev.js"
@@ -113,10 +113,6 @@
"react-dom": "ReactDOM", "react-dom": "ReactDOM",
"react-dom/server": "ReactDOMServer" "react-dom/server": "ReactDOMServer"
}, },
"jest": {
"testEnvironment": "node",
"testRegex": "/test/(rendering|schema|serializers|transforms)/index\\.js$"
},
"keywords": [ "keywords": [
"canvas", "canvas",
"contenteditable", "contenteditable",

View File

@@ -1,185 +0,0 @@
import assert from 'assert'
import type from 'type-of'
/**
* Assertion error.
*/
const AssertionError = assert.AssertionError
/**
* Assert that an `actual` JSON object equals an `expected` value.
*
* @param {Object} actual
* @param {Object} expected
* @throws {AssertionError}
*/
export function equal(actual, expected, message) {
if (!test(actual, expected)) {
throw new AssertionError({
actual: actual,
expected: wrap(actual, expected),
operator: '==',
stackStartFunction: equal
})
}
}
/**
* Assert that an `actual` JSON object does not equal an `expected` value.
*
* @param {Object} actual
* @param {Object} expected
* @throws {AssertionError}
*/
export function notEqual(actual, expected, message) {
if (test(actual, expected)) {
throw new AssertionError({
actual: actual,
expected: wrap(actual, expected),
operator: '!=',
stackStartFunction: notEqual
})
}
}
/**
* Assert that an `actual` JSON object strict equals an `expected` value.
*
* @param {Object} actual
* @param {Object} expected
* @throws {AssertionError}
*/
export function strictEqual(actual, expected, message) {
if (!test(actual, expected, true)) {
throw new AssertionError({
actual: actual,
expected: wrap(actual, expected),
operator: '===',
stackStartFunction: equal
})
}
}
/**
* Assert that an `actual` JSON object does not strict equal an `expected` value.
*
* @param {Object} actual
* @param {Object} expected
* @throws {AssertionError}
*/
export function notStrictEqual(actual, expected, message) {
if (test(actual, expected, true)) {
throw new AssertionError({
actual: actual,
expected: wrap(actual, expected),
operator: '!==',
stackStartFunction: notEqual
})
}
}
/**
* Test that an `actual` JSON value equals an `expected` JSON value.
*
* If a function is passed as any value, it is called with the actual value and
* must return a boolean.
*
* Strict mode uses strict equality, forces arrays to be of the same length, and
* objects to have the same keys.
*
* @param {Mixed} actual
* @param {Mixed} expected
* @param {Boolean} strict
* @return {Boolean}
*/
function test(actual, expected, strict) {
if (type(expected) == 'function') return !! expected(actual)
if (type(actual) != type(expected)) return false
switch (type(expected)) {
case 'object':
return object(actual, expected, strict)
case 'array':
return array(actual, expected, strict)
default:
return strict ? actual === expected : actual == expected
}
}
/**
* Test that an `actual` object equals an `expected` object.
*
* @param {Object} object
* @param {Object} expected
* @param {Boolean} strict
* @return {Boolean}
*/
function object(actual, expected, strict) {
if (strict) {
var ka = Object.keys(actual).sort()
var ke = Object.keys(expected).sort()
if (!test(ka, ke, strict)) return false
}
for (var key in expected) {
if (!test(actual[key], expected[key], strict)) return false
}
return true
}
/**
* Test that an `actual` array equals an `expected` array.
*
* @param {Array} actual
* @param {Array} expected
* @param {Boolean} strict
* @return {Boolean}
*/
function array(actual, expected, strict) {
if (strict) {
if (!test(actual.length, expected.length, strict)) return false
}
for (var i = 0; i < expected.length; i++) {
if (!test(actual[i], expected[i], strict)) return false
}
return true
}
/**
* Wrap an expected value to remove annoying false negatives.
*
* @param {Mixed} actual
* @param {Mixed} expected
* @return {Mixed}
*/
function wrap(actual, expected) {
if (type(expected) == 'function') return expected(actual) ? actual : expected
if (type(actual) != type(expected)) return expected
if (type(expected) == 'object') {
for (var key in expected) {
expected[key] = wrap(actual[key], expected[key])
}
}
if (type(expected) == 'array') {
for (var i = 0; i < expected.length; i++) {
expected[i] = wrap(actual[i], expected[i])
}
}
return expected
}

11
test/index.js Normal file
View File

@@ -0,0 +1,11 @@
import 'babel-polyfill'
/**
* Tests.
*/
import './rendering'
import './schema'
import './serializers'
import './transforms'

View File

@@ -1,10 +1,10 @@
import assert from 'assert'
import fs from 'fs' import fs from 'fs'
import readYaml from 'read-yaml-promise' import readYaml from 'read-yaml-promise'
import strip from '../helpers/strip-dynamic' import strip from '../helpers/strip-dynamic'
import { Raw, Schema } from '../..' import { Raw, Schema } from '../..'
import { resolve } from 'path' import { resolve } from 'path'
import { strictEqual } from '../helpers/assert-json'
/** /**
* Tests. * Tests.
@@ -31,7 +31,7 @@ describe('schema', () => {
const state = Raw.deserialize(input, { terse: true }) const state = Raw.deserialize(input, { terse: true })
const normalized = state.transform().normalize(schema).apply() const normalized = state.transform().normalize(schema).apply()
const output = Raw.serialize(normalized, { terse: true }) const output = Raw.serialize(normalized, { terse: true })
strictEqual(strip(output), strip(expected)) assert.deepEqual(strip(output), strip(expected))
}) })
} }
}) })

View File

@@ -4,7 +4,6 @@ import fs from 'fs'
import readYaml from 'read-yaml-promise' import readYaml from 'read-yaml-promise'
import strip from '../helpers/strip-dynamic' import strip from '../helpers/strip-dynamic'
import { Html, Plain, Raw } from '../..' import { Html, Plain, Raw } from '../..'
import { strictEqual } from '../helpers/assert-json'
import { resolve } from 'path' import { resolve } from 'path'
import React from 'react' import React from 'react'
import { Iterable } from 'immutable' import { Iterable } from 'immutable'
@@ -28,7 +27,7 @@ describe('serializers', () => {
const input = fs.readFileSync(resolve(innerDir, 'input.html'), 'utf8') const input = fs.readFileSync(resolve(innerDir, 'input.html'), 'utf8')
const state = html.deserialize(input) const state = html.deserialize(input)
const json = state.document.toJS() const json = state.document.toJS()
strictEqual(strip(json), expected) assert.deepEqual(strip(json), expected)
}) })
} }
}) })
@@ -45,7 +44,7 @@ describe('serializers', () => {
const input = require(resolve(innerDir, 'input.js')).default const input = require(resolve(innerDir, 'input.js')).default
const expected = fs.readFileSync(resolve(innerDir, 'output.html'), 'utf8') const expected = fs.readFileSync(resolve(innerDir, 'output.html'), 'utf8')
const serialized = html.serialize(input) const serialized = html.serialize(input)
strictEqual(serialized, expected.trim()) assert.deepEqual(serialized, expected.trim())
}) })
} }
@@ -72,7 +71,7 @@ describe('serializers', () => {
const input = fs.readFileSync(resolve(innerDir, 'input.txt'), 'utf8') const input = fs.readFileSync(resolve(innerDir, 'input.txt'), 'utf8')
const state = Plain.deserialize(input.replace(/\n$/m, '')) const state = Plain.deserialize(input.replace(/\n$/m, ''))
const json = state.document.toJS() const json = state.document.toJS()
strictEqual(strip(json), expected) assert.deepEqual(strip(json), expected)
}) })
} }
}) })
@@ -88,7 +87,7 @@ describe('serializers', () => {
const input = require(resolve(innerDir, 'input.js')).default const input = require(resolve(innerDir, 'input.js')).default
const expected = fs.readFileSync(resolve(innerDir, 'output.txt'), 'utf8') const expected = fs.readFileSync(resolve(innerDir, 'output.txt'), 'utf8')
const serialized = Plain.serialize(input) const serialized = Plain.serialize(input)
strictEqual(serialized, expected.replace(/\n$/m, '')) assert.deepEqual(serialized, expected.replace(/\n$/m, ''))
}) })
} }
}) })
@@ -107,7 +106,7 @@ describe('serializers', () => {
const input = await readYaml(resolve(innerDir, 'input.yaml')) const input = await readYaml(resolve(innerDir, 'input.yaml'))
const state = Raw.deserialize(input) const state = Raw.deserialize(input)
const json = state.document.toJS() const json = state.document.toJS()
strictEqual(strip(json), expected) assert.deepEqual(strip(json), expected)
}) })
} }
}) })
@@ -124,7 +123,7 @@ describe('serializers', () => {
const expected = await readYaml(resolve(innerDir, 'output.yaml')) const expected = await readYaml(resolve(innerDir, 'output.yaml'))
const serialized = Raw.serialize(input) const serialized = Raw.serialize(input)
serialized.document = strip(serialized.document) serialized.document = strip(serialized.document)
strictEqual(serialized, expected) assert.deepEqual(serialized, expected)
}) })
} }
}) })
@@ -141,7 +140,7 @@ describe('serializers', () => {
const input = await readYaml(resolve(innerDir, 'input.yaml')) const input = await readYaml(resolve(innerDir, 'input.yaml'))
const state = Raw.deserialize(input, { terse: true }) const state = Raw.deserialize(input, { terse: true })
const json = state.document.toJS() const json = state.document.toJS()
strictEqual(strip(json), expected) assert.deepEqual(strip(json), expected)
}) })
} }
}) })
@@ -157,7 +156,7 @@ describe('serializers', () => {
const input = require(resolve(innerDir, 'input.js')).default const input = require(resolve(innerDir, 'input.js')).default
const expected = await readYaml(resolve(innerDir, 'output.yaml')) const expected = await readYaml(resolve(innerDir, 'output.yaml'))
const serialized = Raw.serialize(input, { terse: true }) const serialized = Raw.serialize(input, { terse: true })
strictEqual(strip(serialized), expected) assert.deepEqual(strip(serialized), expected)
}) })
} }
}) })

View File

@@ -1,14 +0,0 @@
<html>
<head>
<meta charset="utf-8" />
<link rel="stylesheet" href="mocha.css" />
<title>Editor | Tests</title>
</head>
<body>
<div id="mocha"></div>
<script src="mocha.js"></script>
<script>mocha.ui('bdd')</script>
<script src="build.js"></script>
<script>mocha.run()</script>
</body>
</html>

View File

@@ -1,314 +0,0 @@
@charset "utf-8";
body {
margin:0;
}
#mocha {
font: 20px/1.5 "Helvetica Neue", Helvetica, Arial, sans-serif;
margin: 60px 50px;
}
#mocha ul,
#mocha li {
margin: 0;
padding: 0;
}
#mocha ul {
list-style: none;
}
#mocha h1,
#mocha h2 {
margin: 0;
}
#mocha h1 {
margin-top: 15px;
font-size: 1em;
font-weight: 200;
}
#mocha h1 a {
text-decoration: none;
color: inherit;
}
#mocha h1 a:hover {
text-decoration: underline;
}
#mocha .suite .suite h1 {
margin-top: 0;
font-size: .8em;
}
#mocha .hidden {
display: none;
}
#mocha h2 {
font-size: 12px;
font-weight: normal;
cursor: pointer;
}
#mocha .suite {
margin-left: 15px;
}
#mocha .test {
margin-left: 15px;
overflow: hidden;
}
#mocha .test.pending:hover h2::after {
content: '(pending)';
font-family: arial, sans-serif;
}
#mocha .test.pass.medium .duration {
background: #c09853;
}
#mocha .test.pass.slow .duration {
background: #b94a48;
}
#mocha .test.pass::before {
content: '✓';
font-size: 12px;
display: block;
float: left;
margin-right: 5px;
color: #00d6b2;
}
#mocha .test.pass .duration {
font-size: 9px;
margin-left: 5px;
padding: 2px 5px;
color: #fff;
-webkit-box-shadow: inset 0 1px 1px rgba(0,0,0,.2);
-moz-box-shadow: inset 0 1px 1px rgba(0,0,0,.2);
box-shadow: inset 0 1px 1px rgba(0,0,0,.2);
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
-ms-border-radius: 5px;
-o-border-radius: 5px;
border-radius: 5px;
}
#mocha .test.pass.fast .duration {
display: none;
}
#mocha .test.pending {
color: #0b97c4;
}
#mocha .test.pending::before {
content: '◦';
color: #0b97c4;
}
#mocha .test.fail {
color: #c00;
}
#mocha .test.fail pre {
color: black;
}
#mocha .test.fail::before {
content: '✖';
font-size: 12px;
display: block;
float: left;
margin-right: 5px;
color: #c00;
}
#mocha .test pre.error {
color: #c00;
max-height: 300px;
overflow: auto;
}
#mocha .test .html-error {
overflow: auto;
color: black;
line-height: 1.5;
display: block;
float: left;
clear: left;
font: 12px/1.5 monaco, monospace;
margin: 5px;
padding: 15px;
border: 1px solid #eee;
max-width: 85%; /*(1)*/
max-width: calc(100% - 42px); /*(2)*/
max-height: 300px;
word-wrap: break-word;
border-bottom-color: #ddd;
-webkit-border-radius: 3px;
-webkit-box-shadow: 0 1px 3px #eee;
-moz-border-radius: 3px;
-moz-box-shadow: 0 1px 3px #eee;
border-radius: 3px;
}
#mocha .test .html-error pre.error {
border: none;
-webkit-border-radius: none;
-webkit-box-shadow: none;
-moz-border-radius: none;
-moz-box-shadow: none;
padding: 0;
margin: 0;
margin-top: 18px;
max-height: none;
}
/**
* (1): approximate for browsers not supporting calc
* (2): 42 = 2*15 + 2*10 + 2*1 (padding + margin + border)
* ^^ seriously
*/
#mocha .test pre {
display: block;
float: left;
clear: left;
font: 12px/1.5 monaco, monospace;
margin: 5px;
padding: 15px;
border: 1px solid #eee;
max-width: 85%; /*(1)*/
max-width: calc(100% - 42px); /*(2)*/
word-wrap: break-word;
border-bottom-color: #ddd;
-webkit-border-radius: 3px;
-webkit-box-shadow: 0 1px 3px #eee;
-moz-border-radius: 3px;
-moz-box-shadow: 0 1px 3px #eee;
border-radius: 3px;
}
#mocha .test h2 {
position: relative;
}
#mocha .test a.replay {
position: absolute;
top: 3px;
right: 0;
text-decoration: none;
vertical-align: middle;
display: block;
width: 15px;
height: 15px;
line-height: 15px;
text-align: center;
background: #eee;
font-size: 15px;
-moz-border-radius: 15px;
border-radius: 15px;
-webkit-transition: opacity 200ms;
-moz-transition: opacity 200ms;
transition: opacity 200ms;
opacity: 0.3;
color: #888;
}
#mocha .test:hover a.replay {
opacity: 1;
}
#mocha-report.pass .test.fail {
display: none;
}
#mocha-report.fail .test.pass {
display: none;
}
#mocha-report.pending .test.pass,
#mocha-report.pending .test.fail {
display: none;
}
#mocha-report.pending .test.pass.pending {
display: block;
}
#mocha-error {
color: #c00;
font-size: 1.5em;
font-weight: 100;
letter-spacing: 1px;
}
#mocha-stats {
position: fixed;
top: 15px;
right: 10px;
font-size: 12px;
margin: 0;
color: #888;
z-index: 1;
}
#mocha-stats .progress {
float: right;
padding-top: 0;
/**
* Set safe initial values, so mochas .progress does not inherit these
* properties from Bootstrap .progress (which causes .progress height to
* equal line height set in Bootstrap).
*/
height: auto;
box-shadow: none;
background-color: initial;
}
#mocha-stats em {
color: black;
}
#mocha-stats a {
text-decoration: none;
color: inherit;
}
#mocha-stats a:hover {
border-bottom: 1px solid #eee;
}
#mocha-stats li {
display: inline-block;
margin: 0 5px;
list-style: none;
padding-top: 11px;
}
#mocha-stats canvas {
width: 40px;
height: 40px;
}
#mocha code .comment { color: #ddd; }
#mocha code .init { color: #2f6fad; }
#mocha code .string { color: #5890ad; }
#mocha code .keyword { color: #8a6343; }
#mocha code .number { color: #2f6fad; }
@media screen and (max-device-width: 480px) {
#mocha {
margin: 60px 0px;
}
#mocha #stats {
position: absolute;
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,10 +1,10 @@
import assert from 'assert'
import fs from 'fs-promise' import fs from 'fs-promise'
import readYaml from 'read-yaml-promise' import readYaml from 'read-yaml-promise'
import strip from '../helpers/strip-dynamic' import strip from '../helpers/strip-dynamic'
import toCamel from 'to-camel-case' import toCamel from 'to-camel-case'
import { Raw } from '../..' import { Raw } from '../..'
import { strictEqual } from '../helpers/assert-json'
import { resolve } from 'path' import { resolve } from 'path'
/** /**
@@ -35,7 +35,7 @@ describe('transforms', async () => {
let state = Raw.deserialize(input, { terse: true }) let state = Raw.deserialize(input, { terse: true })
state = fn(state) state = fn(state)
const output = Raw.serialize(state, { terse: true }) const output = Raw.serialize(state, { terse: true })
strictEqual(strip(output), strip(expected)) assert.deepEqual(strip(output), strip(expected))
}) })
} }
}) })
@@ -91,7 +91,7 @@ describe('transforms', async () => {
let state = Raw.deserialize(input, { terse: true }) let state = Raw.deserialize(input, { terse: true })
state = fn(state) state = fn(state)
const output = Raw.serialize(state, { terse: true }) const output = Raw.serialize(state, { terse: true })
strictEqual(strip(output), strip(expected)) assert.deepEqual(strip(output), strip(expected))
}) })
} }
}) })
@@ -121,7 +121,7 @@ describe('transforms', async () => {
let state = Raw.deserialize(input, { terse: true }) let state = Raw.deserialize(input, { terse: true })
state = fn(state) state = fn(state)
const output = Raw.serialize(state, { terse: true }) const output = Raw.serialize(state, { terse: true })
strictEqual(strip(output), strip(expected)) assert.deepEqual(strip(output), strip(expected))
}) })
} }
}) })
@@ -151,7 +151,7 @@ describe('transforms', async () => {
let state = Raw.deserialize(input, { terse: true }) let state = Raw.deserialize(input, { terse: true })
state = fn(state) state = fn(state)
const output = Raw.serialize(state, { terse: true }) const output = Raw.serialize(state, { terse: true })
strictEqual(strip(output), strip(expected)) assert.deepEqual(strip(output), strip(expected))
}) })
} }
}) })