Skip to content

Commit a4b5a25

Browse files
authored
Merge pull request #1 from ngs/add-tests
Add tests
2 parents 80abb64 + fe97ff3 commit a4b5a25

37 files changed

+2202
-32
lines changed

.babelrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
"env": {
44
"development": {
55
"presets": ["react-hmre"]
6+
},
7+
"test": {
8+
"plugins": ["rewire"]
69
}
710
}
811
}

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,5 @@ jspm_packages
3939
lib
4040
demo/public
4141
.deploy
42+
test-results.xml
43+

.mocha-multi-reporters.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"reporterEnabled": "spec, mocha-junit-reporter"
3+
}

.mocha.opts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
--compilers js:babel-core/register
2+
--recursive
3+
--require testHelper.js
4+
--reporter mocha-multi-reporters --reporter-options configFile=.mocha-multi-reporters.json

.nycrc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"exclude": [
3+
"src/**/__test__/*.js",
4+
"testHelper.js"
5+
],
6+
"reporter": [
7+
"lcov",
8+
"text-summary",
9+
"html"
10+
],
11+
"require": [
12+
"./testHelper.js"
13+
]
14+
}

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ draft-js-markdown-shortcuts-plugin
33

44
[![CircleCI](https://circleci.com/gh/ngs/draft-js-markdown-shortcuts-plugin.svg?style=svg)](https://circleci.com/gh/ngs/draft-js-markdown-shortcuts-plugin)
55
[![npm](https://img.shields.io/npm/v/draft-js-markdown-shortcuts-plugin.svg)][npm]
6+
[![Coverage Status](https://coveralls.io/repos/github/ngs/draft-js-markdown-shortcuts-plugin/badge.svg?branch=master)](https://coveralls.io/github/ngs/draft-js-markdown-shortcuts-plugin?branch=master)
67

78
A [DraftJS] plugin for supporting Markdown syntax shortcuts
89

circle.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ general:
99
branches:
1010
ignore:
1111
- gh-pages
12+
test:
13+
post:
14+
- cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js
15+
- cp -R lib $CIRCLE_ARTIFACTS/
16+
- cp -R coverage $CIRCLE_ARTIFACTS/
17+
- mkdir -p $CIRCLE_TEST_REPORTS/nyc && cp test-results.xml $CIRCLE_TEST_REPORTS/nyc
1218
deployment:
1319
production:
1420
branch: master

demo/client/components/DemoEditor/index.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,17 @@ import 'prismjs/components/prism-ruby';
1515
import 'prismjs/components/prism-swift';
1616

1717
import createMarkdownShortcutsPlugin from 'draft-js-markdown-shortcuts-plugin'; // eslint-disable-line
18-
import {
19-
// convertToRaw,
18+
import Draft, {
19+
convertToRaw,
2020
// convertFromRaw,
2121
ContentState,
2222
EditorState,
2323
} from 'draft-js';
2424
import styles from './styles.css';
2525
// import initialState from './initialState';
2626

27+
window.Draft = Draft;
28+
2729
const plugins = [createMarkdownShortcutsPlugin()];
2830

2931
const decorators = [
@@ -59,6 +61,9 @@ export default class DemoEditor extends Component {
5961
}
6062

6163
onChange = (editorState) => {
64+
window.editorState = editorState;
65+
window.rawContent = convertToRaw(editorState.getCurrentContent());
66+
6267
this.setState({
6368
editorState,
6469
});

demo/client/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22
import { render } from 'react-dom';
3-
import DemoEditor from './components/DemoEditor';
43
import Ribbon from 'react-github-fork-ribbon';
4+
import DemoEditor from './components/DemoEditor';
55

66
// Import your routes so that you can pass them to the <Router /> component
77
// eslint-disable-next-line import/no-named-as-default

package.json

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,26 @@
44
"description": "A DraftJS plugin for supporting Markdown syntax shortcuts",
55
"main": "lib/index.js",
66
"scripts": {
7-
"clean": "node_modules/.bin/rimraf lib; node_modules/.bin/rimraf demo/public",
87
"build": "npm run clean && npm run build:js",
9-
"build:js": "BABEL_DISABLE_CACHE=1 BABEL_ENV=production NODE_ENV=production node_modules/.bin/babel --out-dir='lib' --ignore='**/__test__/*' src",
108
"build:demo": "NODE_ENV=production webpack --config demo/webpack.config.prod.js && rm -rf demo/public/css && cp -R demo/publicTemplate/* demo/public/",
9+
"build:js": "BABEL_DISABLE_CACHE=1 BABEL_ENV=production NODE_ENV=production node_modules/.bin/babel --out-dir='lib' --ignore='**/__test__/*' src",
10+
"clean": "node_modules/.bin/rimraf lib; node_modules/.bin/rimraf demo/public",
11+
"deploy:demo": "COMMIT=$(git rev-parse --short HEAD) && BRANCH=gh-pages && GIT_URL=$(git remote get-url origin) && DIR=.deploy; rm -rf $DIR; (git clone $GIT_URL -b $BRANCH $DIR || (git init $DIR && cd $DIR && git remote add origin $GIT_URL && git checkout -b $BRANCH)) && rm -rf ${DIR}/* && cp -R ${DIR}/../demo/public/* $DIR && cd $DIR && git add -A && git commit -m \"Built artifacts of ${COMMIT} [ci skip]\" && git push origin $BRANCH",
1112
"prepublish": "npm run build",
12-
"start:dev": "node_modules/.bin/babel-node ./demo/server.js",
1313
"start": "npm run start:dev",
14-
"deploy:demo": "COMMIT=$(git rev-parse --short HEAD) && BRANCH=gh-pages && GIT_URL=$(git remote get-url origin) && DIR=.deploy; rm -rf $DIR; (git clone $GIT_URL -b $BRANCH $DIR || (git init $DIR && cd $DIR && git remote add origin $GIT_URL && git checkout -b $BRANCH)) && rm -rf ${DIR}/* && cp -R ${DIR}/../demo/public/* $DIR && cd $DIR && git add -A && git commit -m \"Built artifacts of ${COMMIT} [ci skip]\" && git push origin $BRANCH",
15-
"test": "mocha --compilers js:babel-core/register --require testHelper.js **/__test__/*.js"
14+
"start:dev": "node_modules/.bin/babel-node ./demo/server.js",
15+
"test": "npm run test:coverage",
16+
"test:coverage": "node_modules/.bin/nyc --require babel-core/register npm run test:mocha",
17+
"test:mocha": "mocha --opts .mocha.opts $(find src -name '*-test.js')",
18+
"test:watch": "npm test | npm run watch",
19+
"watch": "npm-watch"
20+
},
21+
"watch": {
22+
"test": {
23+
"patterns": [
24+
"src/**/*.js"
25+
]
26+
}
1627
},
1728
"repository": {
1829
"type": "git",
@@ -36,13 +47,16 @@
3647
"babel-core": "^6.18.2",
3748
"babel-eslint": "^7.1.1",
3849
"babel-loader": "^6.2.8",
50+
"babel-plugin-rewire": "^1.0.0",
3951
"babel-polyfill": "^6.16.0",
4052
"babel-preset-es2015": "^6.18.0",
4153
"babel-preset-react": "^6.16.0",
4254
"babel-preset-react-hmre": "^1.1.1",
4355
"babel-preset-stage-0": "^6.16.0",
4456
"chai": "^3.5.0",
4557
"chai-enzyme": "^0.6.1",
58+
"cheerio": "^0.22.0",
59+
"coveralls": "^2.11.15",
4660
"css-loader": "^0.26.0",
4761
"css-modules-require-hook": "^4.0.5",
4862
"dirty-chai": "^1.2.2",
@@ -62,12 +76,18 @@
6276
"history": "^2.0.0",
6377
"jsdom": "^9.8.3",
6478
"mocha": "^3.2.0",
79+
"mocha-junit-reporter": "^1.12.1",
80+
"mocha-multi-reporters": "^1.1.1",
81+
"npm-watch": "^0.1.6",
82+
"nyc": "^10.0.0",
6583
"postcss-loader": "^1.1.1",
6684
"prismjs": "^1.6.0",
6785
"react-addons-pure-render-mixin": "^15.4.1",
6886
"react-addons-test-utils": "^15.4.1",
6987
"react-github-fork-ribbon": "^0.4.4",
7088
"rimraf": "^2.5.4",
89+
"sinon": "^1.17.6",
90+
"sinon-chai": "^2.8.0",
7191
"static-site-generator-webpack-plugin": "^3.1.0",
7292
"style-loader": "^0.13.1",
7393
"url-loader": "^0.5.7",

0 commit comments

Comments
 (0)