mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-11 01:33:58 +02:00
Refactor tests (#2021)
* add slate-dev-test-utils, refactor tests to use fixtures util * cleanup top-level test files * tweaks
This commit is contained in:
10
.eslintrc
10
.eslintrc
@@ -155,5 +155,13 @@
|
|||||||
{ "blankLine": "always", "prev": "*", "next": "multiline-block-like" },
|
{ "blankLine": "always", "prev": "*", "next": "multiline-block-like" },
|
||||||
{ "blankLine": "any", "prev": "case", "next": "case" }
|
{ "blankLine": "any", "prev": "case", "next": "case" }
|
||||||
]
|
]
|
||||||
}
|
},
|
||||||
|
"overrides": [
|
||||||
|
{
|
||||||
|
"files": "**/test/**/*.js",
|
||||||
|
"rules": {
|
||||||
|
"import/no-extraneous-dependencies": false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
@@ -66,6 +66,7 @@
|
|||||||
"rollup-plugin-uglify": "^3.0.0",
|
"rollup-plugin-uglify": "^3.0.0",
|
||||||
"slate-collapse-on-escape": "^0.6.0",
|
"slate-collapse-on-escape": "^0.6.0",
|
||||||
"slate-dev-benchmark": "*",
|
"slate-dev-benchmark": "*",
|
||||||
|
"slate-dev-test-utils": "*",
|
||||||
"slate-soft-break": "^0.6.0",
|
"slate-soft-break": "^0.6.0",
|
||||||
"source-map-loader": "^0.2.3",
|
"source-map-loader": "^0.2.3",
|
||||||
"source-map-support": "^0.4.0",
|
"source-map-support": "^0.4.0",
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "slate-dev-benchmark",
|
"name": "slate-dev-benchmark",
|
||||||
"description": "A simple, development-only benchmark for Slate",
|
"description": "INTERNAL: A development-only benchmark tool for Slate's core.",
|
||||||
"version": "0.0.3",
|
"version": "0.0.3",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"repository": "git://github.com/ianstormtaylor/slate.git",
|
"repository": "git://github.com/ianstormtaylor/slate.git",
|
||||||
@@ -10,8 +10,5 @@
|
|||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"clean": "rm -rf ./dist ./lib ./node_modules"
|
"clean": "rm -rf ./dist ./lib ./node_modules"
|
||||||
},
|
}
|
||||||
"keywords": [
|
|
||||||
"slate"
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "slate-dev-environment",
|
"name": "slate-dev-environment",
|
||||||
"description": "Detect browser and OS environments in core Slate packages",
|
"description": "INTERNAL: A set of environment-related constants for Slate's core.",
|
||||||
"version": "0.1.3",
|
"version": "0.1.3",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"repository": "git://github.com/ianstormtaylor/slate.git",
|
"repository": "git://github.com/ianstormtaylor/slate.git",
|
||||||
@@ -12,13 +12,10 @@
|
|||||||
"dist/",
|
"dist/",
|
||||||
"lib/"
|
"lib/"
|
||||||
],
|
],
|
||||||
"scripts": {
|
|
||||||
"clean": "rm -rf ./dist ./lib ./node_modules"
|
|
||||||
},
|
|
||||||
"keywords": [
|
|
||||||
"slate"
|
|
||||||
],
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"is-in-browser": "^1.1.3"
|
"is-in-browser": "^1.1.3"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"clean": "rm -rf ./dist ./lib ./node_modules"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "slate-dev-logger",
|
"name": "slate-dev-logger",
|
||||||
"description": "A simple, development-only logger for Slate.",
|
"description": "INTERNAL: A simple, development-only logger for Slate.",
|
||||||
"version": "0.1.41",
|
"version": "0.1.41",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"repository": "git://github.com/ianstormtaylor/slate.git",
|
"repository": "git://github.com/ianstormtaylor/slate.git",
|
||||||
@@ -17,8 +17,5 @@
|
|||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"clean": "rm -rf ./dist ./lib ./node_modules"
|
"clean": "rm -rf ./dist ./lib ./node_modules"
|
||||||
},
|
}
|
||||||
"keywords": [
|
|
||||||
"slate"
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
|
1
packages/slate-dev-test-utils/Readme.md
Normal file
1
packages/slate-dev-test-utils/Readme.md
Normal file
@@ -0,0 +1 @@
|
|||||||
|
This package contains a set of testing utilities used by Slate's other core packages for writing their tests.
|
18
packages/slate-dev-test-utils/package.json
Normal file
18
packages/slate-dev-test-utils/package.json
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
{
|
||||||
|
"name": "slate-dev-test-utils",
|
||||||
|
"description": "INTERNAL: A set of utils for Slate's core tests.",
|
||||||
|
"version": "0.0.0",
|
||||||
|
"license": "MIT",
|
||||||
|
"repository": "git://github.com/ianstormtaylor/slate.git",
|
||||||
|
"main": "src/index.js",
|
||||||
|
"files": [
|
||||||
|
"dist/",
|
||||||
|
"lib/"
|
||||||
|
],
|
||||||
|
"peerDependencies": {
|
||||||
|
"slate": ">=0.35.0"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"clean": "rm -rf ./dist ./lib ./node_modules"
|
||||||
|
}
|
||||||
|
}
|
59
packages/slate-dev-test-utils/src/index.js
Normal file
59
packages/slate-dev-test-utils/src/index.js
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
import fs from 'fs'
|
||||||
|
import { basename, extname, resolve } from 'path'
|
||||||
|
import { KeyUtils } from 'slate'
|
||||||
|
|
||||||
|
export const fixtures = (...args) => {
|
||||||
|
let fn = args.pop()
|
||||||
|
let options = { skip: false }
|
||||||
|
|
||||||
|
if (typeof fn !== 'function') {
|
||||||
|
options = fn
|
||||||
|
fn = args.pop()
|
||||||
|
}
|
||||||
|
|
||||||
|
const path = resolve(...args)
|
||||||
|
const files = fs.readdirSync(path)
|
||||||
|
const dir = basename(path)
|
||||||
|
const d = options.skip ? describe.skip : describe
|
||||||
|
|
||||||
|
d(dir, () => {
|
||||||
|
for (const file of files) {
|
||||||
|
const p = resolve(path, file)
|
||||||
|
const stat = fs.statSync(p)
|
||||||
|
|
||||||
|
if (stat.isDirectory()) {
|
||||||
|
fixtures(path, file, fn)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
stat.isFile() &&
|
||||||
|
file.endsWith('.js') &&
|
||||||
|
!file.startsWith('.') &&
|
||||||
|
// Ignoring `index.js` files allows us to use the fixtures directly
|
||||||
|
// from the top-level directory itself, instead of only children.
|
||||||
|
file !== 'index.js'
|
||||||
|
) {
|
||||||
|
const name = basename(file, extname(file))
|
||||||
|
|
||||||
|
// This needs to be a non-arrow function to use `this.skip()`.
|
||||||
|
it(name, function() {
|
||||||
|
// Ensure that the key generator is reset. We have to do this here
|
||||||
|
// because the `require` call will create the Slate objects.
|
||||||
|
KeyUtils.resetGenerator()
|
||||||
|
const module = require(p)
|
||||||
|
|
||||||
|
if (module.skip) {
|
||||||
|
this.skip()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
fn({ name, path, module })
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
fixtures.skip = (...args) => {
|
||||||
|
fixtures(...args, { skip: true })
|
||||||
|
}
|
0
packages/slate-dev-test-utils/test/index.js
Normal file
0
packages/slate-dev-test-utils/test/index.js
Normal file
@@ -1,64 +1,25 @@
|
|||||||
/**
|
|
||||||
* Dependencies.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import Html from '..'
|
import Html from '..'
|
||||||
import assert from 'assert'
|
import assert from 'assert'
|
||||||
import fs from 'fs'
|
import { JSDOM } from 'jsdom'
|
||||||
import { JSDOM } from 'jsdom' // eslint-disable-line import/no-extraneous-dependencies
|
import { Value } from 'slate'
|
||||||
import { Value, KeyUtils } from 'slate'
|
import { fixtures } from 'slate-dev-test-utils'
|
||||||
import { basename, extname, resolve } from 'path'
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reset Slate's internal key generator state before each text.
|
|
||||||
*/
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
KeyUtils.resetGenerator()
|
|
||||||
})
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests.
|
|
||||||
*/
|
|
||||||
|
|
||||||
describe('slate-html-serializer', () => {
|
describe('slate-html-serializer', () => {
|
||||||
describe('deserialize()', () => {
|
fixtures(__dirname, 'deserialize', ({ module }) => {
|
||||||
const dir = resolve(__dirname, './deserialize')
|
const { input, output, config, options } = module
|
||||||
const tests = fs
|
const html = new Html({ parseHtml: JSDOM.fragment, ...config })
|
||||||
.readdirSync(dir)
|
const value = html.deserialize(input, options)
|
||||||
.filter(t => t[0] != '.')
|
const actual = Value.isValue(value) ? value.toJSON() : value
|
||||||
.map(t => basename(t, extname(t)))
|
const expected = Value.isValue(output) ? output.toJSON() : output
|
||||||
|
assert.deepEqual(actual, expected)
|
||||||
for (const test of tests) {
|
|
||||||
it(test, async () => {
|
|
||||||
const module = require(resolve(dir, test))
|
|
||||||
const { input, output, config, options } = module
|
|
||||||
const html = new Html({ parseHtml: JSDOM.fragment, ...config })
|
|
||||||
const value = html.deserialize(input, options)
|
|
||||||
const actual = Value.isValue(value) ? value.toJSON() : value
|
|
||||||
const expected = Value.isValue(output) ? output.toJSON() : output
|
|
||||||
assert.deepEqual(actual, expected)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('serialize()', () => {
|
fixtures(__dirname, 'serialize', ({ module }) => {
|
||||||
const dir = resolve(__dirname, './serialize')
|
const { input, output, rules, options } = module
|
||||||
const tests = fs
|
const html = new Html({ rules, parseHtml: JSDOM.fragment })
|
||||||
.readdirSync(dir)
|
const string = html.serialize(input, options)
|
||||||
.filter(t => t[0] != '.')
|
const actual = string
|
||||||
.map(t => basename(t, extname(t)))
|
const expected = output
|
||||||
|
assert.deepEqual(actual, expected)
|
||||||
for (const test of tests) {
|
|
||||||
it(test, async () => {
|
|
||||||
const module = require(resolve(dir, test))
|
|
||||||
const { input, output, rules, options } = module
|
|
||||||
const html = new Html({ rules, parseHtml: JSDOM.fragment })
|
|
||||||
const string = html.serialize(input, options)
|
|
||||||
const actual = string
|
|
||||||
const expected = output
|
|
||||||
assert.deepEqual(actual, expected)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@@ -1,56 +1,29 @@
|
|||||||
import assert from 'assert'
|
import assert from 'assert'
|
||||||
import fs from 'fs'
|
import { Value } from 'slate'
|
||||||
import { Value, KeyUtils } from 'slate'
|
import { fixtures } from 'slate-dev-test-utils'
|
||||||
import { basename, extname, resolve } from 'path'
|
|
||||||
|
|
||||||
beforeEach(KeyUtils.resetGenerator)
|
|
||||||
|
|
||||||
describe('slate-hyperscript', () => {
|
describe('slate-hyperscript', () => {
|
||||||
const dir = resolve(__dirname, './fixtures')
|
fixtures(__dirname, 'fixtures', ({ module }) => {
|
||||||
const tests = fs
|
const { input, output, options } = module
|
||||||
.readdirSync(dir)
|
const actual = input.toJSON(options)
|
||||||
.filter(t => t[0] != '.')
|
const expected = Value.isValue(output) ? output.toJSON() : output
|
||||||
.map(t => basename(t, extname(t)))
|
assert.deepEqual(actual, expected)
|
||||||
|
})
|
||||||
|
|
||||||
for (const test of tests) {
|
fixtures.skip(__dirname, 'decorations', ({ module }) => {
|
||||||
it(test, async () => {
|
const { input, output, expectDecorations } = module
|
||||||
const module = require(resolve(dir, test))
|
const actual = input.toJSON()
|
||||||
const { input, output, options } = module
|
const expected = Value.isValue(output) ? output.toJSON() : output
|
||||||
const actual = input.toJSON(options)
|
assert.deepEqual(actual, expected)
|
||||||
const expected = Value.isValue(output) ? output.toJSON() : output
|
|
||||||
assert.deepEqual(actual, expected)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
describe.skip('decorations', () => {
|
expectDecorations.forEach((decoration, i) => {
|
||||||
const decDir = resolve(__dirname, './decorations')
|
Object.keys(decoration).forEach(prop => {
|
||||||
const decTests = fs
|
assert.deepEqual(
|
||||||
.readdirSync(decDir)
|
decoration[prop],
|
||||||
.filter(t => t[0] != '.')
|
input.decorations.toJS()[i][prop],
|
||||||
.map(t => basename(t, extname(t)))
|
`decoration ${i} had incorrect prop: ${prop}`
|
||||||
|
)
|
||||||
for (const test of decTests) {
|
|
||||||
it(test, async () => {
|
|
||||||
const module = require(resolve(decDir, test))
|
|
||||||
const { input, output, expectDecorations } = module
|
|
||||||
|
|
||||||
// ensure deserialization was okay
|
|
||||||
const actual = input.toJSON()
|
|
||||||
const expected = Value.isValue(output) ? output.toJSON() : output
|
|
||||||
assert.deepEqual(actual, expected)
|
|
||||||
|
|
||||||
// ensure expected properties of decorations match
|
|
||||||
// note: they are expected to match order in test result
|
|
||||||
expectDecorations.forEach((decoration, i) => {
|
|
||||||
Object.keys(decoration).forEach(prop => {
|
|
||||||
assert.deepEqual(
|
|
||||||
decoration[prop],
|
|
||||||
input.decorations.toJS()[i][prop],
|
|
||||||
`decoration ${i} had incorrect prop: ${prop}`
|
|
||||||
)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
}
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@@ -1,47 +1,22 @@
|
|||||||
import Plain from '..'
|
import Plain from '..'
|
||||||
import assert from 'assert'
|
import assert from 'assert'
|
||||||
import fs from 'fs'
|
import { Value } from 'slate'
|
||||||
import { Value, KeyUtils } from 'slate'
|
import { fixtures } from 'slate-dev-test-utils'
|
||||||
import { basename, extname, resolve } from 'path'
|
|
||||||
|
|
||||||
beforeEach(KeyUtils.resetGenerator)
|
|
||||||
|
|
||||||
describe('slate-plain-serializer', () => {
|
describe('slate-plain-serializer', () => {
|
||||||
describe('deserialize()', () => {
|
fixtures(__dirname, 'deserialize', ({ module }) => {
|
||||||
const dir = resolve(__dirname, './deserialize')
|
const { input, output, options } = module
|
||||||
const tests = fs
|
const value = Plain.deserialize(input, options)
|
||||||
.readdirSync(dir)
|
const actual = Value.isValue(value) ? value.toJSON() : value
|
||||||
.filter(t => t[0] != '.')
|
const expected = Value.isValue(output) ? output.toJSON() : output
|
||||||
.map(t => basename(t, extname(t)))
|
assert.deepEqual(actual, expected)
|
||||||
|
|
||||||
for (const test of tests) {
|
|
||||||
it(test, async () => {
|
|
||||||
const module = require(resolve(dir, test))
|
|
||||||
const { input, output, options } = module
|
|
||||||
const value = Plain.deserialize(input, options)
|
|
||||||
const actual = Value.isValue(value) ? value.toJSON() : value
|
|
||||||
const expected = Value.isValue(output) ? output.toJSON() : output
|
|
||||||
assert.deepEqual(actual, expected)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('serialize()', () => {
|
fixtures(__dirname, 'serialize', ({ module }) => {
|
||||||
const dir = resolve(__dirname, './serialize')
|
const { input, output, options } = module
|
||||||
const tests = fs
|
const string = Plain.serialize(input, options)
|
||||||
.readdirSync(dir)
|
const actual = string
|
||||||
.filter(t => t[0] != '.')
|
const expected = output
|
||||||
.map(t => basename(t, extname(t)))
|
assert.deepEqual(actual, expected)
|
||||||
|
|
||||||
for (const test of tests) {
|
|
||||||
it(test, async () => {
|
|
||||||
const module = require(resolve(dir, test))
|
|
||||||
const { input, output, options } = module
|
|
||||||
const string = Plain.serialize(input, options)
|
|
||||||
const actual = string
|
|
||||||
const expected = output
|
|
||||||
assert.deepEqual(actual, expected)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@@ -1,9 +1,42 @@
|
|||||||
import { KeyUtils } from 'slate'
|
import AfterPlugin from '../src/plugins/after'
|
||||||
|
import assert from 'assert'
|
||||||
beforeEach(KeyUtils.resetGenerator)
|
import BeforePlugin from '../src/plugins/before'
|
||||||
|
import clean from './helpers/clean'
|
||||||
|
import React from 'react'
|
||||||
|
import ReactDOM from 'react-dom/server'
|
||||||
|
import Simulator from 'slate-simulator'
|
||||||
|
import { Editor } from '..'
|
||||||
|
import { fixtures } from 'slate-dev-test-utils'
|
||||||
|
import { JSDOM } from 'jsdom'
|
||||||
|
|
||||||
describe('slate-react', () => {
|
describe('slate-react', () => {
|
||||||
require('./plugins')
|
fixtures.skip(__dirname, 'plugins', ({ module }) => {
|
||||||
require('./rendering')
|
const { input, output, props = {} } = module
|
||||||
require('./utils')
|
const fn = module.default
|
||||||
|
const plugins = [BeforePlugin(props), AfterPlugin(props)]
|
||||||
|
const simulator = new Simulator({ plugins, value: input })
|
||||||
|
fn(simulator)
|
||||||
|
|
||||||
|
const actual = simulator.value.toJSON({ preserveSelection: true })
|
||||||
|
const expected = output.toJSON({ preserveSelection: true })
|
||||||
|
assert.deepEqual(actual, expected)
|
||||||
|
})
|
||||||
|
|
||||||
|
fixtures(__dirname, 'rendering/fixtures', ({ module }) => {
|
||||||
|
const { value, output, props } = module
|
||||||
|
const p = {
|
||||||
|
value,
|
||||||
|
onChange() {},
|
||||||
|
...(props || {}),
|
||||||
|
}
|
||||||
|
|
||||||
|
const string = ReactDOM.renderToStaticMarkup(<Editor {...p} />)
|
||||||
|
const dom = JSDOM.fragment(output)
|
||||||
|
const expected = dom.firstChild.outerHTML
|
||||||
|
.trim()
|
||||||
|
.replace(/\n/gm, '')
|
||||||
|
.replace(/>\s*</g, '><')
|
||||||
|
|
||||||
|
assert.equal(clean(string), expected)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
@@ -1,45 +0,0 @@
|
|||||||
import AfterPlugin from '../../src/plugins/after'
|
|
||||||
import BeforePlugin from '../../src/plugins/before'
|
|
||||||
import Simulator from 'slate-simulator'
|
|
||||||
import assert from 'assert'
|
|
||||||
import fs from 'fs'
|
|
||||||
import toCamel from 'to-camel-case' // eslint-disable-line import/no-extraneous-dependencies
|
|
||||||
import { basename, extname, resolve } from 'path'
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests.
|
|
||||||
*/
|
|
||||||
|
|
||||||
describe('plugins', () => {
|
|
||||||
describe.skip('core', () => {
|
|
||||||
const dir = resolve(__dirname, 'core')
|
|
||||||
const events = fs
|
|
||||||
.readdirSync(dir)
|
|
||||||
.filter(e => e[0] != '.' && e != 'index.js')
|
|
||||||
|
|
||||||
for (const event of events) {
|
|
||||||
describe(`${toCamel(event)}`, () => {
|
|
||||||
const testDir = resolve(dir, event)
|
|
||||||
const tests = fs
|
|
||||||
.readdirSync(testDir)
|
|
||||||
.filter(t => t[0] != '.' && !!~t.indexOf('.js'))
|
|
||||||
.map(t => basename(t, extname(t)))
|
|
||||||
|
|
||||||
for (const test of tests) {
|
|
||||||
it(test, async () => {
|
|
||||||
const module = require(resolve(testDir, test))
|
|
||||||
const { input, output, props = {} } = module
|
|
||||||
const fn = module.default
|
|
||||||
const plugins = [BeforePlugin(props), AfterPlugin(props)]
|
|
||||||
const simulator = new Simulator({ plugins, value: input })
|
|
||||||
fn(simulator)
|
|
||||||
|
|
||||||
const actual = simulator.value.toJSON({ preserveSelection: true })
|
|
||||||
const expected = output.toJSON({ preserveSelection: true })
|
|
||||||
assert.deepEqual(actual, expected)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
|
@@ -1,41 +0,0 @@
|
|||||||
import React from 'react'
|
|
||||||
import ReactDOM from 'react-dom/server'
|
|
||||||
import assert from 'assert'
|
|
||||||
import clean from '../helpers/clean'
|
|
||||||
import fs from 'fs-promise' // eslint-disable-line import/no-extraneous-dependencies
|
|
||||||
import { JSDOM } from 'jsdom' // eslint-disable-line import/no-extraneous-dependencies
|
|
||||||
import { Editor } from '../..'
|
|
||||||
import { basename, extname, resolve } from 'path'
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests.
|
|
||||||
*/
|
|
||||||
|
|
||||||
describe('rendering', () => {
|
|
||||||
const dir = resolve(__dirname, './fixtures')
|
|
||||||
const tests = fs
|
|
||||||
.readdirSync(dir)
|
|
||||||
.filter(t => t[0] != '.' && !!~t.indexOf('.js'))
|
|
||||||
.map(t => basename(t, extname(t)))
|
|
||||||
|
|
||||||
for (const test of tests) {
|
|
||||||
it(test, async () => {
|
|
||||||
const module = require(resolve(dir, test))
|
|
||||||
const { value, output, props } = module
|
|
||||||
const p = {
|
|
||||||
value,
|
|
||||||
onChange() {},
|
|
||||||
...(props || {}),
|
|
||||||
}
|
|
||||||
|
|
||||||
const string = ReactDOM.renderToStaticMarkup(<Editor {...p} />)
|
|
||||||
const dom = JSDOM.fragment(output)
|
|
||||||
const expected = dom.firstChild.outerHTML
|
|
||||||
.trim()
|
|
||||||
.replace(/\n/gm, '')
|
|
||||||
.replace(/>\s*</g, '><')
|
|
||||||
|
|
||||||
assert.equal(clean(string), expected)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
|
@@ -1,93 +0,0 @@
|
|||||||
/** @jsx h */
|
|
||||||
|
|
||||||
import { List } from 'immutable'
|
|
||||||
import assert from 'assert'
|
|
||||||
|
|
||||||
import h from '../helpers/h'
|
|
||||||
|
|
||||||
import getChildrenDecorations from '../../src/utils/get-children-decorations'
|
|
||||||
|
|
||||||
const value = (
|
|
||||||
<value>
|
|
||||||
<document key="a">
|
|
||||||
<paragraph key="b">
|
|
||||||
<text key="c">First line</text>
|
|
||||||
</paragraph>
|
|
||||||
<paragraph key="d">
|
|
||||||
<text key="e">Second line</text>
|
|
||||||
</paragraph>
|
|
||||||
</document>
|
|
||||||
</value>
|
|
||||||
)
|
|
||||||
|
|
||||||
const { document } = value
|
|
||||||
const [paragraphB] = document.nodes.toArray()
|
|
||||||
|
|
||||||
describe('getChildrenDecorations', () => {
|
|
||||||
it('should return the child list when no decorations are given', () => {
|
|
||||||
const actual = getChildrenDecorations(document, List())
|
|
||||||
|
|
||||||
const expected = [[], []]
|
|
||||||
|
|
||||||
assert.deepEqual(actual.map(l => l.toArray()), expected)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('should wrap a block with the range it contains', () => {
|
|
||||||
const decoration1 = {
|
|
||||||
startKey: 'c',
|
|
||||||
startOffset: 1,
|
|
||||||
endKey: 'c',
|
|
||||||
endOffset: 2,
|
|
||||||
decoration: 'd1',
|
|
||||||
}
|
|
||||||
|
|
||||||
const actual = getChildrenDecorations(document, List([decoration1]))
|
|
||||||
|
|
||||||
const expected = [[decoration1], []]
|
|
||||||
|
|
||||||
assert.deepEqual(actual.map(l => l.toArray()), expected)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('should sort two decorations inside a node', () => {
|
|
||||||
const decoration1 = {
|
|
||||||
startKey: 'c',
|
|
||||||
startOffset: 1,
|
|
||||||
endKey: 'c',
|
|
||||||
endOffset: 2,
|
|
||||||
decoration: 'd1',
|
|
||||||
}
|
|
||||||
|
|
||||||
const decoration2 = {
|
|
||||||
startKey: 'c',
|
|
||||||
startOffset: 1,
|
|
||||||
endKey: 'e',
|
|
||||||
endOffset: 2,
|
|
||||||
decoration: 'd2',
|
|
||||||
}
|
|
||||||
|
|
||||||
const actual = getChildrenDecorations(
|
|
||||||
document,
|
|
||||||
List([decoration1, decoration2])
|
|
||||||
)
|
|
||||||
|
|
||||||
const expected = [[decoration1, decoration2], [decoration2]]
|
|
||||||
|
|
||||||
assert.deepEqual(actual.map(l => l.toArray()), expected)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('should sort decorations outside the node', () => {
|
|
||||||
const decoration1 = {
|
|
||||||
startKey: 'c',
|
|
||||||
startOffset: 1,
|
|
||||||
endKey: 'e',
|
|
||||||
endOffset: 2,
|
|
||||||
decoration: 'd1',
|
|
||||||
}
|
|
||||||
|
|
||||||
const actual = getChildrenDecorations(paragraphB, List([decoration1]))
|
|
||||||
|
|
||||||
const expected = [[decoration1]]
|
|
||||||
|
|
||||||
assert.deepEqual(actual.map(l => l.toArray()), expected)
|
|
||||||
})
|
|
||||||
})
|
|
@@ -1,7 +0,0 @@
|
|||||||
import { KeyUtils } from 'slate'
|
|
||||||
|
|
||||||
beforeEach(KeyUtils.resetGenerator)
|
|
||||||
|
|
||||||
describe('utils', () => {
|
|
||||||
// require('./get-children-decorations')
|
|
||||||
})
|
|
@@ -28,7 +28,8 @@
|
|||||||
"react": ">=0.14.0"
|
"react": ">=0.14.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"slate-hyperscript": "^0.6.2"
|
"slate-hyperscript": "^0.6.2",
|
||||||
|
"slate-dev-test-utils": "*"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"clean": "rm -rf ./dist ./lib ./node_modules"
|
"clean": "rm -rf ./dist ./lib ./node_modules"
|
||||||
|
@@ -1,48 +0,0 @@
|
|||||||
import assert from 'assert'
|
|
||||||
import fs from 'fs-promise' // eslint-disable-line import/no-extraneous-dependencies
|
|
||||||
import toCamel from 'to-camel-case' // eslint-disable-line import/no-extraneous-dependencies
|
|
||||||
import { basename, extname, resolve } from 'path'
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests.
|
|
||||||
*/
|
|
||||||
|
|
||||||
describe('changes', async () => {
|
|
||||||
const dir = resolve(__dirname)
|
|
||||||
const categories = fs
|
|
||||||
.readdirSync(dir)
|
|
||||||
.filter(c => c[0] != '.' && c != 'index.js')
|
|
||||||
|
|
||||||
for (const category of categories) {
|
|
||||||
describe(category, () => {
|
|
||||||
const categoryDir = resolve(dir, category)
|
|
||||||
const methods = fs.readdirSync(categoryDir).filter(c => c[0] != '.')
|
|
||||||
|
|
||||||
for (const method of methods) {
|
|
||||||
describe(toCamel(method), () => {
|
|
||||||
const testDir = resolve(categoryDir, method)
|
|
||||||
const tests = fs
|
|
||||||
.readdirSync(testDir)
|
|
||||||
.filter(t => t[0] != '.' && !!~t.indexOf('.js'))
|
|
||||||
.map(t => basename(t, extname(t)))
|
|
||||||
|
|
||||||
for (const test of tests) {
|
|
||||||
const module = require(resolve(testDir, test))
|
|
||||||
const { input, output, skip } = module
|
|
||||||
const fn = module.default
|
|
||||||
const t = skip ? it.skip : it
|
|
||||||
|
|
||||||
t(test, async () => {
|
|
||||||
const change = input.change()
|
|
||||||
fn(change)
|
|
||||||
const opts = { preserveSelection: true, preserveData: true }
|
|
||||||
const actual = change.value.toJSON(opts)
|
|
||||||
const expected = output.toJSON(opts)
|
|
||||||
assert.deepEqual(actual, expected)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
|
@@ -1,11 +1,5 @@
|
|||||||
import { createHyperscript } from 'slate-hyperscript'
|
import { createHyperscript } from 'slate-hyperscript'
|
||||||
|
|
||||||
/**
|
|
||||||
* Define a hyperscript.
|
|
||||||
*
|
|
||||||
* @type {Function}
|
|
||||||
*/
|
|
||||||
|
|
||||||
const h = createHyperscript({
|
const h = createHyperscript({
|
||||||
blocks: {
|
blocks: {
|
||||||
line: 'line',
|
line: 'line',
|
||||||
@@ -39,10 +33,4 @@ const h = createHyperscript({
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
/**
|
|
||||||
* Export.
|
|
||||||
*
|
|
||||||
* @type {Function}
|
|
||||||
*/
|
|
||||||
|
|
||||||
export default h
|
export default h
|
||||||
|
@@ -1,39 +0,0 @@
|
|||||||
import assert from 'assert'
|
|
||||||
import fs from 'fs'
|
|
||||||
import { basename, extname, resolve } from 'path'
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests.
|
|
||||||
*/
|
|
||||||
|
|
||||||
describe('history', async () => {
|
|
||||||
const dir = resolve(__dirname)
|
|
||||||
const methods = fs
|
|
||||||
.readdirSync(dir)
|
|
||||||
.filter(d => d[0] != '.' && d != 'index.js')
|
|
||||||
|
|
||||||
for (const method of methods) {
|
|
||||||
describe(method, () => {
|
|
||||||
const testDir = resolve(dir, method)
|
|
||||||
const tests = fs
|
|
||||||
.readdirSync(testDir)
|
|
||||||
.filter(f => f[0] != '.' && !!~f.indexOf('.js'))
|
|
||||||
.map(f => basename(f, extname(f)))
|
|
||||||
|
|
||||||
for (const test of tests) {
|
|
||||||
const module = require(resolve(testDir, test))
|
|
||||||
const { input, output, skip } = module
|
|
||||||
const fn = module.default
|
|
||||||
const t = skip ? it.skip : it
|
|
||||||
|
|
||||||
t(test, async () => {
|
|
||||||
const next = fn(input)
|
|
||||||
const opts = { preserveSelection: true, preserveData: true }
|
|
||||||
const actual = next.toJSON(opts)
|
|
||||||
const expected = output.toJSON(opts)
|
|
||||||
assert.deepEqual(actual, expected)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
|
@@ -1,26 +1,116 @@
|
|||||||
/**
|
import assert from 'assert'
|
||||||
* Dependencies.
|
import { fixtures } from 'slate-dev-test-utils'
|
||||||
*/
|
import { Node, Schema, Value } from '..'
|
||||||
|
|
||||||
import { KeyUtils } from '..'
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests.
|
|
||||||
*/
|
|
||||||
|
|
||||||
describe('slate', () => {
|
describe('slate', () => {
|
||||||
require('./serializers')
|
fixtures(__dirname, 'models/leaf', ({ module }) => {
|
||||||
require('./schema')
|
const { input, output } = module
|
||||||
require('./changes')
|
const fn = module.default
|
||||||
require('./history')
|
const actual = fn(input).toJSON()
|
||||||
require('./operations')
|
const expected = output.toJSON()
|
||||||
require('./models')
|
assert.deepEqual(actual, expected)
|
||||||
})
|
})
|
||||||
|
|
||||||
/**
|
fixtures(__dirname, 'models/text', ({ module }) => {
|
||||||
* Reset Slate's internal key generator state before each text.
|
const { input, output } = module
|
||||||
*/
|
const fn = module.default
|
||||||
|
const actual = fn(input).toJSON()
|
||||||
|
const expected = output.toJSON()
|
||||||
|
assert.deepEqual(actual, expected)
|
||||||
|
})
|
||||||
|
|
||||||
beforeEach(() => {
|
fixtures(__dirname, 'models/node', ({ module }) => {
|
||||||
KeyUtils.resetGenerator()
|
const { input, output } = module
|
||||||
|
const fn = module.default
|
||||||
|
let actual = fn(input)
|
||||||
|
let expected = output
|
||||||
|
|
||||||
|
if (Node.isNode(actual)) {
|
||||||
|
actual = actual.toJSON()
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Node.isNode(expected)) {
|
||||||
|
expected = expected.toJSON()
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.deepEqual(actual, expected)
|
||||||
|
})
|
||||||
|
|
||||||
|
fixtures(__dirname, 'models/change', ({ module }) => {
|
||||||
|
const { input, output, schema, flags, customChange } = module
|
||||||
|
const s = Schema.create(schema)
|
||||||
|
const expected = output.toJSON()
|
||||||
|
const actual = input
|
||||||
|
.change(flags)
|
||||||
|
.setValue({ schema: s })
|
||||||
|
.withoutNormalization(customChange)
|
||||||
|
.value.toJSON()
|
||||||
|
|
||||||
|
assert.deepEqual(actual, expected)
|
||||||
|
})
|
||||||
|
|
||||||
|
fixtures(__dirname, 'serializers/raw/deserialize', ({ module }) => {
|
||||||
|
const { input, output, options } = module
|
||||||
|
const actual = Value.fromJSON(input, options).toJSON()
|
||||||
|
const expected = output.toJSON()
|
||||||
|
assert.deepEqual(actual, expected)
|
||||||
|
})
|
||||||
|
|
||||||
|
fixtures(__dirname, 'serializers/raw/serialize', ({ module }) => {
|
||||||
|
const { input, output, options } = module
|
||||||
|
const actual = input.toJSON(options)
|
||||||
|
const expected = output
|
||||||
|
assert.deepEqual(actual, expected)
|
||||||
|
})
|
||||||
|
|
||||||
|
fixtures(__dirname, 'operations', ({ module }) => {
|
||||||
|
const { input, output } = module
|
||||||
|
const operations = module.default
|
||||||
|
const change = input.change()
|
||||||
|
change.applyOperations(operations)
|
||||||
|
const opts = {
|
||||||
|
preserveSelection: true,
|
||||||
|
preserveDecorations: true,
|
||||||
|
preserveData: true,
|
||||||
|
}
|
||||||
|
const actual = change.value.toJSON(opts)
|
||||||
|
const expected = output.toJSON(opts)
|
||||||
|
assert.deepEqual(actual, expected)
|
||||||
|
})
|
||||||
|
|
||||||
|
fixtures(__dirname, 'changes', ({ module }) => {
|
||||||
|
const { input, output } = module
|
||||||
|
const fn = module.default
|
||||||
|
const change = input.change()
|
||||||
|
fn(change)
|
||||||
|
const opts = { preserveSelection: true, preserveData: true }
|
||||||
|
const actual = change.value.toJSON(opts)
|
||||||
|
const expected = output.toJSON(opts)
|
||||||
|
assert.deepEqual(actual, expected)
|
||||||
|
})
|
||||||
|
|
||||||
|
fixtures(__dirname, 'schema', ({ module }) => {
|
||||||
|
const { input, output, schema } = module
|
||||||
|
const s = Schema.create(schema)
|
||||||
|
let expected = output
|
||||||
|
let actual = input
|
||||||
|
.change()
|
||||||
|
.setValue({ schema: s })
|
||||||
|
.normalize().value
|
||||||
|
|
||||||
|
if (Value.isValue(actual)) actual = actual.toJSON()
|
||||||
|
if (Value.isValue(expected)) expected = expected.toJSON()
|
||||||
|
|
||||||
|
assert.deepEqual(actual, expected)
|
||||||
|
})
|
||||||
|
|
||||||
|
fixtures(__dirname, 'history', ({ module }) => {
|
||||||
|
const { input, output } = module
|
||||||
|
const fn = module.default
|
||||||
|
const next = fn(input)
|
||||||
|
const opts = { preserveSelection: true, preserveData: true }
|
||||||
|
const actual = next.toJSON(opts)
|
||||||
|
const expected = output.toJSON(opts)
|
||||||
|
assert.deepEqual(actual, expected)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
@@ -1,56 +0,0 @@
|
|||||||
import assert from 'assert'
|
|
||||||
import fs from 'fs'
|
|
||||||
import { Schema } from '../..'
|
|
||||||
import { basename, extname, resolve } from 'path'
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests.
|
|
||||||
*/
|
|
||||||
|
|
||||||
describe('models', () => {
|
|
||||||
describe('change', () => {
|
|
||||||
describe('withoutNormalization', () => {
|
|
||||||
const testsDir = resolve(__dirname, 'change')
|
|
||||||
const tests = fs
|
|
||||||
.readdirSync(testsDir)
|
|
||||||
.filter(t => t[0] != '.')
|
|
||||||
.map(t => basename(t, extname(t)))
|
|
||||||
|
|
||||||
for (const test of tests) {
|
|
||||||
it(test, async () => {
|
|
||||||
const module = require(resolve(testsDir, test))
|
|
||||||
const { input, output, schema, flags, customChange } = module
|
|
||||||
const s = Schema.create(schema)
|
|
||||||
const expected = output.toJSON()
|
|
||||||
const actual = input
|
|
||||||
.change(flags)
|
|
||||||
.setValue({ schema: s })
|
|
||||||
.withoutNormalization(customChange)
|
|
||||||
.value.toJSON()
|
|
||||||
|
|
||||||
assert.deepEqual(actual, expected)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
describe('node', () => {
|
|
||||||
describe('node', () => {
|
|
||||||
const testsDir = resolve(__dirname, 'node')
|
|
||||||
const tests = fs
|
|
||||||
.readdirSync(testsDir)
|
|
||||||
.filter(t => t[0] != '.')
|
|
||||||
.map(t => basename(t, extname(t)))
|
|
||||||
|
|
||||||
for (const test of tests) {
|
|
||||||
it(test, async () => {
|
|
||||||
const run = require(resolve(testsDir, test)).default
|
|
||||||
run()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
require('./text/')
|
|
||||||
require('./leaf/')
|
|
||||||
})
|
|
@@ -1,34 +0,0 @@
|
|||||||
import assert from 'assert'
|
|
||||||
import fs from 'fs'
|
|
||||||
import { resolve } from 'path'
|
|
||||||
|
|
||||||
describe('leaf', () => {
|
|
||||||
const dir = resolve(__dirname)
|
|
||||||
|
|
||||||
const methods = fs
|
|
||||||
.readdirSync(dir)
|
|
||||||
.filter(c => c[0] != '.' && c != 'index.js')
|
|
||||||
|
|
||||||
for (const method of methods) {
|
|
||||||
describe(method, () => {
|
|
||||||
const testDir = resolve(dir, method)
|
|
||||||
const tests = fs
|
|
||||||
.readdirSync(testDir)
|
|
||||||
.filter(t => t[0] != '.' && t.includes('.js'))
|
|
||||||
|
|
||||||
for (const test of tests) {
|
|
||||||
const module = require(resolve(testDir, test))
|
|
||||||
const { input, output, skip } = module
|
|
||||||
const fn = module.default
|
|
||||||
const t = skip ? it.skip : it
|
|
||||||
|
|
||||||
t(test.replace('.js', ''), () => {
|
|
||||||
const actual = fn(input)
|
|
||||||
const opts = { preserveData: true }
|
|
||||||
const expected = output.toJSON(opts)
|
|
||||||
assert.deepEqual(actual.toJSON(opts), expected)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
|
@@ -1,28 +0,0 @@
|
|||||||
/** @jsx h */
|
|
||||||
|
|
||||||
import h from '../../helpers/h'
|
|
||||||
import assert from 'assert'
|
|
||||||
|
|
||||||
export default function() {
|
|
||||||
const value = (
|
|
||||||
<value>
|
|
||||||
<document>
|
|
||||||
<paragraph>
|
|
||||||
one <anchor />two<focus /> three
|
|
||||||
</paragraph>
|
|
||||||
</document>
|
|
||||||
</value>
|
|
||||||
)
|
|
||||||
|
|
||||||
const { document, selection } = value
|
|
||||||
const actual = document.getFragmentAtRange(selection)
|
|
||||||
const expected = (
|
|
||||||
<document>
|
|
||||||
<paragraph>two</paragraph>
|
|
||||||
</document>
|
|
||||||
)
|
|
||||||
|
|
||||||
const a = actual.toJSON()
|
|
||||||
const e = expected.toJSON()
|
|
||||||
assert.deepEqual(a, e)
|
|
||||||
}
|
|
@@ -0,0 +1,29 @@
|
|||||||
|
/** @jsx h */
|
||||||
|
|
||||||
|
import h from '../../../helpers/h'
|
||||||
|
|
||||||
|
export const input = (
|
||||||
|
<value>
|
||||||
|
<document>
|
||||||
|
<paragraph>
|
||||||
|
on<anchor />e
|
||||||
|
</paragraph>
|
||||||
|
<paragraph>two</paragraph>
|
||||||
|
<paragraph>
|
||||||
|
th<focus /> ree
|
||||||
|
</paragraph>
|
||||||
|
</document>
|
||||||
|
</value>
|
||||||
|
)
|
||||||
|
|
||||||
|
export default function({ document, selection }) {
|
||||||
|
return document.getFragmentAtRange(selection)
|
||||||
|
}
|
||||||
|
|
||||||
|
export const output = (
|
||||||
|
<document>
|
||||||
|
<paragraph>e</paragraph>
|
||||||
|
<paragraph>two</paragraph>
|
||||||
|
<paragraph>th</paragraph>
|
||||||
|
</document>
|
||||||
|
)
|
@@ -0,0 +1,23 @@
|
|||||||
|
/** @jsx h */
|
||||||
|
|
||||||
|
import h from '../../../helpers/h'
|
||||||
|
|
||||||
|
export const input = (
|
||||||
|
<value>
|
||||||
|
<document>
|
||||||
|
<paragraph>
|
||||||
|
one <anchor />two<focus /> three
|
||||||
|
</paragraph>
|
||||||
|
</document>
|
||||||
|
</value>
|
||||||
|
)
|
||||||
|
|
||||||
|
export default function({ document, selection }) {
|
||||||
|
return document.getFragmentAtRange(selection)
|
||||||
|
}
|
||||||
|
|
||||||
|
export const output = (
|
||||||
|
<document>
|
||||||
|
<paragraph>two</paragraph>
|
||||||
|
</document>
|
||||||
|
)
|
@@ -1,21 +0,0 @@
|
|||||||
/** @jsx h */
|
|
||||||
|
|
||||||
import h from '../../helpers/h'
|
|
||||||
import assert from 'assert'
|
|
||||||
|
|
||||||
export default function() {
|
|
||||||
const { document } = (
|
|
||||||
<value>
|
|
||||||
<document>
|
|
||||||
<paragraph>Some Text</paragraph>
|
|
||||||
</document>
|
|
||||||
</value>
|
|
||||||
)
|
|
||||||
|
|
||||||
const paragraph = document.nodes.first()
|
|
||||||
const text = paragraph.getFirstText()
|
|
||||||
|
|
||||||
assert.equal(document.getFurthestOnlyChildAncestor(paragraph.key), null)
|
|
||||||
assert.equal(paragraph.getFurthestOnlyChildAncestor(text.key), null)
|
|
||||||
assert.equal(document.getFurthestOnlyChildAncestor(text.key), paragraph)
|
|
||||||
}
|
|
@@ -0,0 +1,24 @@
|
|||||||
|
/** @jsx h */
|
||||||
|
|
||||||
|
import h from '../../../helpers/h'
|
||||||
|
|
||||||
|
export const input = (
|
||||||
|
<value>
|
||||||
|
<document>
|
||||||
|
<quote>
|
||||||
|
<paragraph key="a">word</paragraph>
|
||||||
|
</quote>
|
||||||
|
</document>
|
||||||
|
</value>
|
||||||
|
)
|
||||||
|
|
||||||
|
export default function(value) {
|
||||||
|
const { document } = value
|
||||||
|
return document.getFurthestOnlyChildAncestor('a')
|
||||||
|
}
|
||||||
|
|
||||||
|
export const output = (
|
||||||
|
<quote>
|
||||||
|
<paragraph>word</paragraph>
|
||||||
|
</quote>
|
||||||
|
)
|
@@ -0,0 +1,17 @@
|
|||||||
|
/** @jsx h */
|
||||||
|
|
||||||
|
import h from '../../../helpers/h'
|
||||||
|
|
||||||
|
export const input = (
|
||||||
|
<value>
|
||||||
|
<document>
|
||||||
|
<paragraph key="a">word</paragraph>
|
||||||
|
</document>
|
||||||
|
</value>
|
||||||
|
)
|
||||||
|
|
||||||
|
export default function({ document }) {
|
||||||
|
return document.getFurthestOnlyChildAncestor('a')
|
||||||
|
}
|
||||||
|
|
||||||
|
export const output = null
|
@@ -0,0 +1,22 @@
|
|||||||
|
/** @jsx h */
|
||||||
|
|
||||||
|
import h from '../../../helpers/h'
|
||||||
|
|
||||||
|
export const input = (
|
||||||
|
<value>
|
||||||
|
<document>
|
||||||
|
<paragraph>
|
||||||
|
one<link>
|
||||||
|
<text key="a">two</text>
|
||||||
|
</link>three
|
||||||
|
</paragraph>
|
||||||
|
</document>
|
||||||
|
</value>
|
||||||
|
)
|
||||||
|
|
||||||
|
export default function(value) {
|
||||||
|
const { document } = value
|
||||||
|
return document.getFurthestOnlyChildAncestor('a')
|
||||||
|
}
|
||||||
|
|
||||||
|
export const output = <link>two</link>
|
@@ -0,0 +1,26 @@
|
|||||||
|
/** @jsx h */
|
||||||
|
|
||||||
|
import h from '../../../helpers/h'
|
||||||
|
|
||||||
|
export const input = (
|
||||||
|
<value>
|
||||||
|
<document>
|
||||||
|
<quote>
|
||||||
|
<paragraph>
|
||||||
|
<text key="a">word</text>
|
||||||
|
</paragraph>
|
||||||
|
</quote>
|
||||||
|
</document>
|
||||||
|
</value>
|
||||||
|
)
|
||||||
|
|
||||||
|
export default function(value) {
|
||||||
|
const { document } = value
|
||||||
|
return document.getFurthestOnlyChildAncestor('a')
|
||||||
|
}
|
||||||
|
|
||||||
|
export const output = (
|
||||||
|
<quote>
|
||||||
|
<paragraph>word</paragraph>
|
||||||
|
</quote>
|
||||||
|
)
|
@@ -0,0 +1,20 @@
|
|||||||
|
/** @jsx h */
|
||||||
|
|
||||||
|
import h from '../../../helpers/h'
|
||||||
|
|
||||||
|
export const input = (
|
||||||
|
<value>
|
||||||
|
<document>
|
||||||
|
<paragraph>
|
||||||
|
<text key="a">word</text>
|
||||||
|
</paragraph>
|
||||||
|
</document>
|
||||||
|
</value>
|
||||||
|
)
|
||||||
|
|
||||||
|
export default function(value) {
|
||||||
|
const { document } = value
|
||||||
|
return document.getFurthestOnlyChildAncestor('a')
|
||||||
|
}
|
||||||
|
|
||||||
|
export const output = <paragraph>word</paragraph>
|
@@ -1,43 +0,0 @@
|
|||||||
import assert from 'assert'
|
|
||||||
import fs from 'fs'
|
|
||||||
import { resolve } from 'path'
|
|
||||||
|
|
||||||
describe('texts', () => {
|
|
||||||
const dir = resolve(__dirname)
|
|
||||||
|
|
||||||
const categories = fs
|
|
||||||
.readdirSync(dir)
|
|
||||||
.filter(c => c[0] != '.' && c != 'index.js')
|
|
||||||
|
|
||||||
for (const category of categories) {
|
|
||||||
describe(category, () => {
|
|
||||||
const categoryDir = resolve(dir, category)
|
|
||||||
const methods = fs
|
|
||||||
.readdirSync(categoryDir)
|
|
||||||
.filter(c => c[0] != '.' && !c.includes('.js'))
|
|
||||||
|
|
||||||
for (const method of methods) {
|
|
||||||
describe(method, () => {
|
|
||||||
const testDir = resolve(categoryDir, method)
|
|
||||||
const tests = fs
|
|
||||||
.readdirSync(testDir)
|
|
||||||
.filter(t => t[0] != '.' && t.includes('.js'))
|
|
||||||
|
|
||||||
for (const test of tests) {
|
|
||||||
const module = require(resolve(testDir, test))
|
|
||||||
const { input, output, skip } = module
|
|
||||||
const fn = module.default
|
|
||||||
const t = skip ? it.skip : it
|
|
||||||
|
|
||||||
t(test.replace('.js', ''), () => {
|
|
||||||
const actual = fn(input)
|
|
||||||
const opts = { preserveData: true }
|
|
||||||
const expected = output.toJSON(opts)
|
|
||||||
assert.deepEqual(actual.toJSON(opts), expected)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
|
@@ -1,50 +0,0 @@
|
|||||||
import assert from 'assert'
|
|
||||||
import fs from 'fs-promise' // eslint-disable-line import/no-extraneous-dependencies
|
|
||||||
import toSnake from 'to-snake-case' // eslint-disable-line import/no-extraneous-dependencies
|
|
||||||
import { basename, extname, resolve } from 'path'
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests.
|
|
||||||
*/
|
|
||||||
|
|
||||||
describe('operations', async () => {
|
|
||||||
const dir = resolve(__dirname)
|
|
||||||
const categories = fs
|
|
||||||
.readdirSync(dir)
|
|
||||||
.filter(c => c[0] != '.' && c != 'index.js')
|
|
||||||
|
|
||||||
for (const category of categories) {
|
|
||||||
describe(category, () => {
|
|
||||||
const categoryDir = resolve(dir, category)
|
|
||||||
const methods = fs.readdirSync(categoryDir).filter(c => c[0] != '.')
|
|
||||||
|
|
||||||
for (const method of methods) {
|
|
||||||
describe(toSnake(method), () => {
|
|
||||||
const testDir = resolve(categoryDir, method)
|
|
||||||
const tests = fs
|
|
||||||
.readdirSync(testDir)
|
|
||||||
.filter(t => t[0] != '.' && !!~t.indexOf('.js'))
|
|
||||||
.map(t => basename(t, extname(t)))
|
|
||||||
|
|
||||||
for (const test of tests) {
|
|
||||||
it(test, async () => {
|
|
||||||
const module = require(resolve(testDir, test))
|
|
||||||
const { input, output } = module
|
|
||||||
const operations = module.default
|
|
||||||
const change = input.change()
|
|
||||||
change.applyOperations(operations)
|
|
||||||
const opts = {
|
|
||||||
preserveSelection: true,
|
|
||||||
preserveDecorations: true,
|
|
||||||
preserveData: true,
|
|
||||||
}
|
|
||||||
const actual = change.value.toJSON(opts)
|
|
||||||
const expected = output.toJSON(opts)
|
|
||||||
assert.deepEqual(actual, expected)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
|
@@ -1,58 +0,0 @@
|
|||||||
import assert from 'assert'
|
|
||||||
import fs from 'fs'
|
|
||||||
import { Schema } from '../..'
|
|
||||||
import { basename, extname, resolve } from 'path'
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests.
|
|
||||||
*/
|
|
||||||
|
|
||||||
describe('schema', () => {
|
|
||||||
describe('core', () => {
|
|
||||||
const testsDir = resolve(__dirname, 'core')
|
|
||||||
const tests = fs
|
|
||||||
.readdirSync(testsDir)
|
|
||||||
.filter(t => t[0] != '.')
|
|
||||||
.map(t => basename(t, extname(t)))
|
|
||||||
|
|
||||||
for (const test of tests) {
|
|
||||||
it(test, async () => {
|
|
||||||
const module = require(resolve(testsDir, test))
|
|
||||||
const { input, output, schema } = module
|
|
||||||
const s = Schema.create(schema)
|
|
||||||
const expected = output
|
|
||||||
const actual = input
|
|
||||||
.change()
|
|
||||||
.setValue({ schema: s })
|
|
||||||
.normalize()
|
|
||||||
.value.toJSON()
|
|
||||||
|
|
||||||
assert.deepEqual(actual, expected)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
describe('custom', () => {
|
|
||||||
const testsDir = resolve(__dirname, 'custom')
|
|
||||||
const tests = fs
|
|
||||||
.readdirSync(testsDir)
|
|
||||||
.filter(t => t[0] != '.')
|
|
||||||
.map(t => basename(t, extname(t)))
|
|
||||||
|
|
||||||
for (const test of tests) {
|
|
||||||
it(test, async () => {
|
|
||||||
const module = require(resolve(testsDir, test))
|
|
||||||
const { input, output, schema } = module
|
|
||||||
const s = Schema.create(schema)
|
|
||||||
const expected = output.toJSON()
|
|
||||||
const actual = input
|
|
||||||
.change()
|
|
||||||
.setValue({ schema: s })
|
|
||||||
.normalize()
|
|
||||||
.value.toJSON()
|
|
||||||
|
|
||||||
assert.deepEqual(actual, expected)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
|
@@ -1,48 +0,0 @@
|
|||||||
import assert from 'assert'
|
|
||||||
import fs from 'fs'
|
|
||||||
import { Value } from '../..'
|
|
||||||
import { basename, extname, resolve } from 'path'
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests.
|
|
||||||
*/
|
|
||||||
|
|
||||||
describe('serializers', () => {
|
|
||||||
describe('raw', () => {
|
|
||||||
describe('deserialize()', () => {
|
|
||||||
const dir = resolve(__dirname, './raw/deserialize')
|
|
||||||
const tests = fs
|
|
||||||
.readdirSync(dir)
|
|
||||||
.filter(t => t[0] != '.')
|
|
||||||
.map(t => basename(t, extname(t)))
|
|
||||||
|
|
||||||
for (const test of tests) {
|
|
||||||
it(test, async () => {
|
|
||||||
const module = require(resolve(dir, test))
|
|
||||||
const { input, output, options } = module
|
|
||||||
const actual = Value.fromJSON(input, options).toJSON()
|
|
||||||
const expected = output.toJSON()
|
|
||||||
assert.deepEqual(actual, expected)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
describe('serialize()', () => {
|
|
||||||
const dir = resolve(__dirname, './raw/serialize')
|
|
||||||
const tests = fs
|
|
||||||
.readdirSync(dir)
|
|
||||||
.filter(t => t[0] != '.')
|
|
||||||
.map(t => basename(t, extname(t)))
|
|
||||||
|
|
||||||
for (const test of tests) {
|
|
||||||
it(test, async () => {
|
|
||||||
const module = require(resolve(dir, test))
|
|
||||||
const { input, output, options } = module
|
|
||||||
const actual = input.toJSON(options)
|
|
||||||
const expected = output
|
|
||||||
assert.deepEqual(actual, expected)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
@@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
import h from '../../../helpers/h'
|
import h from '../../../helpers/h'
|
||||||
|
|
||||||
|
export const skip = true
|
||||||
|
|
||||||
export const input = (
|
export const input = (
|
||||||
<value>
|
<value>
|
||||||
<document>
|
<document>
|
||||||
|
@@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
import h from '../../../helpers/h'
|
import h from '../../../helpers/h'
|
||||||
|
|
||||||
|
export const skip = true
|
||||||
|
|
||||||
export const input = (
|
export const input = (
|
||||||
<value>
|
<value>
|
||||||
<document>
|
<document>
|
||||||
|
Reference in New Issue
Block a user