1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-16 12:14:14 +02:00

Jest testing for slate-react (#4459)

* initial skeleton for jest testing

* run in serial mocha, then jest on slate-react only

* run-s without glob patterns https://github.com/yarnpkg/berry/issues/22

* don't run mocha on slate-react package

* use yarn run instead of run-s
This commit is contained in:
Eric Charles
2021-09-01 23:25:11 +02:00
committed by GitHub
parent e51566ada8
commit d338dcc7ce
5 changed files with 1409 additions and 35 deletions

9
babel.config.js Normal file
View File

@@ -0,0 +1,9 @@
// Needed for jest.
module.exports = {
inputSourceMap: true,
presets: [
'@babel/preset-typescript',
['@babel/preset-env', { targets: { node: 'current' } }],
'@babel/preset-react',
],
}

5
jest.config.js Normal file
View File

@@ -0,0 +1,5 @@
const config = {
testMatch: ['<rootDir>/packages/slate-react/test/**/*.{js,ts,tsx,jsx}'],
}
module.exports = config

View File

@@ -27,10 +27,12 @@
"internal:release:next": "yarn prerelease && yarn changeset publish --tag next", "internal:release:next": "yarn prerelease && yarn changeset publish --tag next",
"serve": "cd ./site && next", "serve": "cd ./site && next",
"start": "npm-run-all --parallel --print-label watch serve", "start": "npm-run-all --parallel --print-label watch serve",
"test": "mocha --require ./config/babel/register.cjs './packages/*/test/**/*.{js,ts}'", "test": "yarn run test:mocha && yarn run test:jest",
"test:custom": "mocha --require ./config/babel/register.cjs ./packages/slate/test/index.js", "test:custom": "mocha --require ./config/babel/register.cjs ./packages/slate/test/index.js",
"test:inspect": "yarn test --inspect-brk", "test:inspect": "yarn test --inspect-brk",
"test:integration": "run-p -r serve cypress:run", "test:integration": "run-p -r serve cypress:run",
"test:mocha": "mocha --require ./config/babel/register.cjs ./packages/{slate,slate-history,slate-hyperscript}/test/**/*.{js,ts}",
"test:jest": "jest --config jest.config.js",
"watch": "yarn build:rollup --watch", "watch": "yarn build:rollup --watch",
"cypress:run": "cypress run", "cypress:run": "cypress run",
"cypress:open": "cypress open" "cypress:open": "cypress open"
@@ -52,6 +54,7 @@
"@changesets/changelog-github": "^0.3.0", "@changesets/changelog-github": "^0.3.0",
"@changesets/cli": "^2.14.1", "@changesets/cli": "^2.14.1",
"@testing-library/cypress": "^8.0.0", "@testing-library/cypress": "^8.0.0",
"@types/jest": "27.0.1",
"@types/lodash": "^4.14.149", "@types/lodash": "^4.14.149",
"@types/mocha": "^5.2.7", "@types/mocha": "^5.2.7",
"@types/node": "^12.12.14", "@types/node": "^12.12.14",
@@ -60,6 +63,7 @@
"@typescript-eslint/eslint-plugin": "^2.9.0", "@typescript-eslint/eslint-plugin": "^2.9.0",
"@typescript-eslint/parser": "^2.9.0", "@typescript-eslint/parser": "^2.9.0",
"babel-eslint": "^10.0.3", "babel-eslint": "^10.0.3",
"babel-jest": "27.0.6",
"babel-plugin-dev-expression": "^0.2.2", "babel-plugin-dev-expression": "^0.2.2",
"babel-plugin-module-resolver": "^3.1.1", "babel-plugin-module-resolver": "^3.1.1",
"cypress": "^8.3.0", "cypress": "^8.3.0",
@@ -73,6 +77,7 @@
"image-extensions": "^1.1.0", "image-extensions": "^1.1.0",
"is-hotkey": "^0.1.6", "is-hotkey": "^0.1.6",
"is-url": "^1.2.2", "is-url": "^1.2.2",
"jest": "27.0.6",
"lerna": "^3.19.0", "lerna": "^3.19.0",
"lint-staged": ">=10", "lint-staged": ">=10",
"lodash": "^4.17.4", "lodash": "^4.17.4",

View File

@@ -9,7 +9,7 @@ describe('slate-react', () => {
describe('Editable', () => { describe('Editable', () => {
describe('decorate', () => { describe('decorate', () => {
// stub out some DOM stuff to avoid crashes // stub out some DOM stuff to avoid crashes
before(() => { beforeEach(() => {
const jsdom = new JSDOM() const jsdom = new JSDOM()
global.window = jsdom.window global.window = jsdom.window
global.document = jsdom.window.document global.document = jsdom.window.document

1421
yarn.lock

File diff suppressed because it is too large Load Diff