Use jest for unit tests instead of mocha

This commit is contained in:
AkiraFukushima 2018-12-26 20:29:05 +09:00
parent 7f097067e0
commit 02e0ba5b97
7 changed files with 2325 additions and 27 deletions

View File

@ -24,5 +24,5 @@ jobs:
paths: paths:
- node_modules - node_modules
- run: - run:
name: mocha name: spec
command: npm run mocha command: npm run spec:unit

2299
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -39,7 +39,7 @@
"test": "npm run unit && npm run e2e", "test": "npm run unit && npm run e2e",
"unit": "karma start test/unit/karma.conf.js", "unit": "karma start test/unit/karma.conf.js",
"postinstall": "npm run lint:fix", "postinstall": "npm run lint:fix",
"mocha": "BABEL_ENV=test mocha --require babel-register --recursive ./test/mocha/**/*.js" "spec:unit": "BABEL_ENV=test jest -u ./spec/unit/*.spec.js"
}, },
"build": { "build": {
"productName": "Whalebird", "productName": "Whalebird",
@ -169,6 +169,7 @@
"eslint-plugin-standard": "^4.0.0", "eslint-plugin-standard": "^4.0.0",
"file-loader": "^2.0.0", "file-loader": "^2.0.0",
"html-webpack-plugin": "^3.2.0", "html-webpack-plugin": "^3.2.0",
"jest": "^23.6.0",
"jsdom": "^13.0.0", "jsdom": "^13.0.0",
"karma": "^3.1.3", "karma": "^3.1.3",
"karma-chai": "^0.1.0", "karma-chai": "^0.1.0",

View File

@ -16,7 +16,7 @@ describe('emojify', () => {
url: 'https://example.com/slack' url: 'https://example.com/slack'
} }
] ]
context('Does not contain shortcode', () => { describe('Does not contain shortcode', () => {
const str = 'I have a pen.' const str = 'I have a pen.'
it('should not change', () => { it('should not change', () => {
const result = emojify(str, emoji) const result = emojify(str, emoji)
@ -26,7 +26,7 @@ describe('emojify', () => {
) )
}) })
}) })
context('Contain a shortcode', () => { describe('Contain a shortcode', () => {
const str = 'I like :python:' const str = 'I like :python:'
it('should replace', () => { it('should replace', () => {
const result = emojify(str, emoji) const result = emojify(str, emoji)
@ -36,7 +36,7 @@ describe('emojify', () => {
) )
}) })
}) })
context('Contain some shortcodes', () => { describe('Contain some shortcodes', () => {
const str = 'I like :python: , :nodejs: and :slack:' const str = 'I like :python: , :nodejs: and :slack:'
it('should replace', () => { it('should replace', () => {
const result = emojify(str, emoji) const result = emojify(str, emoji)
@ -46,7 +46,7 @@ describe('emojify', () => {
) )
}) })
}) })
context('Contain same shortcodes', () => { describe('Contain same shortcodes', () => {
const str = 'I like :python: , I love :python:' const str = 'I like :python: , I love :python:'
it('should replace', () => { it('should replace', () => {
const result = emojify(str, emoji) const result = emojify(str, emoji)

View File

@ -2,7 +2,7 @@ import assert from 'assert'
import suggestText from '../../src/renderer/utils/suggestText' import suggestText from '../../src/renderer/utils/suggestText'
describe('account', () => { describe('account', () => {
context('Only account name', () => { describe('Only account name', () => {
const str = '@h3pote' const str = '@h3pote'
it('should match', () => { it('should match', () => {
const [start, word] = suggestText(str, 7) const [start, word] = suggestText(str, 7)
@ -10,7 +10,7 @@ describe('account', () => {
assert.strictEqual(start, 1) assert.strictEqual(start, 1)
}) })
}) })
context('Beginning of the sentence', () => { describe('Beginning of the sentence', () => {
const str = '@h3pote toot body' const str = '@h3pote toot body'
it('should match', () => { it('should match', () => {
const [start, word] = suggestText(str, 7) const [start, word] = suggestText(str, 7)
@ -18,7 +18,7 @@ describe('account', () => {
assert.strictEqual(start, 1) assert.strictEqual(start, 1)
}) })
}) })
context('Halfway of the sentence', () => { describe('Halfway of the sentence', () => {
const str = 'toot body @h3pote toot' const str = 'toot body @h3pote toot'
it('should match', () => { it('should match', () => {
const [start, word] = suggestText(str, 17) const [start, word] = suggestText(str, 17)
@ -26,7 +26,7 @@ describe('account', () => {
assert.strictEqual(start, 11) assert.strictEqual(start, 11)
}) })
}) })
context('End of the sentence', () => { describe('End of the sentence', () => {
const str = 'toot body @h3pote' const str = 'toot body @h3pote'
it('should match', () => { it('should match', () => {
const [start, word] = suggestText(str, 17) const [start, word] = suggestText(str, 17)
@ -34,7 +34,7 @@ describe('account', () => {
assert.strictEqual(start, 11) assert.strictEqual(start, 11)
}) })
}) })
context('No space', () => { describe('No space', () => {
const str = 'tootbody@h3pote' const str = 'tootbody@h3pote'
it('should not match', () => { it('should not match', () => {
const [start, word] = suggestText(str, 15) const [start, word] = suggestText(str, 15)

View File

@ -3,7 +3,7 @@ import { JSDOM } from 'jsdom'
import { findLink, findTag, findAccount } from '../../src/renderer/utils/tootParser' import { findLink, findTag, findAccount } from '../../src/renderer/utils/tootParser'
describe('findLink', () => { describe('findLink', () => {
context('Pleroma', () => { describe('Pleroma', () => {
const doc = (new JSDOM(`<html><head></head><body> const doc = (new JSDOM(`<html><head></head><body>
<div class="toot"> <div class="toot">
<p> <p>
@ -22,7 +22,7 @@ I released Whalebird version 2.4.1. In version 2.4.0, Whalebird supports streami
}) })
describe('findTag', () => { describe('findTag', () => {
context('Pleroma', () => { describe('Pleroma', () => {
const doc = (new JSDOM(`<html><head></head><body> const doc = (new JSDOM(`<html><head></head><body>
<div class="toot"> <div class="toot">
<p> <p>
@ -38,7 +38,7 @@ I released Whalebird version 2.4.1. In version 2.4.0, Whalebird supports streami
}) })
}) })
context('Mastodon', () => { describe('Mastodon', () => {
const doc = (new JSDOM(`<html><head></head><body> const doc = (new JSDOM(`<html><head></head><body>
<div class="toot"> <div class="toot">
<p> <p>
@ -56,8 +56,8 @@ I released Whalebird version 2.4.1. In version 2.4.0, Whalebird supports streami
}) })
describe('findAccount', () => { describe('findAccount', () => {
context('in Pleroma', () => { describe('in Pleroma', () => {
context('from Mastodon', () => { describe('from Mastodon', () => {
const doc = (new JSDOM(`<html><head></head><body> const doc = (new JSDOM(`<html><head></head><body>
<div class="toot"> <div class="toot">
<p><span><a href="https://social.mikutter.hachune.net/@h3_poteto">@<span id="user">h3_poteto</span></a></span> hogehoge</p> <p><span><a href="https://social.mikutter.hachune.net/@h3_poteto">@<span id="user">h3_poteto</span></a></span> hogehoge</p>
@ -72,7 +72,7 @@ describe('findAccount', () => {
}) })
}) })
context('from Pleroma', () => { describe('from Pleroma', () => {
const doc = (new JSDOM(`<html><head></head><body> const doc = (new JSDOM(`<html><head></head><body>
<div class="toot"> <div class="toot">
<p><span><a href="https://pleroma.io/users/h3poteto">@<span id="user">h3_poteto</span></a></span> hogehoge</p> <p><span><a href="https://pleroma.io/users/h3poteto">@<span id="user">h3_poteto</span></a></span> hogehoge</p>

View File

@ -3,56 +3,56 @@ import { domainFormat } from '../../src/renderer/utils/validator'
describe('validator', () => { describe('validator', () => {
describe('domainFormat', () => { describe('domainFormat', () => {
context('string contains protocol', () => { describe('string contains protocol', () => {
const domain = 'https://mastodon.social' const domain = 'https://mastodon.social'
it('should not match', () => { it('should not match', () => {
const res = domain.search(domainFormat) const res = domain.search(domainFormat)
assert.strictEqual(res, -1) assert.strictEqual(res, -1)
}) })
}) })
context('string contains account name', () => { describe('string contains account name', () => {
const domain = 'h3_poteto@mastodon.social' const domain = 'h3_poteto@mastodon.social'
it('should not match', () => { it('should not match', () => {
const res = domain.search(domainFormat) const res = domain.search(domainFormat)
assert.strictEqual(res, -1) assert.strictEqual(res, -1)
}) })
}) })
context('string is gTLD domain', () => { describe('string is gTLD domain', () => {
const domain = 'mastodon.social' const domain = 'mastodon.social'
it('should match', () => { it('should match', () => {
const res = domain.search(domainFormat) const res = domain.search(domainFormat)
assert.strictEqual(res, 0) assert.strictEqual(res, 0)
}) })
}) })
context('string is subdomain', () => { describe('string is subdomain', () => {
const domain = 'music.mastodon.social' const domain = 'music.mastodon.social'
it('should match', () => { it('should match', () => {
const res = domain.search(domainFormat) const res = domain.search(domainFormat)
assert.strictEqual(res, 0) assert.strictEqual(res, 0)
}) })
}) })
context('string is subdomain', () => { describe('string is subdomain', () => {
const domain = 'social.tchncs.de' const domain = 'social.tchncs.de'
it('should match', () => { it('should match', () => {
const res = domain.search(domainFormat) const res = domain.search(domainFormat)
assert.strictEqual(res, 0) assert.strictEqual(res, 0)
}) })
}) })
context('string is jp domain', () => { describe('string is jp domain', () => {
const domain = 'mstdn.co.jp' const domain = 'mstdn.co.jp'
it('should match', () => { it('should match', () => {
const res = domain.search(domainFormat) const res = domain.search(domainFormat)
assert.strictEqual(res, 0) assert.strictEqual(res, 0)
}) })
}) })
context('string contains hyphone', () => { describe('string contains hyphone', () => {
const domain = 'music-mastodon.social' const domain = 'music-mastodon.social'
it('should match', () => { it('should match', () => {
const res = domain.search(domainFormat) const res = domain.search(domainFormat)
assert.strictEqual(res, 0) assert.strictEqual(res, 0)
}) })
}) })
context('string is short domain', () => { describe('string is short domain', () => {
const domain = 'id.cc' const domain = 'id.cc'
it('should match', () => { it('should match', () => {
const res = domain.search(domainFormat) const res = domain.search(domainFormat)