Skip to content

Commit 137aa69

Browse files
authored
Merge pull request #3547 from ZeroX-DG/migrate-to-jest
[WIP] Migrate to jest
2 parents 4b67026 + 634fec3 commit 137aa69

21 files changed

+407
-267
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ node_modules/*
1111
.idea
1212
.vscode
1313
package-lock.json
14+
config.json

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

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

43
const path = require('path')
@@ -13,23 +12,25 @@ const srcPath = path.join(srcFolder, testFile)
1312
const dstFolder = path.join(__dirname, '😇')
1413
const dstPath = path.join(dstFolder, testFile)
1514

16-
test.before(t => {
15+
beforeAll(() => {
1716
if (!fs.existsSync(srcFolder)) fs.mkdirSync(srcFolder)
1817

1918
fs.writeFileSync(srcPath, 'test')
2019
})
2120

22-
test('`copyFile` should handle encoded URI on src path', t => {
21+
it('`copyFile` should handle encoded URI on src path', done => {
2322
return copyFile(encodeURI(srcPath), dstPath)
2423
.then(() => {
25-
t.true(true)
24+
expect(true).toBe(true)
25+
done()
2626
})
2727
.catch(() => {
28-
t.true(false)
28+
expect(false).toBe(true)
29+
done()
2930
})
3031
})
3132

32-
test.after(t => {
33+
afterAll(() => {
3334
fs.unlinkSync(srcPath)
3435
fs.unlinkSync(dstPath)
3536
execSync(removeDirCommand + '"' + srcFolder + '"')

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

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

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

2019
const storagePath = path.join(os.tmpdir(), 'test/create-folder')
2120

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

27-
test.serial('Create a folder', t => {
28-
const storageKey = t.context.storage.cache.key
28+
it('Create a folder', done => {
29+
const storageKey = storageContext.cache.key
2930
const input = {
3031
name: 'created',
3132
color: '#ff5555'
3233
}
3334
return Promise.resolve()
34-
.then(function doTest() {
35+
.then(() => {
3536
return createFolder(storageKey, input)
3637
})
37-
.then(function assert(data) {
38-
t.true(_.find(data.storage.folders, input) != null)
38+
.then(data => {
39+
expect(_.find(data.storage.folders, input)).not.toBeNull()
3940
const jsonData = CSON.readFileSync(
4041
path.join(data.storage.path, 'boostnote.json')
4142
)
42-
console.log(path.join(data.storage.path, 'boostnote.json'))
43-
t.true(_.find(jsonData.folders, input) != null)
43+
expect(_.find(jsonData.folders, input)).not.toBeNull()
44+
done()
4445
})
4546
})
4647

47-
test.after(function after() {
48+
afterAll(() => {
4849
localStorage.clear()
4950
sander.rimrafSync(storagePath)
5051
})

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

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

43
global.document = require('jsdom').jsdom('<body></body>')
@@ -19,14 +18,16 @@ const faker = require('faker')
1918

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

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

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

3132
const randLinesHighlightedArray = new Array(10)
3233
.fill()
@@ -58,58 +59,58 @@ test.serial('Create a note', t => {
5859
input2.title = input2.content.split('\n').shift()
5960

6061
return Promise.resolve()
61-
.then(function doTest() {
62+
.then(() => {
6263
return Promise.all([
6364
createNote(storageKey, input1),
6465
createNote(storageKey, input2)
6566
])
6667
})
67-
.then(function assert(data) {
68+
.then(data => {
6869
const data1 = data[0]
6970
const data2 = data[1]
7071

71-
t.is(storageKey, data1.storage)
72+
expect(storageKey).toEqual(data1.storage)
7273
const jsonData1 = CSON.readFileSync(
7374
path.join(storagePath, 'notes', data1.key + '.cson')
7475
)
7576

76-
t.is(input1.title, data1.title)
77-
t.is(input1.title, jsonData1.title)
78-
t.is(input1.description, data1.description)
79-
t.is(input1.description, jsonData1.description)
80-
t.is(input1.tags.length, data1.tags.length)
81-
t.is(input1.tags.length, jsonData1.tags.length)
82-
t.is(input1.snippets.length, data1.snippets.length)
83-
t.is(input1.snippets.length, jsonData1.snippets.length)
84-
t.is(input1.snippets[0].content, data1.snippets[0].content)
85-
t.is(input1.snippets[0].content, jsonData1.snippets[0].content)
86-
t.is(input1.snippets[0].name, data1.snippets[0].name)
87-
t.is(input1.snippets[0].name, jsonData1.snippets[0].name)
88-
t.deepEqual(
89-
input1.snippets[0].linesHighlighted,
77+
expect(input1.title).toEqual(data1.title)
78+
expect(input1.title).toEqual(jsonData1.title)
79+
expect(input1.description).toEqual(data1.description)
80+
expect(input1.description).toEqual(jsonData1.description)
81+
expect(input1.tags.length).toEqual(data1.tags.length)
82+
expect(input1.tags.length).toEqual(jsonData1.tags.length)
83+
expect(input1.snippets.length).toEqual(data1.snippets.length)
84+
expect(input1.snippets.length).toEqual(jsonData1.snippets.length)
85+
expect(input1.snippets[0].content).toEqual(data1.snippets[0].content)
86+
expect(input1.snippets[0].content).toEqual(jsonData1.snippets[0].content)
87+
expect(input1.snippets[0].name).toEqual(data1.snippets[0].name)
88+
expect(input1.snippets[0].name).toEqual(jsonData1.snippets[0].name)
89+
expect(input1.snippets[0].linesHighlighted).toEqual(
9090
data1.snippets[0].linesHighlighted
9191
)
92-
t.deepEqual(
93-
input1.snippets[0].linesHighlighted,
92+
expect(input1.snippets[0].linesHighlighted).toEqual(
9493
jsonData1.snippets[0].linesHighlighted
9594
)
9695

97-
t.is(storageKey, data2.storage)
96+
expect(storageKey).toEqual(data2.storage)
9897
const jsonData2 = CSON.readFileSync(
9998
path.join(storagePath, 'notes', data2.key + '.cson')
10099
)
101-
t.is(input2.title, data2.title)
102-
t.is(input2.title, jsonData2.title)
103-
t.is(input2.content, data2.content)
104-
t.is(input2.content, jsonData2.content)
105-
t.is(input2.tags.length, data2.tags.length)
106-
t.is(input2.tags.length, jsonData2.tags.length)
107-
t.deepEqual(input2.linesHighlighted, data2.linesHighlighted)
108-
t.deepEqual(input2.linesHighlighted, jsonData2.linesHighlighted)
100+
expect(input2.title).toEqual(data2.title)
101+
expect(input2.title).toEqual(jsonData2.title)
102+
expect(input2.content).toEqual(data2.content)
103+
expect(input2.content).toEqual(jsonData2.content)
104+
expect(input2.tags.length).toEqual(data2.tags.length)
105+
expect(input2.tags.length).toEqual(jsonData2.tags.length)
106+
expect(input2.linesHighlighted).toEqual(data2.linesHighlighted)
107+
expect(input2.linesHighlighted).toEqual(jsonData2.linesHighlighted)
108+
109+
done()
109110
})
110111
})
111112

112-
test.after(function after() {
113+
afterAll(function after() {
113114
localStorage.clear()
114115
sander.rimrafSync(storagePath)
115116
})

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)