From ffb26034853684577eeccd4df9991dd7b8938df0 Mon Sep 17 00:00:00 2001 From: amedora Date: Wed, 7 Aug 2019 14:17:48 +0900 Subject: [PATCH 1/4] jest-codemods tests/lib --- tests/lib/escapeHtmlCharacters-test.js | 29 +++++----- tests/lib/find-storage-test.js | 11 ++-- tests/lib/find-title-test.js | 17 +++--- tests/lib/get-todo-status-test.js | 7 ++- tests/lib/html-text-helper-test.js | 13 +++-- tests/lib/markdown-test.js | 53 +++++++++---------- tests/lib/markdown-text-helper-test.js | 5 +- tests/lib/markdown-toc-generator-test.js | 9 ++-- .../lib/normalize-editor-font-family-test.js | 9 ++-- tests/lib/rc-parser-test.js | 7 ++- tests/lib/search-test.js | 7 ++- tests/lib/slugify-test.js | 29 +++++----- 12 files changed, 92 insertions(+), 104 deletions(-) diff --git a/tests/lib/escapeHtmlCharacters-test.js b/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 index 3d7fdc63..0504881a 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('') @@ -13,20 +12,20 @@ const sander = require('sander') const os = require('os') const storagePath = path.join(os.tmpdir(), 'test/find-storage') -test.beforeEach((t) => { +beforeEach(() => { t.context.storage = TestDummy.dummyStorage(storagePath) localStorage.setItem('storages', JSON.stringify([t.context.storage.cache])) }) // Unit test -test('findStorage() should return a correct storage path(string)', t => { +test('findStorage() should return a correct storage path(string)', () => { const storageKey = t.context.storage.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 index 103b8774..2e0c49d7 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,11 +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'], @@ -34,11 +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 = [ ['---\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 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'], @@ -61,6 +60,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 index db74ec56..8acae04f 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,8 +39,8 @@ 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 index 538b8757..1d8fe795 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', @@ -49,6 +48,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-test.js b/tests/lib/markdown-test.js index 31ffc518..917924cb 100644 --- a/tests/lib/markdown-test.js +++ b/tests/lib/markdown-test.js @@ -1,4 +1,3 @@ -import test from 'ava' import Markdown from 'browser/lib/markdown' import markdownFixtures from '../fixtures/markdowns' @@ -6,70 +5,70 @@ 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() }) diff --git a/tests/lib/markdown-text-helper-test.js b/tests/lib/markdown-text-helper-test.js index 38ee3136..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,6 +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 index 60568741..77c37005 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,11 +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 : * [ @@ -663,6 +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/normalize-editor-font-family-test.js b/tests/lib/normalize-editor-font-family-test.js index aacd03ac..7fec7eaf 100644 --- a/tests/lib/normalize-editor-font-family-test.js +++ b/tests/lib/normalize-editor-font-family-test.js @@ -1,16 +1,15 @@ /** * @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), `${arg}, ${defaultEditorFontFamily.join(', ')}`) + expect(normalizeEditorFontFamily(arg)).toBe(`${arg}, ${defaultEditorFontFamily.join(', ')}`) }) diff --git a/tests/lib/rc-parser-test.js b/tests/lib/rc-parser-test.js index 024a2d36..0548e3ff 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' }, 'listWidth': 135, 'navWidth': 135 } const allJson = { 'amaEnabled': true, 'editor': { 'fontFamily': 'Monaco, Consolas', 'fontSize': '14', 'indentSize': '2', 'indentType': 'space', 'keyMap': 'vim', 'switchPreview': 'BLUR', 'theme': 'monokai' }, 'hotkey': { 'toggleMain': 'Cmd + Alt + L' }, 'isSideNavFolded': false, 'listStyle': 'DEFAULT', 'listWidth': 174, 'navWidth': 200, 'preview': { 'codeBlockTheme': 'dracula', 'fontFamily': 'Lato', 'fontSize': '14', 'lineNumber': true }, 'sortBy': { 'default': 'UPDATED_AT' }, 'ui': { 'defaultNote': 'ALWAYS_ASK', 'disableDirectWrite': false, 'theme': 'default' }, 'zoom': 1 } @@ -19,12 +18,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 index 2e288d26..6c52097f 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' @@ -8,7 +7,7 @@ const pickContents = (notes) => notes.map((note) => { return note.content }) let notes = [] let note1, note2, note3 -test.before(t => { +beforeAll(() => { const data1 = { type: 'MARKDOWN_NOTE', content: 'content1', tags: ['tag1'] } const data2 = { type: 'MARKDOWN_NOTE', content: 'content1\ncontent2', tags: ['tag1', 'tag2'] } const data3 = { type: 'MARKDOWN_NOTE', content: '#content4', tags: ['tag1'] } @@ -20,7 +19,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]], @@ -42,6 +41,6 @@ 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 index 0277bd10..71305454 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) }) From 404dddcb868ecc0363dacbac1c6a3deeea2f99c4 Mon Sep 17 00:00:00 2001 From: amedora Date: Wed, 7 Aug 2019 14:28:38 +0900 Subject: [PATCH 2/4] rename files to suit Jest --- ...{escapeHtmlCharacters-test.js => escapeHtmlCharacters.test.js} | 0 tests/lib/{find-storage-test.js => find-storage.test.js} | 0 tests/lib/{find-title-test.js => find-title.test.js} | 0 tests/lib/{get-todo-status-test.js => get-todo-status.test.js} | 0 tests/lib/{html-text-helper-test.js => html-text-helper.test.js} | 0 ...{markdown-text-helper-test.js => markdown-text-helper.test.js} | 0 ...kdown-toc-generator-test.js => markdown-toc-generator.test.js} | 0 tests/lib/{markdown-test.js => markdown.test.js} | 0 ...r-font-family-test.js => normalize-editor-font-family.test.js} | 0 tests/lib/{rc-parser-test.js => rc-parser.test.js} | 0 tests/lib/{search-test.js => search.test.js} | 0 tests/lib/{slugify-test.js => slugify.test.js} | 0 12 files changed, 0 insertions(+), 0 deletions(-) rename tests/lib/{escapeHtmlCharacters-test.js => escapeHtmlCharacters.test.js} (100%) rename tests/lib/{find-storage-test.js => find-storage.test.js} (100%) rename tests/lib/{find-title-test.js => find-title.test.js} (100%) rename tests/lib/{get-todo-status-test.js => get-todo-status.test.js} (100%) rename tests/lib/{html-text-helper-test.js => html-text-helper.test.js} (100%) rename tests/lib/{markdown-text-helper-test.js => markdown-text-helper.test.js} (100%) rename tests/lib/{markdown-toc-generator-test.js => markdown-toc-generator.test.js} (100%) rename tests/lib/{markdown-test.js => markdown.test.js} (100%) rename tests/lib/{normalize-editor-font-family-test.js => normalize-editor-font-family.test.js} (100%) rename tests/lib/{rc-parser-test.js => rc-parser.test.js} (100%) rename tests/lib/{search-test.js => search.test.js} (100%) rename tests/lib/{slugify-test.js => slugify.test.js} (100%) diff --git a/tests/lib/escapeHtmlCharacters-test.js b/tests/lib/escapeHtmlCharacters.test.js similarity index 100% rename from tests/lib/escapeHtmlCharacters-test.js rename to tests/lib/escapeHtmlCharacters.test.js diff --git a/tests/lib/find-storage-test.js b/tests/lib/find-storage.test.js similarity index 100% rename from tests/lib/find-storage-test.js rename to tests/lib/find-storage.test.js diff --git a/tests/lib/find-title-test.js b/tests/lib/find-title.test.js similarity index 100% rename from tests/lib/find-title-test.js rename to tests/lib/find-title.test.js diff --git a/tests/lib/get-todo-status-test.js b/tests/lib/get-todo-status.test.js similarity index 100% rename from tests/lib/get-todo-status-test.js rename to tests/lib/get-todo-status.test.js diff --git a/tests/lib/html-text-helper-test.js b/tests/lib/html-text-helper.test.js similarity index 100% rename from tests/lib/html-text-helper-test.js rename to tests/lib/html-text-helper.test.js diff --git a/tests/lib/markdown-text-helper-test.js b/tests/lib/markdown-text-helper.test.js similarity index 100% rename from tests/lib/markdown-text-helper-test.js rename to tests/lib/markdown-text-helper.test.js diff --git a/tests/lib/markdown-toc-generator-test.js b/tests/lib/markdown-toc-generator.test.js similarity index 100% rename from tests/lib/markdown-toc-generator-test.js rename to tests/lib/markdown-toc-generator.test.js diff --git a/tests/lib/markdown-test.js b/tests/lib/markdown.test.js similarity index 100% rename from tests/lib/markdown-test.js rename to tests/lib/markdown.test.js diff --git a/tests/lib/normalize-editor-font-family-test.js b/tests/lib/normalize-editor-font-family.test.js similarity index 100% rename from tests/lib/normalize-editor-font-family-test.js rename to tests/lib/normalize-editor-font-family.test.js diff --git a/tests/lib/rc-parser-test.js b/tests/lib/rc-parser.test.js similarity index 100% rename from tests/lib/rc-parser-test.js rename to tests/lib/rc-parser.test.js diff --git a/tests/lib/search-test.js b/tests/lib/search.test.js similarity index 100% rename from tests/lib/search-test.js rename to tests/lib/search.test.js diff --git a/tests/lib/slugify-test.js b/tests/lib/slugify.test.js similarity index 100% rename from tests/lib/slugify-test.js rename to tests/lib/slugify.test.js From e4e10d523fac38f256d0b2e1af613badd3c015da Mon Sep 17 00:00:00 2001 From: amedora Date: Wed, 7 Aug 2019 14:52:17 +0900 Subject: [PATCH 3/4] fix how handle the storage as context data --- tests/lib/find-storage.test.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/lib/find-storage.test.js b/tests/lib/find-storage.test.js index 0504881a..77a7ca64 100644 --- a/tests/lib/find-storage.test.js +++ b/tests/lib/find-storage.test.js @@ -12,14 +12,16 @@ const sander = require('sander') const os = require('os') const storagePath = path.join(os.tmpdir(), 'test/find-storage') +let storageContext + beforeEach(() => { - t.context.storage = TestDummy.dummyStorage(storagePath) - localStorage.setItem('storages', JSON.stringify([t.context.storage.cache])) + storageContext = TestDummy.dummyStorage(storagePath) + localStorage.setItem('storages', JSON.stringify([storageContext.cache])) }) // Unit test test('findStorage() should return a correct storage path(string)', () => { - const storageKey = t.context.storage.cache.key + const storageKey = storageContext.cache.key expect(findStorage(storageKey).key).toBe(storageKey) expect(findStorage(storageKey).path).toBe(storagePath) From 39216551573b6372df133df36558984b2cc5091f Mon Sep 17 00:00:00 2001 From: amedora Date: Wed, 7 Aug 2019 15:22:27 +0900 Subject: [PATCH 4/4] replace the snapshot file --- tests/lib/__snapshots__/markdown.test.js.snap | 144 +++++++++++++++ tests/lib/snapshots/markdown-test.js.md | 172 ------------------ tests/lib/snapshots/markdown-test.js.snap | Bin 2471 -> 0 bytes 3 files changed, 144 insertions(+), 172 deletions(-) create mode 100644 tests/lib/__snapshots__/markdown.test.js.snap delete mode 100644 tests/lib/snapshots/markdown-test.js.md delete mode 100644 tests/lib/snapshots/markdown-test.js.snap diff --git a/tests/lib/__snapshots__/markdown.test.js.snap b/tests/lib/__snapshots__/markdown.test.js.snap new file mode 100644 index 00000000..d782ce39 --- /dev/null +++ b/tests/lib/__snapshots__/markdown.test.js.snap @@ -0,0 +1,144 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +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 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`] = ` +"
    +
  • Unchecked
  • +
  • Checked
  • +
+" +`; + +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/snapshots/markdown-test.js.md b/tests/lib/snapshots/markdown-test.js.md deleted file mode 100644 index 4111c2f2..00000000 --- a/tests/lib/snapshots/markdown-test.js.md +++ /dev/null @@ -1,172 +0,0 @@ -# Snapshot report for `tests/lib/markdown-test.js` - -The actual snapshot is saved in `markdown-test.js.snap`. - -Generated by [AVA](https://ava.li). - -## Markdown.render() should render footnote correctly - -> Snapshot 1 - - `

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

␊ -
␊ -
␊ -
    ␊ -
  1. hello-world ↩︎

    ␊ -
  2. ␊ -
␊ -
␊ - ` - -## Markdown.render() should render line breaks correctly - -> Snapshot 1 - - `

This is the first line.
␊ - This is the second line.

␊ - ` - -> Snapshot 2 - - `

This is the first line.␊ - This is the second line.

␊ - ` - -## Markdown.render() should render shortcuts correctly - -> Snapshot 1 - - `

Ctrl

␊ -

Ctrl

␊ - ` - -## Markdown.render() should renders KaTeX correctly - -> Snapshot 1 - - `c=pmsqrta2+b2c = pmsqrt{a^2 + b^2}␊ - ` - -## Markdown.render() should renders abbrevations correctly - -> Snapshot 1 - - `

abbr

␊ -

The HTML specification
␊ - is maintained by the W3C.

␊ - ` - -## Markdown.render() should renders checkboxes - -> Snapshot 1 - - `
    ␊ -
  • Unchecked
  • ␊ -
  • Checked
  • ␊ -
␊ - ` - -## Markdown.render() should renders codeblock correctly - -> Snapshot 1 - - `
␊
-            filename.js␊
-            2␊
-            var project = 'boostnote';␊
-    ␊
-          
` - -## Markdown.render() should renders definition lists correctly - -> Snapshot 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.

␊ -
␊ -
␊ - ` - -## Markdown.render() should renders markdown correctly - -> Snapshot 1 - - `

Welcome to Boostnote!

␊ -

Click here to edit markdown 👋

␊ - ␊ -

Docs 📝

␊ - ␊ -
␊ -

Article Archive 📚

␊ - ␊ -
␊ -

Community 🍻

␊ - ␊ - ` - -## Markdown.render() should renders sub correctly - -> Snapshot 1 - - `

sub

␊ -

H20

␊ - ` - -## Markdown.render() should renders sup correctly - -> Snapshot 1 - - `

sup

␊ -

29th

␊ - ` - -## Markdown.render() should text with quotes correctly - -> Snapshot 1 - - `

This is a “QUOTE”.

␊ - ` - -> Snapshot 2 - - `

This is a "QUOTE".

␊ - ` diff --git a/tests/lib/snapshots/markdown-test.js.snap b/tests/lib/snapshots/markdown-test.js.snap deleted file mode 100644 index 3f5ec41c0d4710ca98ea132da2e1ca9c30ff7799..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2471 zcmV;Y30U?)RzVr=7)FxiPRiiN_u!mDdGJb&Z0vtO$`cTYi{Jg_v7fA6_lGS-DShSMLgCbvV^L_`bN%NF|9Im=m%s4Pkd(gfzT}yJ=gWt# zpR8Uw@$@6!bEoDvJnsxi>9zEE2cFI64?n%`cYnOF{!j0mZhZbph*d~$tS=NAuRnS7 z=GTW8e>O_jJo~FRPZXte(}qIfudlv(AiZmx@w)9-jAJIrHZ5)Ppbo z`i-~j&;9NG=d<-IbyYS)p-fBdJXpSk+lM<4vu zg{e;-zgCpe!=ES=h6*2$%oX2XxOeEGH8rP#T)VE!5YM7MQ8`t2QX27qa-tv`bF6x9 zKM&^#ViLt@4+nZQ85$&@P#bCs>c&EVg*sTJnuej< zp4-!fu|8dxb-5FpGJNT2??J8YU0ZaUt~TM(*jA4$2bLSm%D8tzx8qO@Ikcd(1#QHB zxE&>J(ZCqS?BbD*jvLv7h$uln73^>G-fZlLalgg}|gS}Vp zcG7UXq)tM1@kEA!N!pnogo`->?Z|1hi*SwvZWuyaGBoXYG?@?_hO|x|*}=GL!MxkS zEXQ5QWmm`+X*){WMSA(>;Pg_-FHY#9>GG1dtm*#2eTQN|JWOnnR(A)po*OxX>FT$} zL@H&{UQ)(7$?7zTv^MsU5C-|>53fNZA!JcqL@)|tMdcUc?0`^?k!QO`<@GN-0 zF`J;i9|w>mv%A-bSgC0XjMHO38az(==-_eMF*9?fxl1t~cKKv%4(?}uE9rtbGq&^S zzT=89z36gI*kFtmrpugV;W4fld$0vNBWGXr~%nDfQ?o$T5qK}NGL*OfQ0}&5W|+vx}2%AvFJFYr;Kiw zf-noDnPTXvgC0M!3#siKfGuDq_RKkAaa2c}+LLJ0cA!Hjw`^+~5MgAnOxe~?24xd>d=Hw$3n&mD2aq2k5HPw3->zZRH2ALh)TqN7m9j9ExrX0< zi`sAV?Kjqbr%%QyG%O1?)q~zRIE)7@9BcsIME_P{%+*2`Z1;Ms5h?Krz z_)uyh5u{BTIQC$fS$);uk44)4pc0;iO^~Ht^{tuD*kEsrz?`Z7hduN`TPoe9%o?0$d#)pT8?|{Q_b!z_V)S^|X4PdTZ9T`jLn*X<8^cL%EbwTq%YRala zSuosx#z0{nn>phJs3o|{`$}0qY40K$8y&8cJ5ypj8F*=!szTAdO|6zHl`6F5nHuTR zPaTDQC!b#0I&e-!?iq0iVNe5b75

B)+T2=fbuxV`)on6S;$*J6Mmo&)~ITx`85c z@_*06Y9^5R{|WTJm_YyfCtIierqHfQ(?B?mno~gPUQYacp;mK)Fy@Fahw$HWh}AUd zk|GP?)<0EOpgu-N11TVOr`YU+k5Z-l)z1Jwsdm<1Rr;IAcpMsJNv<(!6#Bv*Hk(Y7+q59Z`!!)4V$Xu3zXV7OT^K3NZ zLQy_LOept*h(gT}`-(ABok+3!a5mZMo=7{n-bLbw)wgq#HE5Ho5`N0PsCzr8VJ~Vp z097Bai8`1&0$0?-`N4Q;sD%q@)P=JoFr+34FYBYzj6`$ljVnKvs+&bg4H3TReA z(-tYf=G`iAf}JMJ7b-Rvt#s8v1f6RgU6V6w-ouzo zFtAO5F`i{ObOb`z+|x_ly_JKMStk2>5>~Bg+QtNDUQH8kY0&xIppQ~!om?yC=7QK; zA>p(x5-3eB(HUuUU2;6o2r9|m)d)ZUMkgvKlS>V`9Fu9}5YMCPqDVK}(4E~GD#ohR z5|?3ewUi4vQX>*7^1=!7wj?>PA!Y*gdJScsNOs<&kI>mXA+Fftjaq1Q^%8XxBzfsE lGqKf_T;96;{o5~G>2x67eW_STS{ksi_MfXTBG{lC005BY)zAO{