Skip to content

Commit

Permalink
refactor: upgrage ts\jest version
Browse files Browse the repository at this point in the history
  • Loading branch information
cycleccc committed Sep 25, 2024
1 parent ee83451 commit cda2050
Show file tree
Hide file tree
Showing 566 changed files with 5,748 additions and 3,508 deletions.
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

yarn lint:staged
# yarn lint:staged
26 changes: 26 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
module.exports = {
presets: [
[
'@babel/preset-env',
{
modules: false,
useBuiltIns: 'usage',
corejs: 3,
targets: 'ie 11',
},
],
'@babel/preset-typescript',
],
plugins: [
[
'@babel/plugin-transform-runtime',
{
absoluteRuntime: false,
corejs: 3,
helpers: true,
regenerator: true,
useESModules: false,
},
],
],
}
26 changes: 0 additions & 26 deletions babel.config.json

This file was deleted.

4 changes: 2 additions & 2 deletions build/config/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
* @author wangfupeng
*/

import path from 'path'
import commonjs from '@rollup/plugin-commonjs'
import json from '@rollup/plugin-json'
import nodeResolve from '@rollup/plugin-node-resolve'
import typescript from 'rollup-plugin-typescript2'
import replace from '@rollup/plugin-replace'
import path from 'path'
import peerDepsExternal from 'rollup-plugin-peer-deps-external'
import typescript from 'rollup-plugin-typescript2'
// import del from 'rollup-plugin-delete'

export const extensions = ['.js', '.jsx', '.ts', '.tsx']
Expand Down
7 changes: 5 additions & 2 deletions build/config/dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,19 @@
* @author wangfupeng
*/

import postcss from 'rollup-plugin-postcss'
import autoprefixer from 'autoprefixer'
import postcss from 'rollup-plugin-postcss'

import genCommonConf from './common'

/**
* 生成 dev config
* @param {string} format 'umd' 'esm'
*/
function genDevConf(format) {
const { input, output = {}, plugins = [], external } = genCommonConf(format)
const {
input, output = {}, plugins = [], external,
} = genCommonConf(format)

return {
input,
Expand Down
12 changes: 7 additions & 5 deletions build/config/prd.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,22 @@
*/

import babel from '@rollup/plugin-babel'
import postcss from 'rollup-plugin-postcss'
import terser from '@rollup/plugin-terser'
import autoprefixer from 'autoprefixer'
import cssnano from 'cssnano'
import terser from '@rollup/plugin-terser'
import cleanup from 'rollup-plugin-cleanup'
import genCommonConf from './common'
import { extensions } from './common'
import postcss from 'rollup-plugin-postcss'

import genCommonConf, { extensions } from './common'

/**
* 生成 prd config
* @param {string} format 'umd' 'esm'
*/
function genPrdConf(format) {
const { input, output = {}, plugins = [], external } = genCommonConf(format)
const {
input, output = {}, plugins = [], external,
} = genCommonConf(format)

const finalPlugins = [
...plugins,
Expand Down
6 changes: 5 additions & 1 deletion build/create-rollup-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@

import { merge } from 'lodash'
import { visualizer } from 'rollup-plugin-visualizer'

import genDevConf from './config/dev'
import genPrdConf from './config/prd'

// 环境变量
const ENV = process.env.NODE_ENV || 'production'
const IS_SIZE_STATS = ENV.indexOf('size_stats') >= 0 // 分析包体积

export const IS_DEV = ENV.indexOf('development') >= 0
export const IS_PRD = ENV.indexOf('production') >= 0

Expand All @@ -23,6 +25,7 @@ export function createRollupConfig(customConfig = {}) {
const { format } = output

let baseConfig

if (IS_PRD) {
baseConfig = genPrdConf(format)
} else {
Expand All @@ -35,11 +38,12 @@ export function createRollupConfig(customConfig = {}) {
}

const config = {
input: input ? input : baseConfig.input,
input: input || baseConfig.input,
output,
plugins,
}

const res = merge({}, baseConfig, config)

return res
}
13 changes: 10 additions & 3 deletions jest.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@ module.exports = {
testEnvironment: 'jsdom',
testMatch: ['**/(*.)+(spec|test).+(ts|js|tsx)'],
transform: {
'^.+\\.tsx?$': 'ts-jest',
'^.+\\.js$': 'ts-jest',
'^.+\\.tsx?$': [
'ts-jest',
{
useESM: true,
},
],
'^.+\\.js$': 'babel-jest',
},
globals: {
'ts-jest': {
Expand All @@ -15,7 +20,7 @@ module.exports = {
moduleNameMapper: {
'^.+\\.(css|less)$': '<rootDir>/tests/utils/stylesMock.js',
},
transformIgnorePatterns: ['node_modules/(?!(html-void-elements)/)'],
transformIgnorePatterns: ['node_modules/(?!html-void-elements)'],
setupFilesAfterEnv: ['<rootDir>/tests/setup/index.ts'],
// just collect basic module
collectCoverageFrom: [
Expand All @@ -28,5 +33,7 @@ module.exports = {
'config.ts',
'browser-polyfill.ts',
'node-polyfill.ts',
'/node_modules/',
'\\.d\\.ts$',
],
}
20 changes: 13 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
"name": "@wangeditor-next/wangeditor",
"private": true,
"packageManager": "yarn@1.22.22",
"engines": {
"node": ">=18.12.0",
"npm": "please-use-yarn",
"yarn": ">=1.22.0"
},
"browserslist": [
"defaults",
"not IE 11"
Expand Down Expand Up @@ -50,13 +55,13 @@
"@rollup/plugin-replace": "^2.4.2",
"@rollup/plugin-terser": "^0.4.0",
"@testing-library/dom": "^10.4.0",
"@testing-library/jest-dom": "^5.14.1",
"@types/jest": "^25.2.1",
"@testing-library/jest-dom": "6.5.0",
"@types/jest": "^29.5.13",
"@typescript-eslint/eslint-plugin": "^5.62.0",
"@typescript-eslint/parser": "^5.62.0",
"autoprefixer": "^10.2.5",
"babel-core": "^7.0.0-bridge.0",
"babel-jest": "^27.0.6",
"babel-jest": "^29.7.0",
"babel-plugin-istanbul": "^6.0.0",
"concurrently": "^6.2.0",
"core-js": "3",
Expand All @@ -77,7 +82,8 @@
"eslint-plugin-vue": "^9.27.0",
"http-server": "^0.13.0",
"husky": "^9.1.6",
"jest": "^27.0.6",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"less": "^3.11.1",
"lint-staged": "^15.2.10",
"lodash": "^4.17.21",
Expand All @@ -96,10 +102,10 @@
"rollup-plugin-serve": "^1.1.0",
"rollup-plugin-typescript2": "^0.36.0",
"rollup-plugin-visualizer": "^5.5.0",
"ts-jest": "^27.0.4",
"ts-jest": "^29.2.5",
"tslib": "^2.3.0",
"turbo": "2.0.6",
"typescript": "4.3.2"
"typescript": "^5.2.0"
},
"commitlint": {
"extends": [
Expand All @@ -120,4 +126,4 @@
"dependencies": {
"@babel/runtime": "^7.14.6"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/

import { Editor, Transforms } from 'slate'

import createEditor from '../../../../tests/utils/create-editor'
import BlockquoteMenu from '../../src/modules/blockquote/menu/BlockquoteMenu'

Expand Down Expand Up @@ -46,11 +47,13 @@ describe('blockquote menu', () => {

menu.exec(editor, '') // 转换为 blockquote
const blockquotes1 = editor.getElemsByTypePrefix('blockquote')

expect(blockquotes1.length).toBe(1)
expect(menu.isActive(editor)).toBeTruthy()

menu.exec(editor, '') // 取消 blockquote
const blockquotes2 = editor.getElemsByTypePrefix('blockquote')

expect(blockquotes2.length).toBe(0)
expect(menu.isActive(editor)).toBeFalsy()
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ describe('blockquote elem to html', () => {

const elem = { type: 'blockquote', children: [] }
const html = quoteToHtmlConf.elemToHtml(elem, 'hello')

expect(html).toBe('<blockquote>hello</blockquote>')
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import { $ } from 'dom7'
import { BaseElement } from 'slate'

import createEditor from '../../../../tests/utils/create-editor'
import { parseHtmlConf } from '../../src/modules/blockquote/parse-elem-html'

Expand All @@ -19,6 +20,7 @@ describe('blockquote - parse html', () => {

// parse
const res = parseHtmlConf.parseElemHtml($elem[0], [], editor)

expect(res).toEqual({
type: 'blockquote',
children: [{ text: 'hello world' }],
Expand All @@ -31,6 +33,7 @@ describe('blockquote - parse html', () => {

// parse
const res = parseHtmlConf.parseElemHtml($elem[0], children, editor)

expect(res).toEqual({
type: 'blockquote',
children: [{ text: 'hello ' }, { text: 'world', bold: true }],
Expand All @@ -46,13 +49,15 @@ describe('blockquote - parse html', () => {
]

const isInline = editor.isInline

editor.isInline = (element: any) => {
if (element.type === 'link') return true
if (element.type === 'link') { return true }
return isInline(element)
}

// parse
const res = parseHtmlConf.parseElemHtml($elem[0], children, editor)

expect(res).toEqual({
type: 'blockquote',
children: [{ text: 'hello ' }, { type: 'link', url: 'http://wangeditor.com' }],
Expand Down
12 changes: 8 additions & 4 deletions packages/basic-modules/__tests__/blockquote/plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
*/

import { Editor, Transforms } from 'slate'

import createEditor from '../../../../tests/utils/create-editor'
import withBlockquote from '../../src/modules/blockquote/plugin'
import { BlockQuoteElement } from '../../src/modules/blockquote/custom-types'
import withBlockquote from '../../src/modules/blockquote/plugin'

describe('blockquote plugin', () => {
let editor: any = withBlockquote(createEditor())
Expand All @@ -16,7 +17,7 @@ describe('blockquote plugin', () => {
editor = withBlockquote(
createEditor({
content: [{ type: 'blockquote', children: [{ text: 'hello\n' }] }],
})
}),
)
startLocation = Editor.start(editor, [])
})
Expand All @@ -30,12 +31,14 @@ describe('blockquote plugin', () => {
editor.deselect()
editor.insertBreak()
let pList = editor.getElemsByType('paragraph')

expect(pList.length).toBe(0)

editor.select({ path: [0, 0], offset: 5 })
editor.insertBreak()
let bqList = editor.getElemsByType('blockquote') as unknown as BlockQuoteElement[]
let text = bqList[0].children[0].text

expect(text).toBe('hello\n\n')

editor.select({ path: [0, 0], offset: 6 })
Expand All @@ -52,8 +55,9 @@ describe('blockquote plugin', () => {
it('insert break new line', () => {
editor.select({ path: [0, 0], offset: 6 })
editor.insertBreak()
let bqList = editor.getElemsByType('blockquote') as unknown as BlockQuoteElement[]
let text = bqList[0].children[0].text
const bqList = editor.getElemsByType('blockquote') as unknown as BlockQuoteElement[]
const text = bqList[0].children[0].text

expect(text).toBe('hello')
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ describe('blockquote - render elem', () => {

const elem = { type: 'blockquote', children: [] }
const vnode = renderBlockQuoteConf.renderElem(elem, null, editor)

expect(vnode.sel).toBe('blockquote')
})
})
Loading

0 comments on commit cda2050

Please sign in to comment.