mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-02-01 05:16:10 +01:00
* update tests to use jest and be async, closes #495 * add read-metadata for perf and fragments
This commit is contained in:
parent
2fa096898c
commit
55fd06449b
10
package.json
10
package.json
@ -25,6 +25,7 @@
|
||||
"babel-cli": "^6.10.1",
|
||||
"babel-core": "^6.9.1",
|
||||
"babel-eslint": "^6.1.0",
|
||||
"babel-jest": "^17.0.2",
|
||||
"babel-preset-es2015": "^6.9.0",
|
||||
"babel-preset-react": "^6.5.0",
|
||||
"babel-preset-stage-0": "^6.5.0",
|
||||
@ -41,10 +42,12 @@
|
||||
"eslint-plugin-react": "^6.4.1",
|
||||
"faker": "^3.1.0",
|
||||
"fbjs": "^0.8.3",
|
||||
"fs-promise": "^1.0.0",
|
||||
"gh-pages": "^0.11.0",
|
||||
"http-server": "^0.9.0",
|
||||
"is-image": "^1.0.1",
|
||||
"is-url": "^1.2.2",
|
||||
"jest": "^17.0.3",
|
||||
"jsdom": "9.6.0",
|
||||
"jsdom-global": "2.1.0",
|
||||
"microtime": "2.1.1",
|
||||
@ -61,6 +64,7 @@
|
||||
"react-portal": "^2.2.0",
|
||||
"react-router": "^2.5.1",
|
||||
"read-metadata": "^1.0.0",
|
||||
"read-yaml-promise": "^1.0.2",
|
||||
"selection-position": "^1.0.0",
|
||||
"slate-auto-replace-text": "^0.3.0",
|
||||
"slate-collapse-on-escape": "^0.2.0",
|
||||
@ -98,7 +102,7 @@
|
||||
"release:next": "np --tag=next",
|
||||
"start": "http-server ./examples",
|
||||
"test": "npm-run-all build:test tests",
|
||||
"tests": "mocha --compilers js:babel-core/register --reporter spec ./test/server.js",
|
||||
"tests": "jest",
|
||||
"watch": "npm-run-all --parallel --print-label watch:lib watch:examples start",
|
||||
"watch:lib": "babel --watch --out-dir ./lib ./src",
|
||||
"watch:examples": "watchify --debug --transform babelify ./examples/index.js -o ./examples/build.dev.js"
|
||||
@ -109,6 +113,10 @@
|
||||
"react-dom": "ReactDOM",
|
||||
"react-dom/server": "ReactDOMServer"
|
||||
},
|
||||
"jest": {
|
||||
"testEnvironment": "node",
|
||||
"testRegex": "/test/(rendering|schema|serializers|transforms)/index\\.js$"
|
||||
},
|
||||
"keywords": [
|
||||
"canvas",
|
||||
"contenteditable",
|
||||
|
@ -1,21 +0,0 @@
|
||||
|
||||
/**
|
||||
* Polyfills.
|
||||
*/
|
||||
|
||||
require('babel-polyfill')
|
||||
|
||||
/**
|
||||
* Dependencies.
|
||||
*/
|
||||
|
||||
const assert = require('assert')
|
||||
const Editor = require('..')
|
||||
|
||||
/**
|
||||
* Tests.
|
||||
*/
|
||||
|
||||
describe('browser', () => {
|
||||
|
||||
})
|
@ -3,8 +3,8 @@ import React from 'react'
|
||||
import ReactDOM from 'react-dom/server'
|
||||
import assert from 'assert'
|
||||
import cheerio from 'cheerio'
|
||||
import fs from 'fs'
|
||||
import readMetadata from 'read-metadata'
|
||||
import fs from 'fs-promise'
|
||||
import readYaml from 'read-yaml-promise'
|
||||
import { Editor, Raw } from '../..'
|
||||
import { resolve } from 'path'
|
||||
|
||||
@ -18,10 +18,10 @@ describe('rendering', () => {
|
||||
for (const test of tests) {
|
||||
if (test[0] === '.') continue
|
||||
|
||||
it(test, () => {
|
||||
it(test, async () => {
|
||||
const dir = resolve(__dirname, './fixtures', test)
|
||||
const input = readMetadata.sync(resolve(dir, 'input.yaml'))
|
||||
const output = fs.readFileSync(resolve(dir, 'output.html'), 'utf8')
|
||||
const input = await readYaml(resolve(dir, 'input.yaml'))
|
||||
const output = await fs.readFile(resolve(dir, 'output.html'), 'utf8')
|
||||
const props = {
|
||||
state: Raw.deserialize(input, { terse: true }),
|
||||
onChange: () => {},
|
||||
|
@ -1,7 +1,6 @@
|
||||
|
||||
import 'jsdom-global/register'
|
||||
import fs from 'fs'
|
||||
import readMetadata from 'read-metadata'
|
||||
import readYaml from 'read-yaml-promise'
|
||||
import strip from '../helpers/strip-dynamic'
|
||||
import { Raw, Schema } from '../..'
|
||||
import { resolve } from 'path'
|
||||
@ -24,10 +23,10 @@ describe('schema', () => {
|
||||
for (const test of tests) {
|
||||
if (test[0] == '.') continue
|
||||
|
||||
it(test, () => {
|
||||
it(test, async () => {
|
||||
const testDir = resolve(__dirname, './fixtures', category, test)
|
||||
const input = readMetadata.sync(resolve(testDir, 'input.yaml'))
|
||||
const expected = readMetadata.sync(resolve(testDir, 'output.yaml'))
|
||||
const input = await readYaml(resolve(testDir, 'input.yaml'))
|
||||
const expected = await readYaml(resolve(testDir, 'output.yaml'))
|
||||
const schema = Schema.create(require(testDir))
|
||||
const state = Raw.deserialize(input, { terse: true })
|
||||
const normalized = state.transform().normalize(schema).apply()
|
||||
|
@ -1,11 +1,10 @@
|
||||
|
||||
import assert from 'assert'
|
||||
import type from 'type-of'
|
||||
import fs from 'fs'
|
||||
import readMetadata from 'read-metadata'
|
||||
import readYaml from 'read-yaml-promise'
|
||||
import strip from '../helpers/strip-dynamic'
|
||||
import { Html, Json, Plain, Raw } from '../..'
|
||||
import { equal, strictEqual } from '../helpers/assert-json'
|
||||
import { Html, Plain, Raw } from '../..'
|
||||
import { strictEqual } from '../helpers/assert-json'
|
||||
import { resolve } from 'path'
|
||||
import React from 'react'
|
||||
import { Iterable } from 'immutable'
|
||||
@ -22,10 +21,10 @@ describe('serializers', () => {
|
||||
|
||||
for (const test of tests) {
|
||||
if (test[0] === '.') continue
|
||||
it(test, () => {
|
||||
it(test, async () => {
|
||||
const innerDir = resolve(dir, test)
|
||||
const html = new Html(require(innerDir).default)
|
||||
const expected = readMetadata.sync(resolve(innerDir, 'output.yaml'))
|
||||
const expected = await readYaml(resolve(innerDir, 'output.yaml'))
|
||||
const input = fs.readFileSync(resolve(innerDir, 'input.html'), 'utf8')
|
||||
const state = html.deserialize(input)
|
||||
const json = state.document.toJS()
|
||||
@ -40,7 +39,7 @@ describe('serializers', () => {
|
||||
|
||||
for (const test of tests) {
|
||||
if (test[0] === '.') continue
|
||||
it(test, () => {
|
||||
it(test, async () => {
|
||||
const innerDir = resolve(dir, test)
|
||||
const html = new Html(require(innerDir).default)
|
||||
const input = require(resolve(innerDir, 'input.js')).default
|
||||
@ -67,9 +66,9 @@ describe('serializers', () => {
|
||||
|
||||
for (const test of tests) {
|
||||
if (test[0] === '.') continue
|
||||
it(test, () => {
|
||||
it(test, async () => {
|
||||
const innerDir = resolve(dir, test)
|
||||
const expected = readMetadata.sync(resolve(innerDir, 'output.yaml'))
|
||||
const expected = await readYaml(resolve(innerDir, 'output.yaml'))
|
||||
const input = fs.readFileSync(resolve(innerDir, 'input.txt'), 'utf8')
|
||||
const state = Plain.deserialize(input.replace(/\n$/m, ''))
|
||||
const json = state.document.toJS()
|
||||
@ -84,7 +83,7 @@ describe('serializers', () => {
|
||||
|
||||
for (const test of tests) {
|
||||
if (test[0] === '.') continue
|
||||
it(test, () => {
|
||||
it(test, async () => {
|
||||
const innerDir = resolve(dir, test)
|
||||
const input = require(resolve(innerDir, 'input.js')).default
|
||||
const expected = fs.readFileSync(resolve(innerDir, 'output.txt'), 'utf8')
|
||||
@ -102,10 +101,10 @@ describe('serializers', () => {
|
||||
|
||||
for (const test of tests) {
|
||||
if (test[0] === '.') continue
|
||||
it(test, () => {
|
||||
it(test, async () => {
|
||||
const innerDir = resolve(dir, test)
|
||||
const expected = readMetadata.sync(resolve(innerDir, 'output.yaml'))
|
||||
const input = readMetadata.sync(resolve(innerDir, 'input.yaml'))
|
||||
const expected = await readYaml(resolve(innerDir, 'output.yaml'))
|
||||
const input = await readYaml(resolve(innerDir, 'input.yaml'))
|
||||
const state = Raw.deserialize(input)
|
||||
const json = state.document.toJS()
|
||||
strictEqual(strip(json), expected)
|
||||
@ -119,10 +118,10 @@ describe('serializers', () => {
|
||||
|
||||
for (const test of tests) {
|
||||
if (test[0] === '.') continue
|
||||
it(test, () => {
|
||||
it(test, async () => {
|
||||
const innerDir = resolve(dir, test)
|
||||
const input = require(resolve(innerDir, 'input.js')).default
|
||||
const expected = readMetadata.sync(resolve(innerDir, 'output.yaml'))
|
||||
const expected = await readYaml(resolve(innerDir, 'output.yaml'))
|
||||
const serialized = Raw.serialize(input)
|
||||
serialized.document = strip(serialized.document)
|
||||
strictEqual(serialized, expected)
|
||||
@ -136,10 +135,10 @@ describe('serializers', () => {
|
||||
|
||||
for (const test of tests) {
|
||||
if (test[0] === '.') continue
|
||||
it(test, () => {
|
||||
it(test, async () => {
|
||||
const innerDir = resolve(dir, test)
|
||||
const expected = readMetadata.sync(resolve(innerDir, 'output.yaml'))
|
||||
const input = readMetadata.sync(resolve(innerDir, 'input.yaml'))
|
||||
const expected = await readYaml(resolve(innerDir, 'output.yaml'))
|
||||
const input = await readYaml(resolve(innerDir, 'input.yaml'))
|
||||
const state = Raw.deserialize(input, { terse: true })
|
||||
const json = state.document.toJS()
|
||||
strictEqual(strip(json), expected)
|
||||
@ -153,10 +152,10 @@ describe('serializers', () => {
|
||||
|
||||
for (const test of tests) {
|
||||
if (test[0] === '.') continue
|
||||
it(test, () => {
|
||||
it(test, async () => {
|
||||
const innerDir = resolve(dir, test)
|
||||
const input = require(resolve(innerDir, 'input.js')).default
|
||||
const expected = readMetadata.sync(resolve(innerDir, 'output.yaml'))
|
||||
const expected = await readYaml(resolve(innerDir, 'output.yaml'))
|
||||
const serialized = Raw.serialize(input, { terse: true })
|
||||
strictEqual(strip(serialized), expected)
|
||||
})
|
||||
|
@ -1,5 +0,0 @@
|
||||
|
||||
import './serializers'
|
||||
import './schema'
|
||||
import './rendering'
|
||||
import './transforms'
|
@ -1,10 +1,4 @@
|
||||
|
||||
nodes:
|
||||
- kind: block
|
||||
type: paragraph
|
||||
nodes:
|
||||
- kind: text
|
||||
text: word
|
||||
nodes:
|
||||
- kind: block
|
||||
type: paragraph
|
||||
|
@ -1,15 +1,4 @@
|
||||
|
||||
nodes:
|
||||
- kind: block
|
||||
type: paragraph
|
||||
nodes:
|
||||
- kind: text
|
||||
text: word
|
||||
- kind: block
|
||||
type: image
|
||||
nodes:
|
||||
- kind: text
|
||||
text: ""
|
||||
nodes:
|
||||
- kind: block
|
||||
type: paragraph
|
||||
|
@ -1,10 +1,4 @@
|
||||
|
||||
nodes:
|
||||
- kind: block
|
||||
type: paragraph
|
||||
nodes:
|
||||
- kind: text
|
||||
text: word
|
||||
nodes:
|
||||
- kind: block
|
||||
type: paragraph
|
||||
|
@ -1,15 +1,4 @@
|
||||
|
||||
nodes:
|
||||
- kind: block
|
||||
type: image
|
||||
nodes:
|
||||
- kind: text
|
||||
text: ""
|
||||
- kind: block
|
||||
type: paragraph
|
||||
nodes:
|
||||
- kind: text
|
||||
text: word
|
||||
nodes:
|
||||
- kind: block
|
||||
type: paragraph
|
||||
|
@ -1,6 +1,6 @@
|
||||
|
||||
import fs from 'fs'
|
||||
import readMetadata from 'read-metadata'
|
||||
import fs from 'fs-promise'
|
||||
import readYaml from 'read-yaml-promise'
|
||||
import strip from '../helpers/strip-dynamic'
|
||||
import toCamel from 'to-camel-case'
|
||||
import { Raw } from '../..'
|
||||
@ -11,7 +11,7 @@ import { resolve } from 'path'
|
||||
* Tests.
|
||||
*/
|
||||
|
||||
describe('transforms', () => {
|
||||
describe('transforms', async () => {
|
||||
describe('by-key', () => {
|
||||
const dir = resolve(__dirname, './fixtures/by-key')
|
||||
const transforms = fs.readdirSync(dir)
|
||||
@ -26,11 +26,11 @@ describe('transforms', () => {
|
||||
for (const test of tests) {
|
||||
if (test[0] == '.') continue
|
||||
|
||||
it(test, () => {
|
||||
it(test, async () => {
|
||||
const testDir = resolve(transformDir, test)
|
||||
const fn = require(testDir).default
|
||||
const input = readMetadata.sync(resolve(testDir, 'input.yaml'))
|
||||
const expected = readMetadata.sync(resolve(testDir, 'output.yaml'))
|
||||
const input = await readYaml(resolve(testDir, 'input.yaml'))
|
||||
const expected = await readYaml(resolve(testDir, 'output.yaml'))
|
||||
|
||||
let state = Raw.deserialize(input, { terse: true })
|
||||
state = fn(state)
|
||||
@ -56,10 +56,10 @@ describe('transforms', () => {
|
||||
for (const test of tests) {
|
||||
if (test[0] == '.') continue
|
||||
|
||||
it(test, () => {
|
||||
it(test, async () => {
|
||||
const testDir = resolve(transformDir, test)
|
||||
const fn = require(testDir).default
|
||||
const input = readMetadata.sync(resolve(testDir, 'input.yaml'))
|
||||
const input = await readYaml(resolve(testDir, 'input.yaml'))
|
||||
const state = Raw.deserialize(input, { terse: true })
|
||||
fn(state)
|
||||
})
|
||||
@ -82,11 +82,11 @@ describe('transforms', () => {
|
||||
for (const test of tests) {
|
||||
if (test[0] == '.') continue
|
||||
|
||||
it(test, () => {
|
||||
it(test, async () => {
|
||||
const testDir = resolve(transformDir, test)
|
||||
const fn = require(testDir).default
|
||||
const input = readMetadata.sync(resolve(testDir, 'input.yaml'))
|
||||
const expected = readMetadata.sync(resolve(testDir, 'output.yaml'))
|
||||
const input = await readYaml(resolve(testDir, 'input.yaml'))
|
||||
const expected = await readYaml(resolve(testDir, 'output.yaml'))
|
||||
|
||||
let state = Raw.deserialize(input, { terse: true })
|
||||
state = fn(state)
|
||||
@ -112,11 +112,11 @@ describe('transforms', () => {
|
||||
for (const test of tests) {
|
||||
if (test[0] == '.') continue
|
||||
|
||||
it(test, () => {
|
||||
it(test, async () => {
|
||||
const testDir = resolve(transformDir, test)
|
||||
const fn = require(testDir).default
|
||||
const input = readMetadata.sync(resolve(testDir, 'input.yaml'))
|
||||
const expected = readMetadata.sync(resolve(testDir, 'output.yaml'))
|
||||
const input = await readYaml(resolve(testDir, 'input.yaml'))
|
||||
const expected = await readYaml(resolve(testDir, 'output.yaml'))
|
||||
|
||||
let state = Raw.deserialize(input, { terse: true })
|
||||
state = fn(state)
|
||||
@ -142,11 +142,11 @@ describe('transforms', () => {
|
||||
for (const test of tests) {
|
||||
if (test[0] == '.') continue
|
||||
|
||||
it(test, () => {
|
||||
it(test, async () => {
|
||||
const testDir = resolve(transformDir, test)
|
||||
const fn = require(testDir).default
|
||||
const input = readMetadata.sync(resolve(testDir, 'input.yaml'))
|
||||
const expected = readMetadata.sync(resolve(testDir, 'output.yaml'))
|
||||
const input = await readYaml(resolve(testDir, 'input.yaml'))
|
||||
const expected = await readYaml(resolve(testDir, 'output.yaml'))
|
||||
|
||||
let state = Raw.deserialize(input, { terse: true })
|
||||
state = fn(state)
|
||||
|
Loading…
x
Reference in New Issue
Block a user