mirror of
https://github.com/ueberdosis/tiptap.git
synced 2024-11-23 19:19:03 +08:00
Merge pull request #16 from ueberdosis/feature/add-typescript-support-to-cypress
add typescript support to cypress to enable unit testing
This commit is contained in:
commit
18731f776c
@ -12,6 +12,7 @@ export { default as nodeInputRule } from './src/inputRules/nodeInputRule'
|
||||
export { default as markInputRule } from './src/inputRules/markInputRule'
|
||||
export { default as markPasteRule } from './src/pasteRules/markPasteRule'
|
||||
|
||||
export { default as capitalize } from './src/utils/capitalize'
|
||||
export { default as getSchema } from './src/utils/getSchema'
|
||||
export { default as generateHtml } from './src/utils/generateHtml'
|
||||
export { default as getHtmlFromFragment } from './src/utils/getHtmlFromFragment'
|
||||
|
@ -10,6 +10,7 @@ import getMarkAttrs from './utils/getMarkAttrs'
|
||||
import removeElement from './utils/removeElement'
|
||||
import getSchemaTypeByName from './utils/getSchemaTypeByName'
|
||||
import getHtmlFromFragment from './utils/getHtmlFromFragment'
|
||||
import createStyleTag from './utils/createStyleTag'
|
||||
import CommandManager from './CommandManager'
|
||||
import ExtensionManager from './ExtensionManager'
|
||||
import EventEmitter from './EventEmitter'
|
||||
@ -18,6 +19,7 @@ import Node from './Node'
|
||||
import Mark from './Mark'
|
||||
import defaultPlugins from './plugins'
|
||||
import * as coreCommands from './commands'
|
||||
import style from './style'
|
||||
|
||||
export type Command = (props: {
|
||||
editor: Editor,
|
||||
@ -118,10 +120,7 @@ export class Editor extends EventEmitter {
|
||||
this.extensionManager.resolveConfigs()
|
||||
this.createView()
|
||||
this.registerCommands(coreCommands)
|
||||
|
||||
if (this.options.injectCSS) {
|
||||
require('./style.css')
|
||||
}
|
||||
this.injectCSS()
|
||||
|
||||
this.proxy.focus(this.options.autoFocus)
|
||||
}
|
||||
@ -143,6 +142,15 @@ export class Editor extends EventEmitter {
|
||||
return this.commandManager.createChain()
|
||||
}
|
||||
|
||||
/**
|
||||
* Inject CSS styles.
|
||||
*/
|
||||
private injectCSS() {
|
||||
if (this.options.injectCSS && document) {
|
||||
this.css = createStyleTag(style)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update editor options.
|
||||
*
|
||||
|
@ -1,4 +1,4 @@
|
||||
.ProseMirror {
|
||||
const style = `.ProseMirror {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
@ -49,4 +49,6 @@
|
||||
|
||||
.ProseMirror-focused .ProseMirror-gapcursor {
|
||||
display: block;
|
||||
}
|
||||
}`
|
||||
|
||||
export default style
|
8
packages/core/src/utils/createStyleTag.ts
Normal file
8
packages/core/src/utils/createStyleTag.ts
Normal file
@ -0,0 +1,8 @@
|
||||
export default function createStyleTag(style: string): HTMLStyleElement {
|
||||
const styleNode = document.createElement('style')
|
||||
|
||||
styleNode.innerHTML = style
|
||||
document.getElementsByTagName('head')[0].appendChild(styleNode)
|
||||
|
||||
return styleNode
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
{
|
||||
"baseUrl": "http://localhost:3000",
|
||||
"integrationFolder": "../docs/src/",
|
||||
"testFiles": "**/*.spec.js",
|
||||
"integrationFolder": "../",
|
||||
"testFiles": "{docs,tests}/**/*.spec.{js,ts}",
|
||||
"viewportWidth": 1280,
|
||||
"viewportHeight": 1280
|
||||
}
|
||||
|
11
tests/cypress/integration/core/capitalize.spec.ts
Normal file
11
tests/cypress/integration/core/capitalize.spec.ts
Normal file
@ -0,0 +1,11 @@
|
||||
/// <reference types="cypress" />
|
||||
|
||||
import { capitalize } from '@tiptap/core'
|
||||
|
||||
describe('capitalize test', () => {
|
||||
it('capitalize a word', () => {
|
||||
const capitalized = capitalize('test')
|
||||
|
||||
expect(capitalized).to.eq('Test')
|
||||
})
|
||||
})
|
5
tests/cypress/integration/core/example.spec.ts
Normal file
5
tests/cypress/integration/core/example.spec.ts
Normal file
@ -0,0 +1,5 @@
|
||||
describe('example test', () => {
|
||||
it('should work', () => {
|
||||
expect('<p>Example Text</p>').to.eq('<p>Example Text</p>')
|
||||
})
|
||||
})
|
13
tests/cypress/tsconfig.json
Normal file
13
tests/cypress/tsconfig.json
Normal file
@ -0,0 +1,13 @@
|
||||
{
|
||||
"extends": "../../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"noEmit": false,
|
||||
"sourceMap": false,
|
||||
"types": [
|
||||
"cypress",
|
||||
],
|
||||
},
|
||||
"include": [
|
||||
"./*/*.ts"
|
||||
]
|
||||
}
|
Loading…
Reference in New Issue
Block a user