Skip to content

Commit 634fec3

Browse files
committed
migrate more tests to jest
1 parent d269f1e commit 634fec3

File tree

3 files changed

+35
-37
lines changed

3 files changed

+35
-37
lines changed

tests/dataApi/createNoteFromUrl-test.js renamed to tests/dataApi/createNoteFromUrl.test.js

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
const test = require('ava')
21
const createNoteFromUrl = require('browser/main/lib/dataApi/createNoteFromUrl')
32

43
global.document = require('jsdom').jsdom('<body></body>')
@@ -18,32 +17,34 @@ const CSON = require('@rokt33r/season')
1817

1918
const storagePath = path.join(os.tmpdir(), 'test/create-note-from-url')
2019

21-
test.beforeEach(t => {
22-
t.context.storage = TestDummy.dummyStorage(storagePath)
23-
localStorage.setItem('storages', JSON.stringify([t.context.storage.cache]))
20+
let storageContext
21+
22+
beforeEach(() => {
23+
storageContext = TestDummy.dummyStorage(storagePath)
24+
localStorage.setItem('storages', JSON.stringify([storageContext.cache]))
2425
})
2526

26-
test.serial('Create a note from URL', t => {
27-
const storageKey = t.context.storage.cache.key
28-
const folderKey = t.context.storage.json.folders[0].key
27+
it('Create a note from URL', () => {
28+
const storageKey = storageContext.cache.key
29+
const folderKey = storageContext.json.folders[0].key
2930

3031
const url = 'https://shapeshed.com/writing-cross-platform-node/'
3132

3233
return createNoteFromUrl(url, storageKey, folderKey).then(function assert({
3334
note
3435
}) {
35-
t.is(storageKey, note.storage)
36+
expect(storageKey).toEqual(note.storage)
3637
const jsonData = CSON.readFileSync(
3738
path.join(storagePath, 'notes', note.key + '.cson')
3839
)
3940

4041
// Test if saved content is matching the created in memory note
41-
t.is(note.content, jsonData.content)
42-
t.is(note.tags.length, jsonData.tags.length)
42+
expect(note.content).toEqual(jsonData.content)
43+
expect(note.tags.length).toEqual(jsonData.tags.length)
4344
})
4445
})
4546

46-
test.after(function after() {
47+
afterAll(function after() {
4748
localStorage.clear()
4849
sander.rimrafSync(storagePath)
4950
})
Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
const test = require('ava')
21
const createSnippet = require('browser/main/lib/dataApi/createSnippet')
32
const sander = require('sander')
43
const os = require('os')
@@ -7,29 +6,27 @@ const path = require('path')
76
const snippetFilePath = path.join(os.tmpdir(), 'test', 'create-snippet')
87
const snippetFile = path.join(snippetFilePath, 'snippets.json')
98

10-
test.beforeEach(t => {
9+
beforeEach(() => {
1110
sander.writeFileSync(snippetFile, '[]')
1211
})
1312

14-
test.serial('Create a snippet', t => {
13+
it('Create a snippet', () => {
1514
return Promise.resolve()
16-
.then(function doTest() {
17-
return Promise.all([createSnippet(snippetFile)])
18-
})
15+
.then(() => Promise.all([createSnippet(snippetFile)]))
1916
.then(function assert(data) {
2017
data = data[0]
2118
const snippets = JSON.parse(sander.readFileSync(snippetFile))
2219
const snippet = snippets.find(
2320
currentSnippet => currentSnippet.id === data.id
2421
)
25-
t.not(snippet, undefined)
26-
t.is(snippet.name, data.name)
27-
t.deepEqual(snippet.prefix, data.prefix)
28-
t.is(snippet.content, data.content)
29-
t.deepEqual(snippet.linesHighlighted, data.linesHighlighted)
22+
expect(snippet).not.toBeUndefined()
23+
expect(snippet.name).toEqual(data.name)
24+
expect(snippet.prefix).toEqual(data.prefix)
25+
expect(snippet.content).toEqual(data.content)
26+
expect(snippet.linesHighlighted).toEqual(data.linesHighlighted)
3027
})
3128
})
3229

33-
test.after.always(() => {
30+
afterAll(() => {
3431
sander.rimrafSync(snippetFilePath)
3532
})

tests/dataApi/deleteFolder-test.js renamed to tests/dataApi/deleteFolder.test.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
const test = require('ava')
21
const deleteFolder = require('browser/main/lib/dataApi/deleteFolder')
32
const attachmentManagement = require('browser/main/lib/dataApi/attachmentManagement')
43
const createNote = require('browser/main/lib/dataApi/createNote')
@@ -23,14 +22,16 @@ const CSON = require('@rokt33r/season')
2322

2423
const storagePath = path.join(os.tmpdir(), 'test/delete-folder')
2524

26-
test.beforeEach(t => {
27-
t.context.storage = TestDummy.dummyStorage(storagePath)
28-
localStorage.setItem('storages', JSON.stringify([t.context.storage.cache]))
25+
let storageContext
26+
27+
beforeEach(() => {
28+
storageContext = TestDummy.dummyStorage(storagePath)
29+
localStorage.setItem('storages', JSON.stringify([storageContext.cache]))
2930
})
3031

31-
test.serial('Delete a folder', t => {
32-
const storageKey = t.context.storage.cache.key
33-
const folderKey = t.context.storage.json.folders[0].key
32+
it('Delete a folder', () => {
33+
const storageKey = storageContext.cache.key
34+
const folderKey = storageContext.json.folders[0].key
3435
let noteKey
3536

3637
const input1 = {
@@ -72,28 +73,27 @@ test.serial('Delete a folder', t => {
7273
return deleteFolder(storageKey, folderKey)
7374
})
7475
.then(function assert(data) {
75-
t.true(_.find(data.storage.folders, { key: folderKey }) == null)
76+
expect(_.find(data.storage.folders, { key: folderKey })).toBeUndefined()
7677
const jsonData = CSON.readFileSync(
7778
path.join(data.storage.path, 'boostnote.json')
7879
)
7980

80-
t.true(_.find(jsonData.folders, { key: folderKey }) == null)
81+
expect(_.find(jsonData.folders, { key: folderKey })).toBeUndefined()
8182
const notePaths = sander.readdirSync(data.storage.path, 'notes')
82-
t.is(
83-
notePaths.length,
84-
t.context.storage.notes.filter(note => note.folder !== folderKey).length
83+
expect(notePaths.length).toBe(
84+
storageContext.notes.filter(note => note.folder !== folderKey).length
8585
)
8686

8787
const attachmentFolderPath = path.join(
8888
storagePath,
8989
attachmentManagement.DESTINATION_FOLDER,
9090
noteKey
9191
)
92-
t.false(fs.existsSync(attachmentFolderPath))
92+
expect(fs.existsSync(attachmentFolderPath)).toBe(false)
9393
})
9494
})
9595

96-
test.after.always(function after() {
96+
afterAll(() => {
9797
localStorage.clear()
9898
sander.rimrafSync(storagePath)
9999
})

0 commit comments

Comments
 (0)