Skip to content

Commit ffb2603

Browse files
committed
jest-codemods tests/lib
1 parent 606be43 commit ffb2603

12 files changed

+92
-104
lines changed
Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,45 @@
11
const { escapeHtmlCharacters } = require('browser/lib/utils')
2-
const test = require('ava')
32

4-
test('escapeHtmlCharacters should return the original string if nothing needed to escape', t => {
3+
test('escapeHtmlCharacters should return the original string if nothing needed to escape', () => {
54
const input = 'Nothing to be escaped'
65
const expected = 'Nothing to be escaped'
76
const actual = escapeHtmlCharacters(input)
8-
t.is(actual, expected)
7+
expect(actual).toBe(expected)
98
})
109

11-
test('escapeHtmlCharacters should skip code block if that option is enabled', t => {
10+
test('escapeHtmlCharacters should skip code block if that option is enabled', () => {
1211
const input = ` <no escape>
1312
<escapeMe>`
1413
const expected = ` <no escape>
1514
&lt;escapeMe&gt;`
1615
const actual = escapeHtmlCharacters(input, { detectCodeBlock: true })
17-
t.is(actual, expected)
16+
expect(actual).toBe(expected)
1817
})
1918

20-
test('escapeHtmlCharacters should NOT skip character not in code block but start with 4 spaces', t => {
19+
test('escapeHtmlCharacters should NOT skip character not in code block but start with 4 spaces', () => {
2120
const input = '4 spaces &'
2221
const expected = '4 spaces &amp;'
2322
const actual = escapeHtmlCharacters(input, { detectCodeBlock: true })
24-
t.is(actual, expected)
23+
expect(actual).toBe(expected)
2524
})
2625

27-
test('escapeHtmlCharacters should NOT skip code block if that option is NOT enabled', t => {
26+
test('escapeHtmlCharacters should NOT skip code block if that option is NOT enabled', () => {
2827
const input = ` <no escape>
2928
<escapeMe>`
3029
const expected = ` &lt;no escape&gt;
3130
&lt;escapeMe&gt;`
3231
const actual = escapeHtmlCharacters(input)
33-
t.is(actual, expected)
32+
expect(actual).toBe(expected)
3433
})
3534

36-
test("escapeHtmlCharacters should NOT escape & character if it's a part of an escaped character", t => {
35+
test("escapeHtmlCharacters should NOT escape & character if it's a part of an escaped character", () => {
3736
const input = 'Do not escape &amp; or &quot; but do escape &'
3837
const expected = 'Do not escape &amp; or &quot; but do escape &amp;'
3938
const actual = escapeHtmlCharacters(input)
40-
t.is(actual, expected)
39+
expect(actual).toBe(expected)
4140
})
4241

43-
test('escapeHtmlCharacters should skip char if in code block', t => {
42+
test('escapeHtmlCharacters should skip char if in code block', () => {
4443
const input = `
4544
\`\`\`
4645
<dontescapeme>
@@ -62,12 +61,12 @@ dasdasdasd
6261
\`\`\`
6362
`
6463
const actual = escapeHtmlCharacters(input, { detectCodeBlock: true })
65-
t.is(actual, expected)
64+
expect(actual).toBe(expected)
6665
})
6766

68-
test('escapeHtmlCharacters should return the correct result', t => {
67+
test('escapeHtmlCharacters should return the correct result', () => {
6968
const input = '& < > " \''
7069
const expected = '&amp; &lt; &gt; &quot; &#39;'
7170
const actual = escapeHtmlCharacters(input)
72-
t.is(actual, expected)
71+
expect(actual).toBe(expected)
7372
})

tests/lib/find-storage-test.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
const test = require('ava')
21
const { findStorage } = require('browser/lib/findStorage')
32

43
global.document = require('jsdom').jsdom('<body></body>')
@@ -13,20 +12,20 @@ const sander = require('sander')
1312
const os = require('os')
1413
const storagePath = path.join(os.tmpdir(), 'test/find-storage')
1514

16-
test.beforeEach((t) => {
15+
beforeEach(() => {
1716
t.context.storage = TestDummy.dummyStorage(storagePath)
1817
localStorage.setItem('storages', JSON.stringify([t.context.storage.cache]))
1918
})
2019

2120
// Unit test
22-
test('findStorage() should return a correct storage path(string)', t => {
21+
test('findStorage() should return a correct storage path(string)', () => {
2322
const storageKey = t.context.storage.cache.key
2423

25-
t.is(findStorage(storageKey).key, storageKey)
26-
t.is(findStorage(storageKey).path, storagePath)
24+
expect(findStorage(storageKey).key).toBe(storageKey)
25+
expect(findStorage(storageKey).path).toBe(storagePath)
2726
})
2827

29-
test.after(function after () {
28+
afterAll(function after () {
3029
localStorage.clear()
3130
sander.rimrafSync(storagePath)
3231
})

tests/lib/find-title-test.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22
* @fileoverview Unit test for browser/lib/findTitle
33
*/
44

5-
const test = require('ava')
65
const { findNoteTitle } = require('browser/lib/findNoteTitle')
76

87
// Unit test
9-
test('findNoteTitle#find should return a correct title (string)', t => {
8+
test('findNoteTitle#find should return a correct title (string)', () => {
109
// [input, expected]
1110
const testCases = [
1211
['# hoge\nfuga', '# hoge'],
@@ -20,11 +19,11 @@ test('findNoteTitle#find should return a correct title (string)', t => {
2019

2120
testCases.forEach(testCase => {
2221
const [input, expected] = testCase
23-
t.is(findNoteTitle(input, false), expected, `Test for find() input: ${input} expected: ${expected}`)
22+
expect(findNoteTitle(input, false)).toBe(expected)
2423
})
2524
})
2625

27-
test('findNoteTitle#find should ignore front matter when enableFrontMatterTitle=false', t => {
26+
test('findNoteTitle#find should ignore front matter when enableFrontMatterTitle=false', () => {
2827
// [input, expected]
2928
const testCases = [
3029
['---\nlayout: test\ntitle: hoge hoge hoge \n---\n# fuga', '# fuga'],
@@ -34,11 +33,11 @@ test('findNoteTitle#find should ignore front matter when enableFrontMatterTitle
3433

3534
testCases.forEach(testCase => {
3635
const [input, expected] = testCase
37-
t.is(findNoteTitle(input, false), expected, `Test for find() input: ${input} expected: ${expected}`)
36+
expect(findNoteTitle(input, false)).toBe(expected)
3837
})
3938
})
4039

41-
test('findNoteTitle#find should respect front matter when enableFrontMatterTitle=true', t => {
40+
test('findNoteTitle#find should respect front matter when enableFrontMatterTitle=true', () => {
4241
// [input, expected]
4342
const testCases = [
4443
['---\nlayout: test\ntitle: hoge hoge hoge \n---\n# fuga', 'hoge hoge hoge'],
@@ -48,11 +47,11 @@ test('findNoteTitle#find should respect front matter when enableFrontMatterTitl
4847

4948
testCases.forEach(testCase => {
5049
const [input, expected] = testCase
51-
t.is(findNoteTitle(input, true), expected, `Test for find() input: ${input} expected: ${expected}`)
50+
expect(findNoteTitle(input, true)).toBe(expected)
5251
})
5352
})
5453

55-
test('findNoteTitle#find should respect frontMatterTitleField when provided', t => {
54+
test('findNoteTitle#find should respect frontMatterTitleField when provided', () => {
5655
// [input, expected]
5756
const testCases = [
5857
['---\ntitle: hoge\n---\n# fuga', '# fuga'],
@@ -61,6 +60,6 @@ test('findNoteTitle#find should respect frontMatterTitleField when provided', t
6160

6261
testCases.forEach(testCase => {
6362
const [input, expected] = testCase
64-
t.is(findNoteTitle(input, true, 'custom'), expected, `Test for find() input: ${input} expected: ${expected}`)
63+
expect(findNoteTitle(input, true, 'custom')).toBe(expected)
6564
})
6665
})

tests/lib/get-todo-status-test.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
const test = require('ava')
21
const { getTodoStatus } = require('browser/lib/getTodoStatus')
32

43
// Unit test
5-
test('getTodoStatus should return a correct hash object', t => {
4+
test('getTodoStatus should return a correct hash object', () => {
65
// [input, expected]
76
const testCases = [
87
['', { total: 0, completed: 0 }],
@@ -40,8 +39,8 @@ test('getTodoStatus should return a correct hash object', t => {
4039

4140
testCases.forEach(testCase => {
4241
const [input, expected] = testCase
43-
t.is(getTodoStatus(input).total, expected.total, `Test for getTodoStatus() input: ${input} expected: ${expected.total}`)
44-
t.is(getTodoStatus(input).completed, expected.completed, `Test for getTodoStatus() input: ${input} expected: ${expected.completed}`)
42+
expect(getTodoStatus(input).total).toBe(expected.total)
43+
expect(getTodoStatus(input).completed).toBe(expected.completed)
4544
})
4645
})
4746

tests/lib/html-text-helper-test.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
/**
22
* @fileoverview Unit test for browser/lib/htmlTextHelper
33
*/
4-
const test = require('ava')
54
const htmlTextHelper = require('browser/lib/htmlTextHelper')
65

76
// Unit test
8-
test('htmlTextHelper#decodeEntities should return encoded text (string)', t => {
7+
test('htmlTextHelper#decodeEntities should return encoded text (string)', () => {
98
// [input, expected]
109
const testCases = [
1110
['&lt;a href=', '<a href='],
@@ -18,11 +17,11 @@ test('htmlTextHelper#decodeEntities should return encoded text (string)', t => {
1817

1918
testCases.forEach(testCase => {
2019
const [input, expected] = testCase
21-
t.is(htmlTextHelper.decodeEntities(input), expected, `Test for decodeEntities() input: ${input} expected: ${expected}`)
20+
expect(htmlTextHelper.decodeEntities(input)).toBe(expected)
2221
})
2322
})
2423

25-
test('htmlTextHelper#decodeEntities() should return decoded text (string)', t => {
24+
test('htmlTextHelper#decodeEntities() should return decoded text (string)', () => {
2625
// [input, expected]
2726
const testCases = [
2827
['<a href=', '&lt;a href='],
@@ -34,12 +33,12 @@ test('htmlTextHelper#decodeEntities() should return decoded text (string)', t =>
3433

3534
testCases.forEach(testCase => {
3635
const [input, expected] = testCase
37-
t.is(htmlTextHelper.encodeEntities(input), expected, `Test for encodeEntities() input: ${input} expected: ${expected}`)
36+
expect(htmlTextHelper.encodeEntities(input)).toBe(expected)
3837
})
3938
})
4039

4140
// Integration test
42-
test(t => {
41+
test(() => {
4342
const testCases = [
4443
'var test = \'test\'',
4544
'<a href=\'https://boostnote.io\'>Boostnote',
@@ -49,6 +48,6 @@ test(t => {
4948
testCases.forEach(testCase => {
5049
const encodedText = htmlTextHelper.encodeEntities(testCase)
5150
const decodedText = htmlTextHelper.decodeEntities(encodedText)
52-
t.is(decodedText, testCase, 'Integration test through encodedText() and decodedText()')
51+
expect(decodedText).toBe(testCase)
5352
})
5453
})

tests/lib/markdown-test.js

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,74 @@
1-
import test from 'ava'
21
import Markdown from 'browser/lib/markdown'
32
import markdownFixtures from '../fixtures/markdowns'
43

54
// basic markdown instance which meant to be used in every test cases.
65
// To test markdown options, initialize a new instance in your test case
76
const md = new Markdown()
87

9-
test('Markdown.render() should renders markdown correctly', t => {
8+
test('Markdown.render() should renders markdown correctly', () => {
109
const rendered = md.render(markdownFixtures.basic)
11-
t.snapshot(rendered)
10+
expect(rendered).toMatchSnapshot()
1211
})
1312

14-
test('Markdown.render() should renders codeblock correctly', t => {
13+
test('Markdown.render() should renders codeblock correctly', () => {
1514
const rendered = md.render(markdownFixtures.codeblock)
16-
t.snapshot(rendered)
15+
expect(rendered).toMatchSnapshot()
1716
})
1817

19-
test('Markdown.render() should renders KaTeX correctly', t => {
18+
test('Markdown.render() should renders KaTeX correctly', () => {
2019
const rendered = md.render(markdownFixtures.katex)
21-
t.snapshot(rendered)
20+
expect(rendered).toMatchSnapshot()
2221
})
2322

24-
test('Markdown.render() should renders checkboxes', t => {
23+
test('Markdown.render() should renders checkboxes', () => {
2524
const rendered = md.render(markdownFixtures.checkboxes)
26-
t.snapshot(rendered)
25+
expect(rendered).toMatchSnapshot()
2726
})
2827

29-
test('Markdown.render() should text with quotes correctly', t => {
28+
test('Markdown.render() should text with quotes correctly', () => {
3029
const renderedSmartQuotes = md.render(markdownFixtures.smartQuotes)
31-
t.snapshot(renderedSmartQuotes)
30+
expect(renderedSmartQuotes).toMatchSnapshot()
3231

3332
const newmd = new Markdown({ typographer: false })
3433
const renderedNonSmartQuotes = newmd.render(markdownFixtures.smartQuotes)
35-
t.snapshot(renderedNonSmartQuotes)
34+
expect(renderedNonSmartQuotes).toMatchSnapshot()
3635
})
3736

38-
test('Markdown.render() should render line breaks correctly', t => {
37+
test('Markdown.render() should render line breaks correctly', () => {
3938
const renderedBreaks = md.render(markdownFixtures.breaks)
40-
t.snapshot(renderedBreaks)
39+
expect(renderedBreaks).toMatchSnapshot()
4140

4241
const newmd = new Markdown({ breaks: false })
4342
const renderedNonBreaks = newmd.render(markdownFixtures.breaks)
44-
t.snapshot(renderedNonBreaks)
43+
expect(renderedNonBreaks).toMatchSnapshot()
4544
})
4645

47-
test('Markdown.render() should renders abbrevations correctly', t => {
46+
test('Markdown.render() should renders abbrevations correctly', () => {
4847
const rendered = md.render(markdownFixtures.abbrevations)
49-
t.snapshot(rendered)
48+
expect(rendered).toMatchSnapshot()
5049
})
5150

52-
test('Markdown.render() should renders sub correctly', t => {
51+
test('Markdown.render() should renders sub correctly', () => {
5352
const rendered = md.render(markdownFixtures.subTexts)
54-
t.snapshot(rendered)
53+
expect(rendered).toMatchSnapshot()
5554
})
5655

57-
test('Markdown.render() should renders sup correctly', t => {
56+
test('Markdown.render() should renders sup correctly', () => {
5857
const rendered = md.render(markdownFixtures.supTexts)
59-
t.snapshot(rendered)
58+
expect(rendered).toMatchSnapshot()
6059
})
6160

62-
test('Markdown.render() should renders definition lists correctly', t => {
61+
test('Markdown.render() should renders definition lists correctly', () => {
6362
const rendered = md.render(markdownFixtures.deflists)
64-
t.snapshot(rendered)
63+
expect(rendered).toMatchSnapshot()
6564
})
6665

67-
test('Markdown.render() should render shortcuts correctly', t => {
66+
test('Markdown.render() should render shortcuts correctly', () => {
6867
const rendered = md.render(markdownFixtures.shortcuts)
69-
t.snapshot(rendered)
68+
expect(rendered).toMatchSnapshot()
7069
})
7170

72-
test('Markdown.render() should render footnote correctly', t => {
71+
test('Markdown.render() should render footnote correctly', () => {
7372
const rendered = md.render(markdownFixtures.footnote)
74-
t.snapshot(rendered)
73+
expect(rendered).toMatchSnapshot()
7574
})

tests/lib/markdown-text-helper-test.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
/**
22
* @fileoverview Unit test for browser/lib/markdown
33
*/
4-
const test = require('ava')
54
const markdown = require('browser/lib/markdownTextHelper')
65

7-
test(t => {
6+
test(() => {
87
// [input, expected]
98
const testCases = [
109
// List
@@ -42,6 +41,6 @@ test(t => {
4241

4342
testCases.forEach(testCase => {
4443
const [input, expected] = testCase
45-
t.is(markdown.strip(input), expected, `Test for strip() input: ${input} expected: ${expected}`)
44+
expect(markdown.strip(input)).toBe(expected)
4645
})
4746
})

tests/lib/markdown-toc-generator-test.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@
44

55
import CodeMirror from 'codemirror'
66
require('codemirror/addon/search/searchcursor.js')
7-
const test = require('ava')
87
const markdownToc = require('browser/lib/markdown-toc-generator')
98
const EOL = require('os').EOL
109

11-
test(t => {
10+
test(() => {
1211
/**
1312
* Contains array of test cases in format :
1413
* [
@@ -261,11 +260,11 @@ this is a text
261260
const expectedToc = testCase[2].trim()
262261
const generatedToc = markdownToc.generate(inputMd)
263262

264-
t.is(generatedToc, expectedToc, `generate test : ${title} , generated : ${EOL}${generatedToc}, expected : ${EOL}${expectedToc}`)
263+
expect(generatedToc).toBe(expectedToc)
265264
})
266265
})
267266

268-
test(t => {
267+
test(() => {
269268
/**
270269
* Contains array of test cases in format :
271270
* [
@@ -663,6 +662,6 @@ this is a level one text
663662
editor.setCursor(cursor)
664663
markdownToc.generateInEditor(editor)
665664

666-
t.is(expectedMd, editor.getValue(), `generateInEditor test : ${title} , generated : ${EOL}${editor.getValue()}, expected : ${EOL}${expectedMd}`)
665+
expect(expectedMd).toBe(editor.getValue())
667666
})
668667
})

0 commit comments

Comments
 (0)