1
- const test = require ( 'ava' )
2
1
const createNote = require ( 'browser/main/lib/dataApi/createNote' )
3
2
4
3
global . document = require ( 'jsdom' ) . jsdom ( '<body></body>' )
@@ -19,14 +18,16 @@ const faker = require('faker')
19
18
20
19
const storagePath = path . join ( os . tmpdir ( ) , 'test/create-note' )
21
20
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 ] ) )
25
26
} )
26
27
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
30
31
31
32
const randLinesHighlightedArray = new Array ( 10 )
32
33
. fill ( )
@@ -58,58 +59,58 @@ test.serial('Create a note', t => {
58
59
input2 . title = input2 . content . split ( '\n' ) . shift ( )
59
60
60
61
return Promise . resolve ( )
61
- . then ( function doTest ( ) {
62
+ . then ( ( ) => {
62
63
return Promise . all ( [
63
64
createNote ( storageKey , input1 ) ,
64
65
createNote ( storageKey , input2 )
65
66
] )
66
67
} )
67
- . then ( function assert ( data ) {
68
+ . then ( data => {
68
69
const data1 = data [ 0 ]
69
70
const data2 = data [ 1 ]
70
71
71
- t . is ( storageKey , data1 . storage )
72
+ expect ( storageKey ) . toEqual ( data1 . storage )
72
73
const jsonData1 = CSON . readFileSync (
73
74
path . join ( storagePath , 'notes' , data1 . key + '.cson' )
74
75
)
75
76
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 (
90
90
data1 . snippets [ 0 ] . linesHighlighted
91
91
)
92
- t . deepEqual (
93
- input1 . snippets [ 0 ] . linesHighlighted ,
92
+ expect ( input1 . snippets [ 0 ] . linesHighlighted ) . toEqual (
94
93
jsonData1 . snippets [ 0 ] . linesHighlighted
95
94
)
96
95
97
- t . is ( storageKey , data2 . storage )
96
+ expect ( storageKey ) . toEqual ( data2 . storage )
98
97
const jsonData2 = CSON . readFileSync (
99
98
path . join ( storagePath , 'notes' , data2 . key + '.cson' )
100
99
)
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 ( )
109
110
} )
110
111
} )
111
112
112
- test . after ( function after ( ) {
113
+ afterAll ( function after ( ) {
113
114
localStorage . clear ( )
114
115
sander . rimrafSync ( storagePath )
115
116
} )
0 commit comments