Skip to content

Commit 0f7a466

Browse files
committed
chore: Replace mocha and chai for jest
1 parent 4462e6a commit 0f7a466

9 files changed

+975
-344
lines changed

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,3 @@ dist
2424

2525
# project files
2626
coverage
27-
.nyc_output

package.json

+3-6
Original file line numberDiff line numberDiff line change
@@ -25,25 +25,22 @@
2525
"build": "npm run -s lint && npm test",
2626
"start": "npm run watch",
2727
"lint": "eslint .",
28-
"test": "nyc mocha",
29-
"pretest": "rm -rf coverage .nyc_output",
28+
"test": "jest --coverage",
29+
"pretest": "rm -rf coverage",
3030
"travis": "npm run -s build",
3131
"watch": "watch 'npm run -s build' src/ test/"
3232
},
3333
"dependencies": {
3434
"camelize": "^1.0.0",
3535
"except": "^0.1.3",
3636
"front-matter": "^2.1.2",
37+
"jest": "^20.0.0",
3738
"node-prismjs": "^0.1.0",
3839
"remarkable": "^1.7.1"
3940
},
4041
"devDependencies": {
41-
"chai": "^3.5.0",
42-
"dirty-chai": "^1.2.2",
4342
"eslint": "^3.19.0",
4443
"eslint-config-fernandopasik": "^0.5.1",
45-
"mocha": "^3.3.0",
46-
"nyc": "10.3.2",
4744
"watch": "^1.0.2"
4845
},
4946
"engines": {

test/.eslintrc

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
{
22
"env": {
3-
"mocha": true
4-
},
5-
"globals": {
6-
"expect": true
3+
"jest": true
74
}
85
}

test/build.spec.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ describe('Build Component', () => {
1111
let component = '';
1212
const mdFile = path.join(__dirname, './examples/hello-world.md');
1313

14-
before(done => {
14+
beforeAll(done => {
1515
fs.readFile(mdFile, 'utf8', (err, data) => {
1616
if (err) {
1717
return done(err);
@@ -28,16 +28,16 @@ describe('Build Component', () => {
2828
});
2929

3030
it('add React import', () => {
31-
component.should.contain('import React from \'react\';\n');
31+
expect(component).toMatch(/import React from 'react';\n/);
3232
});
3333

3434
it('add component imports', () => {
35-
component.should.contain('import Button from \'./button.js\';\n');
36-
component.should.contain('import HelloWorld from \'./hello-world.js\';\n');
35+
expect(component).toMatch(/import Button from '.\/button.js';\n/);
36+
expect(component).toMatch(/import HelloWorld from '.\/hello-world.js';\n/);
3737
});
3838

3939
it('exports the front-matter attributes', () => {
40-
component.should.contain('export const attributes = {"testFrontMatter":"hello world"}');
40+
expect(component).toMatch(/export const attributes = {"testFrontMatter":"hello world"}/);
4141
});
4242

4343
});

test/index.spec.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ describe('React Markdown Loader', () => {
1010
let mdExample = '';
1111
const mdFile = path.join(__dirname, './examples/hello-world.md');
1212

13-
before(done => {
13+
beforeAll(done => {
1414
fs.readFile(mdFile, 'utf8', (err, data) => {
1515
if (err) {
1616
return done(err);
@@ -25,7 +25,7 @@ describe('React Markdown Loader', () => {
2525
// eslint-disable-next-line prefer-reflect
2626
loader.call({
2727
async: err => {
28-
expect(err).to.not.exist();
28+
expect(err).not.toBeDefined();
2929
done();
3030
}
3131
}, mdExample);

test/mocha.opts

-5
This file was deleted.

test/parser.spec.js

+17-28
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ describe('Parse Markdown', () => {
1010
let mdExample = '';
1111
const mdFile = path.join(__dirname, './examples/hello-world.md');
1212

13-
before(done => {
13+
beforeAll(done => {
1414
fs.readFile(mdFile, 'utf8', (err, data) => {
1515
if (err) {
1616
return done(err);
@@ -23,24 +23,23 @@ describe('Parse Markdown', () => {
2323

2424
it('extracts front matter from markdown', () => {
2525
const result = parser.parseFrontMatter(mdExample);
26-
result.should.have.property('attributes');
27-
result.should.have.property('body');
26+
expect(result).toHaveProperty('attributes');
27+
expect(result).toHaveProperty('body');
2828
});
2929

3030
it('front matter attributes should contain imports object', () => {
3131
const result = parser.parseFrontMatter(mdExample);
32-
result.attributes.should.have.property('imports');
33-
result.attributes.imports.should.be.a('object');
34-
result.attributes.imports.should
35-
.deep.equal({ Button: './button.js', HelloWorld: './hello-world.js' });
32+
expect(result.attributes).toHaveProperty('imports');
33+
expect(result.attributes.imports).toBeInstanceOf(Object);
34+
expect(result.attributes.imports).toEqual({ Button: './button.js', HelloWorld: './hello-world.js' });
3635
});
3736

3837
it('example code blocks have run and source code', () => {
3938
const
4039
exampleCode = 'example',
4140
result = parser.codeBlockTemplate(exampleCode, exampleCode);
4241

43-
result.should.equal(`
42+
expect(result).toEqual(`
4443
<div class="example">
4544
<div class="run">example</div>
4645
<div class="source">
@@ -51,32 +50,22 @@ describe('Parse Markdown', () => {
5150
</div>`);
5251
});
5352

54-
it('parses markdown with live code blocks', done => {
53+
it('parses markdown with live code blocks', () =>
5554
parser.parse(mdExample).then(result => {
56-
result.html.should.contain(`<div class="run"><HelloWorld />
57-
<Button label="Hello World" />
58-
</div>`);
55+
expect(result.html).toMatch(/<div class="run"><HelloWorld \/>\s*<Button label="Hello World" \/>\s*<\/div>/);
5956
})
60-
.then(done)
61-
.catch(done);
62-
});
57+
);
6358

64-
it('parses markdown and created valid html for JSX', done => {
65-
const
66-
exampleCode = '![](myImage.png)';
67-
parser.parse(exampleCode).then(result => {
68-
result.html.should.equal('<p><img src="myImage.png" alt="" /></p>\n');
59+
it('parses markdown and created valid html for JSX', () =>
60+
parser.parse('![](myImage.png)').then(result => {
61+
expect(result.html).toMatch(/<p><img src="myImage.png" alt="" \/><\/p>\n/);
6962
})
70-
.then(done)
71-
.catch(done);
72-
});
63+
);
7364

74-
it('provides the front-matter attributes', done => {
65+
it('provides the front-matter attributes', () =>
7566
parser.parse(mdExample).then(result => {
76-
result.attributes['test-front-matter'].should.equal('hello world');
67+
expect(result.attributes).toHaveProperty('test-front-matter', 'hello world');
7768
})
78-
.then(done)
79-
.catch(done);
80-
});
69+
);
8170

8271
});

test/setup.js

-9
This file was deleted.

0 commit comments

Comments
 (0)