diff --git a/.gitignore b/.gitignore index aac64950..f494f3b0 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ node_modules/* .idea .vscode package-lock.json +config.json diff --git a/tests/dataApi/copyFile-test.js b/tests/dataApi/copyFile.test.js similarity index 81% rename from tests/dataApi/copyFile-test.js rename to tests/dataApi/copyFile.test.js index f38f1ed2..c3e4aa02 100644 --- a/tests/dataApi/copyFile-test.js +++ b/tests/dataApi/copyFile.test.js @@ -1,4 +1,3 @@ -const test = require('ava') const copyFile = require('browser/main/lib/dataApi/copyFile') const path = require('path') @@ -13,23 +12,25 @@ const srcPath = path.join(srcFolder, testFile) const dstFolder = path.join(__dirname, 'πŸ˜‡') const dstPath = path.join(dstFolder, testFile) -test.before(t => { +beforeAll(() => { if (!fs.existsSync(srcFolder)) fs.mkdirSync(srcFolder) fs.writeFileSync(srcPath, 'test') }) -test('`copyFile` should handle encoded URI on src path', t => { +it('`copyFile` should handle encoded URI on src path', done => { return copyFile(encodeURI(srcPath), dstPath) .then(() => { - t.true(true) + expect(true).toBe(true) + done() }) .catch(() => { - t.true(false) + expect(false).toBe(true) + done() }) }) -test.after(t => { +afterAll(() => { fs.unlinkSync(srcPath) fs.unlinkSync(dstPath) execSync(removeDirCommand + '"' + srcFolder + '"') diff --git a/tests/dataApi/createFolder-test.js b/tests/dataApi/createFolder.test.js similarity index 63% rename from tests/dataApi/createFolder-test.js rename to tests/dataApi/createFolder.test.js index fd54ba27..4b004e94 100644 --- a/tests/dataApi/createFolder-test.js +++ b/tests/dataApi/createFolder.test.js @@ -1,4 +1,3 @@ -const test = require('ava') const createFolder = require('browser/main/lib/dataApi/createFolder') global.document = require('jsdom').jsdom('') @@ -19,32 +18,34 @@ const CSON = require('@rokt33r/season') const storagePath = path.join(os.tmpdir(), 'test/create-folder') -test.beforeEach(t => { - t.context.storage = TestDummy.dummyStorage(storagePath) - localStorage.setItem('storages', JSON.stringify([t.context.storage.cache])) +let storageContext + +beforeAll(() => { + storageContext = TestDummy.dummyStorage(storagePath) + localStorage.setItem('storages', JSON.stringify([storageContext.cache])) }) -test.serial('Create a folder', t => { - const storageKey = t.context.storage.cache.key +it('Create a folder', done => { + const storageKey = storageContext.cache.key const input = { name: 'created', color: '#ff5555' } return Promise.resolve() - .then(function doTest() { + .then(() => { return createFolder(storageKey, input) }) - .then(function assert(data) { - t.true(_.find(data.storage.folders, input) != null) + .then(data => { + expect(_.find(data.storage.folders, input)).not.toBeNull() const jsonData = CSON.readFileSync( path.join(data.storage.path, 'boostnote.json') ) - console.log(path.join(data.storage.path, 'boostnote.json')) - t.true(_.find(jsonData.folders, input) != null) + expect(_.find(jsonData.folders, input)).not.toBeNull() + done() }) }) -test.after(function after() { +afterAll(() => { localStorage.clear() sander.rimrafSync(storagePath) }) diff --git a/tests/dataApi/createNote-test.js b/tests/dataApi/createNote.test.js similarity index 51% rename from tests/dataApi/createNote-test.js rename to tests/dataApi/createNote.test.js index 2c3af348..dd9481e1 100644 --- a/tests/dataApi/createNote-test.js +++ b/tests/dataApi/createNote.test.js @@ -1,4 +1,3 @@ -const test = require('ava') const createNote = require('browser/main/lib/dataApi/createNote') global.document = require('jsdom').jsdom('') @@ -19,14 +18,16 @@ const faker = require('faker') const storagePath = path.join(os.tmpdir(), 'test/create-note') -test.beforeEach(t => { - t.context.storage = TestDummy.dummyStorage(storagePath) - localStorage.setItem('storages', JSON.stringify([t.context.storage.cache])) +let storageContext + +beforeEach(() => { + storageContext = TestDummy.dummyStorage(storagePath) + localStorage.setItem('storages', JSON.stringify([storageContext.cache])) }) -test.serial('Create a note', t => { - const storageKey = t.context.storage.cache.key - const folderKey = t.context.storage.json.folders[0].key +it('Create a note', done => { + const storageKey = storageContext.cache.key + const folderKey = storageContext.json.folders[0].key const randLinesHighlightedArray = new Array(10) .fill() @@ -58,58 +59,58 @@ test.serial('Create a note', t => { input2.title = input2.content.split('\n').shift() return Promise.resolve() - .then(function doTest() { + .then(() => { return Promise.all([ createNote(storageKey, input1), createNote(storageKey, input2) ]) }) - .then(function assert(data) { + .then(data => { const data1 = data[0] const data2 = data[1] - t.is(storageKey, data1.storage) + expect(storageKey).toEqual(data1.storage) const jsonData1 = CSON.readFileSync( path.join(storagePath, 'notes', data1.key + '.cson') ) - t.is(input1.title, data1.title) - t.is(input1.title, jsonData1.title) - t.is(input1.description, data1.description) - t.is(input1.description, jsonData1.description) - t.is(input1.tags.length, data1.tags.length) - t.is(input1.tags.length, jsonData1.tags.length) - t.is(input1.snippets.length, data1.snippets.length) - t.is(input1.snippets.length, jsonData1.snippets.length) - t.is(input1.snippets[0].content, data1.snippets[0].content) - t.is(input1.snippets[0].content, jsonData1.snippets[0].content) - t.is(input1.snippets[0].name, data1.snippets[0].name) - t.is(input1.snippets[0].name, jsonData1.snippets[0].name) - t.deepEqual( - input1.snippets[0].linesHighlighted, + expect(input1.title).toEqual(data1.title) + expect(input1.title).toEqual(jsonData1.title) + expect(input1.description).toEqual(data1.description) + expect(input1.description).toEqual(jsonData1.description) + expect(input1.tags.length).toEqual(data1.tags.length) + expect(input1.tags.length).toEqual(jsonData1.tags.length) + expect(input1.snippets.length).toEqual(data1.snippets.length) + expect(input1.snippets.length).toEqual(jsonData1.snippets.length) + expect(input1.snippets[0].content).toEqual(data1.snippets[0].content) + expect(input1.snippets[0].content).toEqual(jsonData1.snippets[0].content) + expect(input1.snippets[0].name).toEqual(data1.snippets[0].name) + expect(input1.snippets[0].name).toEqual(jsonData1.snippets[0].name) + expect(input1.snippets[0].linesHighlighted).toEqual( data1.snippets[0].linesHighlighted ) - t.deepEqual( - input1.snippets[0].linesHighlighted, + expect(input1.snippets[0].linesHighlighted).toEqual( jsonData1.snippets[0].linesHighlighted ) - t.is(storageKey, data2.storage) + expect(storageKey).toEqual(data2.storage) const jsonData2 = CSON.readFileSync( path.join(storagePath, 'notes', data2.key + '.cson') ) - t.is(input2.title, data2.title) - t.is(input2.title, jsonData2.title) - t.is(input2.content, data2.content) - t.is(input2.content, jsonData2.content) - t.is(input2.tags.length, data2.tags.length) - t.is(input2.tags.length, jsonData2.tags.length) - t.deepEqual(input2.linesHighlighted, data2.linesHighlighted) - t.deepEqual(input2.linesHighlighted, jsonData2.linesHighlighted) + expect(input2.title).toEqual(data2.title) + expect(input2.title).toEqual(jsonData2.title) + expect(input2.content).toEqual(data2.content) + expect(input2.content).toEqual(jsonData2.content) + expect(input2.tags.length).toEqual(data2.tags.length) + expect(input2.tags.length).toEqual(jsonData2.tags.length) + expect(input2.linesHighlighted).toEqual(data2.linesHighlighted) + expect(input2.linesHighlighted).toEqual(jsonData2.linesHighlighted) + + done() }) }) -test.after(function after() { +afterAll(function after() { localStorage.clear() sander.rimrafSync(storagePath) }) diff --git a/tests/dataApi/createNoteFromUrl-test.js b/tests/dataApi/createNoteFromUrl.test.js similarity index 67% rename from tests/dataApi/createNoteFromUrl-test.js rename to tests/dataApi/createNoteFromUrl.test.js index 83b8d4e8..4e067380 100644 --- a/tests/dataApi/createNoteFromUrl-test.js +++ b/tests/dataApi/createNoteFromUrl.test.js @@ -1,4 +1,3 @@ -const test = require('ava') const createNoteFromUrl = require('browser/main/lib/dataApi/createNoteFromUrl') global.document = require('jsdom').jsdom('') @@ -18,32 +17,34 @@ const CSON = require('@rokt33r/season') const storagePath = path.join(os.tmpdir(), 'test/create-note-from-url') -test.beforeEach(t => { - t.context.storage = TestDummy.dummyStorage(storagePath) - localStorage.setItem('storages', JSON.stringify([t.context.storage.cache])) +let storageContext + +beforeEach(() => { + storageContext = TestDummy.dummyStorage(storagePath) + localStorage.setItem('storages', JSON.stringify([storageContext.cache])) }) -test.serial('Create a note from URL', t => { - const storageKey = t.context.storage.cache.key - const folderKey = t.context.storage.json.folders[0].key +it('Create a note from URL', () => { + const storageKey = storageContext.cache.key + const folderKey = storageContext.json.folders[0].key const url = 'https://shapeshed.com/writing-cross-platform-node/' return createNoteFromUrl(url, storageKey, folderKey).then(function assert({ note }) { - t.is(storageKey, note.storage) + expect(storageKey).toEqual(note.storage) const jsonData = CSON.readFileSync( path.join(storagePath, 'notes', note.key + '.cson') ) // Test if saved content is matching the created in memory note - t.is(note.content, jsonData.content) - t.is(note.tags.length, jsonData.tags.length) + expect(note.content).toEqual(jsonData.content) + expect(note.tags.length).toEqual(jsonData.tags.length) }) }) -test.after(function after() { +afterAll(function after() { localStorage.clear() sander.rimrafSync(storagePath) }) diff --git a/tests/dataApi/createSnippet-test.js b/tests/dataApi/createSnippet.test.js similarity index 59% rename from tests/dataApi/createSnippet-test.js rename to tests/dataApi/createSnippet.test.js index e1b9a570..d667a069 100644 --- a/tests/dataApi/createSnippet-test.js +++ b/tests/dataApi/createSnippet.test.js @@ -1,4 +1,3 @@ -const test = require('ava') const createSnippet = require('browser/main/lib/dataApi/createSnippet') const sander = require('sander') const os = require('os') @@ -7,29 +6,27 @@ const path = require('path') const snippetFilePath = path.join(os.tmpdir(), 'test', 'create-snippet') const snippetFile = path.join(snippetFilePath, 'snippets.json') -test.beforeEach(t => { +beforeEach(() => { sander.writeFileSync(snippetFile, '[]') }) -test.serial('Create a snippet', t => { +it('Create a snippet', () => { return Promise.resolve() - .then(function doTest() { - return Promise.all([createSnippet(snippetFile)]) - }) + .then(() => Promise.all([createSnippet(snippetFile)])) .then(function assert(data) { data = data[0] const snippets = JSON.parse(sander.readFileSync(snippetFile)) const snippet = snippets.find( currentSnippet => currentSnippet.id === data.id ) - t.not(snippet, undefined) - t.is(snippet.name, data.name) - t.deepEqual(snippet.prefix, data.prefix) - t.is(snippet.content, data.content) - t.deepEqual(snippet.linesHighlighted, data.linesHighlighted) + expect(snippet).not.toBeUndefined() + expect(snippet.name).toEqual(data.name) + expect(snippet.prefix).toEqual(data.prefix) + expect(snippet.content).toEqual(data.content) + expect(snippet.linesHighlighted).toEqual(data.linesHighlighted) }) }) -test.after.always(() => { +afterAll(() => { sander.rimrafSync(snippetFilePath) }) diff --git a/tests/dataApi/deleteFolder-test.js b/tests/dataApi/deleteFolder.test.js similarity index 76% rename from tests/dataApi/deleteFolder-test.js rename to tests/dataApi/deleteFolder.test.js index 8b930e48..96865164 100644 --- a/tests/dataApi/deleteFolder-test.js +++ b/tests/dataApi/deleteFolder.test.js @@ -1,4 +1,3 @@ -const test = require('ava') const deleteFolder = require('browser/main/lib/dataApi/deleteFolder') const attachmentManagement = require('browser/main/lib/dataApi/attachmentManagement') const createNote = require('browser/main/lib/dataApi/createNote') @@ -23,14 +22,16 @@ const CSON = require('@rokt33r/season') const storagePath = path.join(os.tmpdir(), 'test/delete-folder') -test.beforeEach(t => { - t.context.storage = TestDummy.dummyStorage(storagePath) - localStorage.setItem('storages', JSON.stringify([t.context.storage.cache])) +let storageContext + +beforeEach(() => { + storageContext = TestDummy.dummyStorage(storagePath) + localStorage.setItem('storages', JSON.stringify([storageContext.cache])) }) -test.serial('Delete a folder', t => { - const storageKey = t.context.storage.cache.key - const folderKey = t.context.storage.json.folders[0].key +it('Delete a folder', () => { + const storageKey = storageContext.cache.key + const folderKey = storageContext.json.folders[0].key let noteKey const input1 = { @@ -72,16 +73,15 @@ test.serial('Delete a folder', t => { return deleteFolder(storageKey, folderKey) }) .then(function assert(data) { - t.true(_.find(data.storage.folders, { key: folderKey }) == null) + expect(_.find(data.storage.folders, { key: folderKey })).toBeUndefined() const jsonData = CSON.readFileSync( path.join(data.storage.path, 'boostnote.json') ) - t.true(_.find(jsonData.folders, { key: folderKey }) == null) + expect(_.find(jsonData.folders, { key: folderKey })).toBeUndefined() const notePaths = sander.readdirSync(data.storage.path, 'notes') - t.is( - notePaths.length, - t.context.storage.notes.filter(note => note.folder !== folderKey).length + expect(notePaths.length).toBe( + storageContext.notes.filter(note => note.folder !== folderKey).length ) const attachmentFolderPath = path.join( @@ -89,11 +89,11 @@ test.serial('Delete a folder', t => { attachmentManagement.DESTINATION_FOLDER, noteKey ) - t.false(fs.existsSync(attachmentFolderPath)) + expect(fs.existsSync(attachmentFolderPath)).toBe(false) }) }) -test.after.always(function after() { +afterAll(() => { localStorage.clear() sander.rimrafSync(storagePath) }) diff --git a/tests/lib/__snapshots__/markdown.test.js.snap b/tests/lib/__snapshots__/markdown.test.js.snap new file mode 100644 index 00000000..5d04bc4c --- /dev/null +++ b/tests/lib/__snapshots__/markdown.test.js.snap @@ -0,0 +1,189 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Markdown.render() should render PlantUML Ditaa correctly 1`] = ` +"\\"uml +" +`; + +exports[`Markdown.render() should render PlantUML Gantt correctly 1`] = ` +"\\"uml +" +`; + +exports[`Markdown.render() should render PlantUML MindMaps correctly 1`] = ` +"\\"uml +" +`; + +exports[`Markdown.render() should render PlantUML Umls correctly 1`] = ` +"\\"uml +" +`; + +exports[`Markdown.render() should render PlantUML WBS correctly 1`] = ` +"\\"uml +" +`; + +exports[`Markdown.render() should render footnote correctly 1`] = ` +"

[1]
+hello-world: https://github.com/BoostIO/Boostnote/

+
+
+
    +
  1. hello-world β†©οΈŽ

    +
  2. +
+
+" +`; + +exports[`Markdown.render() should render line breaks correctly 1`] = ` +"

This is the first line.
+This is the second line.

+" +`; + +exports[`Markdown.render() should render line breaks correctly 2`] = ` +"

This is the first line. +This is the second line.

+" +`; + +exports[`Markdown.render() should render shortcuts correctly 1`] = ` +"

Ctrl

+

Ctrl

+" +`; + +exports[`Markdown.render() should renders [TOC] placholder correctly 1`] = ` +"

+

+

H1

+

H2

+

H3

+

###$ H4

+" +`; + +exports[`Markdown.render() should renders KaTeX correctly 1`] = ` +"c=pmsqrta2+b2c = pmsqrt{a^2 + b^2}c=pmsqrta2+b2 +" +`; + +exports[`Markdown.render() should renders abbrevations correctly 1`] = ` +"

abbr

+

The HTML specification
+is maintained by the W3C.

+" +`; + +exports[`Markdown.render() should renders checkboxes 1`] = ` +" +" +`; + +exports[`Markdown.render() should renders codeblock correctly 1`] = ` +"
+        filename.js
+        2
+        var project = 'boostnote';
+
+      
" +`; + +exports[`Markdown.render() should renders definition lists correctly 1`] = ` +"

definition list

+

list 1

+
+
Term 1
+
Definition 1
+
Term 2
+
Definition 2a
+
Definition 2b
+
+

Term 3
+~

+

list 2

+
+
Term 1
+
+

Definition 1

+
+
Term 2 with inline markup
+
+

Definition 2

+
  { some code, part of Definition 2 }
+
+

Third paragraph of definition 2.

+
+
+" +`; + +exports[`Markdown.render() should renders markdown correctly 1`] = ` +"

Welcome to Boostnote!

+

Click here to edit markdown πŸ‘‹

+ +

Docs πŸ“

+ +
+

Article Archive πŸ“š

+ +
+

Community 🍻

+ +" +`; + +exports[`Markdown.render() should renders sub correctly 1`] = ` +"

sub

+

H20

+" +`; + +exports[`Markdown.render() should renders sup correctly 1`] = ` +"

sup

+

29th

+" +`; + +exports[`Markdown.render() should text with quotes correctly 1`] = ` +"

This is a β€œQUOTE”.

+" +`; + +exports[`Markdown.render() should text with quotes correctly 2`] = ` +"

This is a "QUOTE".

+" +`; diff --git a/tests/lib/escapeHtmlCharacters-test.js b/tests/lib/escapeHtmlCharacters.test.js similarity index 75% rename from tests/lib/escapeHtmlCharacters-test.js rename to tests/lib/escapeHtmlCharacters.test.js index 672ef917..8c9e0b42 100644 --- a/tests/lib/escapeHtmlCharacters-test.js +++ b/tests/lib/escapeHtmlCharacters.test.js @@ -1,46 +1,45 @@ const { escapeHtmlCharacters } = require('browser/lib/utils') -const test = require('ava') -test('escapeHtmlCharacters should return the original string if nothing needed to escape', t => { +test('escapeHtmlCharacters should return the original string if nothing needed to escape', () => { const input = 'Nothing to be escaped' const expected = 'Nothing to be escaped' const actual = escapeHtmlCharacters(input) - t.is(actual, expected) + expect(actual).toBe(expected) }) -test('escapeHtmlCharacters should skip code block if that option is enabled', t => { +test('escapeHtmlCharacters should skip code block if that option is enabled', () => { const input = ` ` const expected = ` <escapeMe>` const actual = escapeHtmlCharacters(input, { detectCodeBlock: true }) - t.is(actual, expected) + expect(actual).toBe(expected) }) -test('escapeHtmlCharacters should NOT skip character not in code block but start with 4 spaces', t => { +test('escapeHtmlCharacters should NOT skip character not in code block but start with 4 spaces', () => { const input = '4 spaces &' const expected = '4 spaces &' const actual = escapeHtmlCharacters(input, { detectCodeBlock: true }) - t.is(actual, expected) + expect(actual).toBe(expected) }) -test('escapeHtmlCharacters should NOT skip code block if that option is NOT enabled', t => { +test('escapeHtmlCharacters should NOT skip code block if that option is NOT enabled', () => { const input = ` ` const expected = ` <no escape> <escapeMe>` const actual = escapeHtmlCharacters(input) - t.is(actual, expected) + expect(actual).toBe(expected) }) -test("escapeHtmlCharacters should NOT escape & character if it's a part of an escaped character", t => { +test("escapeHtmlCharacters should NOT escape & character if it's a part of an escaped character", () => { const input = 'Do not escape & or " but do escape &' const expected = 'Do not escape & or " but do escape &' const actual = escapeHtmlCharacters(input) - t.is(actual, expected) + expect(actual).toBe(expected) }) -test('escapeHtmlCharacters should skip char if in code block', t => { +test('escapeHtmlCharacters should skip char if in code block', () => { const input = ` \`\`\` @@ -62,12 +61,12 @@ dasdasdasd \`\`\` ` const actual = escapeHtmlCharacters(input, { detectCodeBlock: true }) - t.is(actual, expected) + expect(actual).toBe(expected) }) -test('escapeHtmlCharacters should return the correct result', t => { +test('escapeHtmlCharacters should return the correct result', () => { const input = '& < > " \'' const expected = '& < > " '' const actual = escapeHtmlCharacters(input) - t.is(actual, expected) + expect(actual).toBe(expected) }) diff --git a/tests/lib/find-storage-test.js b/tests/lib/find-storage.test.js similarity index 64% rename from tests/lib/find-storage-test.js rename to tests/lib/find-storage.test.js index ab3b07a6..9983d813 100644 --- a/tests/lib/find-storage-test.js +++ b/tests/lib/find-storage.test.js @@ -1,4 +1,3 @@ -const test = require('ava') const { findStorage } = require('browser/lib/findStorage') global.document = require('jsdom').jsdom('') @@ -16,20 +15,22 @@ const sander = require('sander') const os = require('os') const storagePath = path.join(os.tmpdir(), 'test/find-storage') -test.beforeEach(t => { - t.context.storage = TestDummy.dummyStorage(storagePath) - localStorage.setItem('storages', JSON.stringify([t.context.storage.cache])) +let storageContext + +beforeEach(() => { + storageContext = TestDummy.dummyStorage(storagePath) + localStorage.setItem('storages', JSON.stringify([storageContext.cache])) }) // Unit test -test('findStorage() should return a correct storage path(string)', t => { - const storageKey = t.context.storage.cache.key +test('findStorage() should return a correct storage path(string)', () => { + const storageKey = storageContext.cache.key - t.is(findStorage(storageKey).key, storageKey) - t.is(findStorage(storageKey).path, storagePath) + expect(findStorage(storageKey).key).toBe(storageKey) + expect(findStorage(storageKey).path).toBe(storagePath) }) -test.after(function after() { +afterAll(function after() { localStorage.clear() sander.rimrafSync(storagePath) }) diff --git a/tests/lib/find-title-test.js b/tests/lib/find-title.test.js similarity index 71% rename from tests/lib/find-title-test.js rename to tests/lib/find-title.test.js index 2498cdc0..101db596 100644 --- a/tests/lib/find-title-test.js +++ b/tests/lib/find-title.test.js @@ -2,11 +2,10 @@ * @fileoverview Unit test for browser/lib/findTitle */ -const test = require('ava') const { findNoteTitle } = require('browser/lib/findNoteTitle') // Unit test -test('findNoteTitle#find should return a correct title (string)', t => { +test('findNoteTitle#find should return a correct title (string)', () => { // [input, expected] const testCases = [ ['# hoge\nfuga', '# hoge'], @@ -20,15 +19,11 @@ test('findNoteTitle#find should return a correct title (string)', t => { testCases.forEach(testCase => { const [input, expected] = testCase - t.is( - findNoteTitle(input, false), - expected, - `Test for find() input: ${input} expected: ${expected}` - ) + expect(findNoteTitle(input, false)).toBe(expected) }) }) -test('findNoteTitle#find should ignore front matter when enableFrontMatterTitle=false', t => { +test('findNoteTitle#find should ignore front matter when enableFrontMatterTitle=false', () => { // [input, expected] const testCases = [ ['---\nlayout: test\ntitle: hoge hoge hoge \n---\n# fuga', '# fuga'], @@ -38,15 +33,11 @@ test('findNoteTitle#find should ignore front matter when enableFrontMatterTitle testCases.forEach(testCase => { const [input, expected] = testCase - t.is( - findNoteTitle(input, false), - expected, - `Test for find() input: ${input} expected: ${expected}` - ) + expect(findNoteTitle(input, false)).toBe(expected) }) }) -test('findNoteTitle#find should respect front matter when enableFrontMatterTitle=true', t => { +test('findNoteTitle#find should respect front matter when enableFrontMatterTitle=true', () => { // [input, expected] const testCases = [ [ @@ -59,15 +50,11 @@ test('findNoteTitle#find should respect front matter when enableFrontMatterTitl testCases.forEach(testCase => { const [input, expected] = testCase - t.is( - findNoteTitle(input, true), - expected, - `Test for find() input: ${input} expected: ${expected}` - ) + expect(findNoteTitle(input, true)).toBe(expected) }) }) -test('findNoteTitle#find should respect frontMatterTitleField when provided', t => { +test('findNoteTitle#find should respect frontMatterTitleField when provided', () => { // [input, expected] const testCases = [ ['---\ntitle: hoge\n---\n# fuga', '# fuga'], @@ -76,10 +63,6 @@ test('findNoteTitle#find should respect frontMatterTitleField when provided', t testCases.forEach(testCase => { const [input, expected] = testCase - t.is( - findNoteTitle(input, true, 'custom'), - expected, - `Test for find() input: ${input} expected: ${expected}` - ) + expect(findNoteTitle(input, true, 'custom')).toBe(expected) }) }) diff --git a/tests/lib/get-todo-status-test.js b/tests/lib/get-todo-status.test.js similarity index 82% rename from tests/lib/get-todo-status-test.js rename to tests/lib/get-todo-status.test.js index 52c57cfe..07f98a3e 100644 --- a/tests/lib/get-todo-status-test.js +++ b/tests/lib/get-todo-status.test.js @@ -1,8 +1,7 @@ -const test = require('ava') const { getTodoStatus } = require('browser/lib/getTodoStatus') // Unit test -test('getTodoStatus should return a correct hash object', t => { +test('getTodoStatus should return a correct hash object', () => { // [input, expected] const testCases = [ ['', { total: 0, completed: 0 }], @@ -40,15 +39,7 @@ test('getTodoStatus should return a correct hash object', t => { testCases.forEach(testCase => { const [input, expected] = testCase - t.is( - getTodoStatus(input).total, - expected.total, - `Test for getTodoStatus() input: ${input} expected: ${expected.total}` - ) - t.is( - getTodoStatus(input).completed, - expected.completed, - `Test for getTodoStatus() input: ${input} expected: ${expected.completed}` - ) + expect(getTodoStatus(input).total).toBe(expected.total) + expect(getTodoStatus(input).completed).toBe(expected.completed) }) }) diff --git a/tests/lib/html-text-helper-test.js b/tests/lib/html-text-helper.test.js similarity index 75% rename from tests/lib/html-text-helper-test.js rename to tests/lib/html-text-helper.test.js index 9e6eb083..3cff03c6 100644 --- a/tests/lib/html-text-helper-test.js +++ b/tests/lib/html-text-helper.test.js @@ -1,11 +1,10 @@ /** * @fileoverview Unit test for browser/lib/htmlTextHelper */ -const test = require('ava') const htmlTextHelper = require('browser/lib/htmlTextHelper') // Unit test -test('htmlTextHelper#decodeEntities should return encoded text (string)', t => { +test('htmlTextHelper#decodeEntities should return encoded text (string)', () => { // [input, expected] const testCases = [ ['<a href=', ' { testCases.forEach(testCase => { const [input, expected] = testCase - t.is( - htmlTextHelper.decodeEntities(input), - expected, - `Test for decodeEntities() input: ${input} expected: ${expected}` - ) + expect(htmlTextHelper.decodeEntities(input)).toBe(expected) }) }) -test('htmlTextHelper#decodeEntities() should return decoded text (string)', t => { +test('htmlTextHelper#decodeEntities() should return decoded text (string)', () => { // [input, expected] const testCases = [ [' testCases.forEach(testCase => { const [input, expected] = testCase - t.is( - htmlTextHelper.encodeEntities(input), - expected, - `Test for encodeEntities() input: ${input} expected: ${expected}` - ) + expect(htmlTextHelper.encodeEntities(input)).toBe(expected) }) }) // Integration test -test(t => { +test(() => { const testCases = [ "var test = 'test'", "Boostnote", @@ -63,10 +54,6 @@ test(t => { testCases.forEach(testCase => { const encodedText = htmlTextHelper.encodeEntities(testCase) const decodedText = htmlTextHelper.decodeEntities(encodedText) - t.is( - decodedText, - testCase, - 'Integration test through encodedText() and decodedText()' - ) + expect(decodedText).toBe(testCase) }) }) diff --git a/tests/lib/markdown-text-helper-test.js b/tests/lib/markdown-text-helper.test.js similarity index 85% rename from tests/lib/markdown-text-helper-test.js rename to tests/lib/markdown-text-helper.test.js index 07d05dde..1971f2a6 100644 --- a/tests/lib/markdown-text-helper-test.js +++ b/tests/lib/markdown-text-helper.test.js @@ -1,10 +1,9 @@ /** * @fileoverview Unit test for browser/lib/markdown */ -const test = require('ava') const markdown = require('browser/lib/markdownTextHelper') -test(t => { +test(() => { // [input, expected] const testCases = [ // List @@ -42,10 +41,6 @@ test(t => { testCases.forEach(testCase => { const [input, expected] = testCase - t.is( - markdown.strip(input), - expected, - `Test for strip() input: ${input} expected: ${expected}` - ) + expect(markdown.strip(input)).toBe(expected) }) }) diff --git a/tests/lib/markdown-toc-generator-test.js b/tests/lib/markdown-toc-generator.test.js similarity index 96% rename from tests/lib/markdown-toc-generator-test.js rename to tests/lib/markdown-toc-generator.test.js index def2bcf8..15cbd448 100644 --- a/tests/lib/markdown-toc-generator-test.js +++ b/tests/lib/markdown-toc-generator.test.js @@ -4,11 +4,10 @@ import CodeMirror from 'codemirror' require('codemirror/addon/search/searchcursor.js') -const test = require('ava') const markdownToc = require('browser/lib/markdown-toc-generator') const EOL = require('os').EOL -test(t => { +test(() => { /** * Contains array of test cases in format : * [ @@ -261,15 +260,11 @@ this is a text const expectedToc = testCase[2].trim() const generatedToc = markdownToc.generate(inputMd) - t.is( - generatedToc, - expectedToc, - `generate test : ${title} , generated : ${EOL}${generatedToc}, expected : ${EOL}${expectedToc}` - ) + expect(generatedToc).toBe(expectedToc) }) }) -test(t => { +test(() => { /** * Contains array of test cases in format : * [ @@ -667,10 +662,6 @@ this is a level one text editor.setCursor(cursor) markdownToc.generateInEditor(editor) - t.is( - expectedMd, - editor.getValue(), - `generateInEditor test : ${title} , generated : ${EOL}${editor.getValue()}, expected : ${EOL}${expectedMd}` - ) + expect(expectedMd).toBe(editor.getValue()) }) }) diff --git a/tests/lib/markdown-test.js b/tests/lib/markdown.test.js similarity index 54% rename from tests/lib/markdown-test.js rename to tests/lib/markdown.test.js index 9aec244d..ee93b0ea 100644 --- a/tests/lib/markdown-test.js +++ b/tests/lib/markdown.test.js @@ -1,4 +1,17 @@ -import test from 'ava' +jest.mock( + 'electron', + () => { + return { + remote: { + app: { + getPath: jest.fn().mockReturnValue('.') + } + } + } + }, + { virtual: true } +) + import Markdown from 'browser/lib/markdown' import markdownFixtures from '../fixtures/markdowns' @@ -6,100 +19,100 @@ import markdownFixtures from '../fixtures/markdowns' // To test markdown options, initialize a new instance in your test case const md = new Markdown() -test('Markdown.render() should renders markdown correctly', t => { +test('Markdown.render() should renders markdown correctly', () => { const rendered = md.render(markdownFixtures.basic) - t.snapshot(rendered) + expect(rendered).toMatchSnapshot() }) -test('Markdown.render() should renders codeblock correctly', t => { +test('Markdown.render() should renders codeblock correctly', () => { const rendered = md.render(markdownFixtures.codeblock) - t.snapshot(rendered) + expect(rendered).toMatchSnapshot() }) -test('Markdown.render() should renders KaTeX correctly', t => { +test('Markdown.render() should renders KaTeX correctly', () => { const rendered = md.render(markdownFixtures.katex) - t.snapshot(rendered) + expect(rendered).toMatchSnapshot() }) -test('Markdown.render() should renders checkboxes', t => { +test('Markdown.render() should renders checkboxes', () => { const rendered = md.render(markdownFixtures.checkboxes) - t.snapshot(rendered) + expect(rendered).toMatchSnapshot() }) -test('Markdown.render() should text with quotes correctly', t => { +test('Markdown.render() should text with quotes correctly', () => { const renderedSmartQuotes = md.render(markdownFixtures.smartQuotes) - t.snapshot(renderedSmartQuotes) + expect(renderedSmartQuotes).toMatchSnapshot() const newmd = new Markdown({ typographer: false }) const renderedNonSmartQuotes = newmd.render(markdownFixtures.smartQuotes) - t.snapshot(renderedNonSmartQuotes) + expect(renderedNonSmartQuotes).toMatchSnapshot() }) -test('Markdown.render() should render line breaks correctly', t => { +test('Markdown.render() should render line breaks correctly', () => { const renderedBreaks = md.render(markdownFixtures.breaks) - t.snapshot(renderedBreaks) + expect(renderedBreaks).toMatchSnapshot() const newmd = new Markdown({ breaks: false }) const renderedNonBreaks = newmd.render(markdownFixtures.breaks) - t.snapshot(renderedNonBreaks) + expect(renderedNonBreaks).toMatchSnapshot() }) -test('Markdown.render() should renders abbrevations correctly', t => { +test('Markdown.render() should renders abbrevations correctly', () => { const rendered = md.render(markdownFixtures.abbrevations) - t.snapshot(rendered) + expect(rendered).toMatchSnapshot() }) -test('Markdown.render() should renders sub correctly', t => { +test('Markdown.render() should renders sub correctly', () => { const rendered = md.render(markdownFixtures.subTexts) - t.snapshot(rendered) + expect(rendered).toMatchSnapshot() }) -test('Markdown.render() should renders sup correctly', t => { +test('Markdown.render() should renders sup correctly', () => { const rendered = md.render(markdownFixtures.supTexts) - t.snapshot(rendered) + expect(rendered).toMatchSnapshot() }) -test('Markdown.render() should renders definition lists correctly', t => { +test('Markdown.render() should renders definition lists correctly', () => { const rendered = md.render(markdownFixtures.deflists) - t.snapshot(rendered) + expect(rendered).toMatchSnapshot() }) -test('Markdown.render() should render shortcuts correctly', t => { +test('Markdown.render() should render shortcuts correctly', () => { const rendered = md.render(markdownFixtures.shortcuts) - t.snapshot(rendered) + expect(rendered).toMatchSnapshot() }) -test('Markdown.render() should render footnote correctly', t => { +test('Markdown.render() should render footnote correctly', () => { const rendered = md.render(markdownFixtures.footnote) - t.snapshot(rendered) + expect(rendered).toMatchSnapshot() }) -test('Markdown.render() should renders [TOC] placholder correctly', t => { +test('Markdown.render() should renders [TOC] placholder correctly', () => { const rendered = md.render(markdownFixtures.tocPlaceholder) - t.snapshot(rendered) + expect(rendered).toMatchSnapshot() }) -test('Markdown.render() should render PlantUML MindMaps correctly', t => { +test('Markdown.render() should render PlantUML MindMaps correctly', () => { const rendered = md.render(markdownFixtures.plantUmlMindMap) - t.snapshot(rendered) + expect(rendered).toMatchSnapshot() }) -test('Markdown.render() should render PlantUML Gantt correctly', t => { +test('Markdown.render() should render PlantUML Gantt correctly', () => { const rendered = md.render(markdownFixtures.plantUmlGantt) - t.snapshot(rendered) + expect(rendered).toMatchSnapshot() }) -test('Markdown.render() should render PlantUML WBS correctly', t => { +test('Markdown.render() should render PlantUML WBS correctly', () => { const rendered = md.render(markdownFixtures.plantUmlWbs) - t.snapshot(rendered) + expect(rendered).toMatchSnapshot() }) -test('Markdown.render() should render PlantUML Umls correctly', t => { +test('Markdown.render() should render PlantUML Umls correctly', () => { const rendered = md.render(markdownFixtures.plantUmlUml) - t.snapshot(rendered) + expect(rendered).toMatchSnapshot() }) -test('Markdown.render() should render PlantUML Ditaa correctly', t => { +test('Markdown.render() should render PlantUML Ditaa correctly', () => { const rendered = md.render(markdownFixtures.plantUmlDitaa) - t.snapshot(rendered) + expect(rendered).toMatchSnapshot() }) diff --git a/tests/lib/normalize-editor-font-family-test.js b/tests/lib/normalize-editor-font-family.test.js similarity index 69% rename from tests/lib/normalize-editor-font-family-test.js rename to tests/lib/normalize-editor-font-family.test.js index beb2b765..902c0f83 100644 --- a/tests/lib/normalize-editor-font-family-test.js +++ b/tests/lib/normalize-editor-font-family.test.js @@ -1,19 +1,17 @@ /** * @fileoverview Unit test for browser/lib/normalizeEditorFontFamily */ -import test from 'ava' import normalizeEditorFontFamily from '../../browser/lib/normalizeEditorFontFamily' import consts from '../../browser/lib/consts' const defaultEditorFontFamily = consts.DEFAULT_EDITOR_FONT_FAMILY -test('normalizeEditorFontFamily() should return default font family (string[])', t => { - t.is(normalizeEditorFontFamily(), defaultEditorFontFamily.join(', ')) +test('normalizeEditorFontFamily() should return default font family (string[])', () => { + expect(normalizeEditorFontFamily()).toBe(defaultEditorFontFamily.join(', ')) }) -test('normalizeEditorFontFamily(["hoge", "huga"]) should return default font family connected with arg.', t => { +test('normalizeEditorFontFamily(["hoge", "huga"]) should return default font family connected with arg.', () => { const arg = 'font1, font2' - t.is( - normalizeEditorFontFamily(arg), + expect(normalizeEditorFontFamily(arg)).toBe( `${arg}, ${defaultEditorFontFamily.join(', ')}` ) }) diff --git a/tests/lib/rc-parser-test.js b/tests/lib/rc-parser.test.js similarity index 77% rename from tests/lib/rc-parser-test.js rename to tests/lib/rc-parser.test.js index 2c8213ea..bad744dc 100644 --- a/tests/lib/rc-parser-test.js +++ b/tests/lib/rc-parser.test.js @@ -1,9 +1,8 @@ -const test = require('ava') const path = require('path') const { parse } = require('browser/lib/RcParser') // Unit test -test('RcParser should return a json object', t => { +test('RcParser should return a json object', () => { const validJson = { editor: { keyMap: 'vim', switchPreview: 'BLUR', theme: 'monokai' }, hotkey: { toggleMain: 'Control + L' }, @@ -51,20 +50,12 @@ test('RcParser should return a json object', t => { validTestCases.forEach(validTestCase => { const [input, expected] = validTestCase - t.is( - parse(filePath(input)).editor.keyMap, - expected.editor.keyMap, - `Test for getTodoStatus() input: ${input} expected: ${expected.keyMap}` - ) + expect(parse(filePath(input)).editor.keyMap).toBe(expected.editor.keyMap) }) invalidTestCases.forEach(invalidTestCase => { const [input, expected] = invalidTestCase - t.is( - parse(filePath(input)).editor, - expected.editor, - `Test for getTodoStatus() input: ${input} expected: ${expected.editor}` - ) + expect(parse(filePath(input)).editor).toBe(expected.editor) }) }) diff --git a/tests/lib/search-test.js b/tests/lib/search.test.js similarity index 89% rename from tests/lib/search-test.js rename to tests/lib/search.test.js index 75180d9e..b3c91523 100644 --- a/tests/lib/search-test.js +++ b/tests/lib/search.test.js @@ -1,4 +1,3 @@ -import test from 'ava' import searchFromNotes from 'browser/lib/search' import { dummyNote } from '../fixtures/TestDummy' import _ from 'lodash' @@ -11,7 +10,7 @@ const pickContents = notes => let notes = [] let note1, note2, note3 -test.before(t => { +beforeAll(() => { const data1 = { type: 'MARKDOWN_NOTE', content: 'content1', tags: ['tag1'] } const data2 = { type: 'MARKDOWN_NOTE', @@ -27,7 +26,7 @@ test.before(t => { notes = [note1, note2, note3] }) -test('it can find notes by tags and words', t => { +test('it can find notes by tags and words', () => { // [input, expected content (Array)] const testWithTags = [ ['#tag1', [note1.content, note2.content, note3.content]], @@ -49,6 +48,8 @@ test('it can find notes by tags and words', t => { testCases.forEach(testCase => { const [input, expectedContents] = testCase const results = searchFromNotes(notes, input) - t.true(_.isEqual(pickContents(results).sort(), expectedContents.sort())) + expect( + _.isEqual(pickContents(results).sort(), expectedContents.sort()) + ).toBe(true) }) }) diff --git a/tests/lib/slugify-test.js b/tests/lib/slugify.test.js similarity index 64% rename from tests/lib/slugify-test.js rename to tests/lib/slugify.test.js index 39991bca..4d346755 100644 --- a/tests/lib/slugify-test.js +++ b/tests/lib/slugify.test.js @@ -1,58 +1,57 @@ -import test from 'ava' import slugify from 'browser/lib/slugify' -test('alphabet and digit', t => { +test('alphabet and digit', () => { const upperAlphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' const lowerAlphabet = 'abcdefghijklmnopqrstuvwxyz' const digit = '0123456789' const testCase = upperAlphabet + lowerAlphabet + digit const decodeSlug = decodeURI(slugify(testCase)) - t.true(decodeSlug === testCase) + expect(decodeSlug === testCase).toBe(true) }) -test('should delete unavailable symbols', t => { +test('should delete unavailable symbols', () => { const availableSymbols = '_-' const testCase = availableSymbols + "][!'#$%&()*+,./:;<=>?@\\^{|}~`" const decodeSlug = decodeURI(slugify(testCase)) - t.true(decodeSlug === availableSymbols) + expect(decodeSlug === availableSymbols).toBe(true) }) -test('should convert from white spaces between words to hyphens', t => { +test('should convert from white spaces between words to hyphens', () => { const testCase = 'This is one' const expectedString = 'This-is-one' const decodeSlug = decodeURI(slugify(testCase)) - t.true(decodeSlug === expectedString) + expect(decodeSlug === expectedString).toBe(true) }) -test('should remove leading white spaces', t => { +test('should remove leading white spaces', () => { const testCase = ' This is one' const expectedString = 'This-is-one' const decodeSlug = decodeURI(slugify(testCase)) - t.true(decodeSlug === expectedString) + expect(decodeSlug === expectedString).toBe(true) }) -test('should remove trailing white spaces', t => { +test('should remove trailing white spaces', () => { const testCase = 'This is one ' const expectedString = 'This-is-one' const decodeSlug = decodeURI(slugify(testCase)) - t.true(decodeSlug === expectedString) + expect(decodeSlug === expectedString).toBe(true) }) -test('2-byte charactor support', t => { +test('2-byte charactor support', () => { const testCase = 'θ θθŠ’ζžœγƒ†γ‚ΉγƒˆΓ€ΕΎΖΖ΅' const decodeSlug = decodeURI(slugify(testCase)) - t.true(decodeSlug === testCase) + expect(decodeSlug === testCase).toBe(true) }) -test('emoji', t => { +test('emoji', () => { const testCase = '🌸' const decodeSlug = decodeURI(slugify(testCase)) - t.true(decodeSlug === testCase) + expect(decodeSlug === testCase).toBe(true) }) diff --git a/tests/lib/snapshots/markdown-test.js.snap b/tests/lib/snapshots/markdown-test.js.snap deleted file mode 100644 index ade26489..00000000 Binary files a/tests/lib/snapshots/markdown-test.js.snap and /dev/null differ