11'use strict' ;
22
3- let os = require ( 'os' ) ;
4- let path = require ( 'path' ) ;
5- let fs = require ( 'fs' ) ;
6- let test = require ( 'tape' ) ;
7- let writejson = require ( '..' ) ;
3+ const os = require ( 'os' ) ;
4+ const path = require ( 'path' ) ;
5+ const fs = require ( 'fs' ) ;
6+ const test = require ( 'tape' ) ;
7+ const writejson = require ( '..' ) ;
88
99const tmp = os . tmpdir ( ) ;
1010const NAME = path . join ( tmp , String ( Math . random ( ) ) ) ;
@@ -13,7 +13,7 @@ const json = {
1313 bye : 'sword'
1414} ;
1515
16- test ( 'writejson: should write json data to file' , t => {
16+ test ( 'writejson: should write json data to file' , ( t ) => {
1717 writejson ( NAME , json , error => {
1818 t . notOk ( error , 'no write error' ) ;
1919
@@ -29,18 +29,18 @@ test('writejson: should write json data to file', t => {
2929 } ) ;
3030} ) ;
3131
32- test ( 'writejson: should write json data to file with options' , t => {
33- let result = {
32+ test ( 'writejson: should write json data to file with options' , ( t ) => {
33+ const result = {
3434 hello : 'world'
3535 } ;
3636
37- let options = {
37+ const options = {
3838 replacer : [ 'hello' ] ,
3939 space : 2 ,
4040 eof : false
4141 } ;
4242
43- let resultStr = JSON . stringify ( json , options . replacer , options . space ) ;
43+ const resultStr = JSON . stringify ( json , options . replacer , options . space ) ;
4444
4545 writejson ( NAME , json , options , error => {
4646 t . notOk ( error , 'no write error' ) ;
@@ -59,9 +59,8 @@ test('writejson: should write json data to file with options', t => {
5959 } ) ;
6060} ) ;
6161
62- test ( 'writejson: should write json data to file with default options' , t => {
63- let resultStr = JSON . stringify ( json , null , 4 ) ;
64- resultStr += '\n' ;
62+ test ( 'writejson: should write json data to file with default options' , ( t ) => {
63+ const resultStr = JSON . stringify ( json , null , 4 ) + '\n'
6564
6665 writejson ( NAME , json , error => {
6766 t . notOk ( error , 'no write error' ) ;
@@ -80,74 +79,74 @@ test('writejson: should write json data to file with default options', t => {
8079 } ) ;
8180} ) ;
8281
83- test ( 'writejson: write error' , t => {
82+ test ( 'writejson: write error' , ( t ) => {
8483 writejson ( '/hello.json' , json , error => {
8584 t . ok ( error , 'should return error: ' + error . message ) ;
8685 t . end ( ) ;
8786 } ) ;
8887} ) ;
8988
90- test ( 'writejson.sync.try: write error' , t => {
91- let error = writejson . sync . try ( '/hello.json' , json ) ;
89+ test ( 'writejson.sync.try: write error' , ( t ) => {
90+ const error = writejson . sync . try ( '/hello.json' , json ) ;
9291
9392 t . ok ( error , 'should return error: ' + error . message ) ;
9493 t . end ( ) ;
9594} ) ;
9695
97- test ( 'writejson: no args' , t => {
96+ test ( 'writejson: no args' , ( t ) => {
9897 t . throws ( writejson , / n a m e s h o u l d b e s t r i n g ! / , 'NAME check' ) ;
9998 t . end ( ) ;
10099} ) ;
101100
102- test ( 'writejson: no json' , t => {
103- let fn = ( ) => writejson ( 'hello' ) ;
101+ test ( 'writejson: no json' , ( t ) => {
102+ const fn = ( ) => writejson ( 'hello' ) ;
104103
105104 t . throws ( fn , / j s o n s h o u l d b e o b j e c t ! / , 'json check' ) ;
106105 t . end ( ) ;
107106} ) ;
108107
109- test ( 'writejson: options not object' , t => {
110- let fn = ( ) => writejson ( 'hello' , { } , 'options' , ( ) => { } ) ;
108+ test ( 'writejson: options not object' , ( t ) => {
109+ const fn = ( ) => writejson ( 'hello' , { } , 'options' , ( ) => { } ) ;
111110
112111 t . throws ( fn , / o p t i o n s s h o u l d b e o b j e c t ! / , 'options check' ) ;
113112 t . end ( ) ;
114113} ) ;
115114
116- test ( 'writejson: no callback' , t => {
117- let fn = ( ) => writejson ( 'hello' , [ 1 , 2 , 3 ] ) ;
115+ test ( 'writejson: no callback' , ( t ) => {
116+ const fn = ( ) => writejson ( 'hello' , [ 1 , 2 , 3 ] ) ;
118117
119118 t . throws ( fn , / c a l l b a c k s h o u l d b e f u n c t i o n ! / , 'callback check' ) ;
120119 t . end ( ) ;
121120} ) ;
122121
123- test ( 'writejson.sync: should write json data to file synchonously' , t => {
122+ test ( 'writejson.sync: should write json data to file synchonously' , ( t ) => {
124123 writejson . sync ( NAME , json ) ;
125- let data = fs . readFileSync ( NAME , 'utf8' ) ;
124+ const data = fs . readFileSync ( NAME , 'utf8' ) ;
126125 t . ok ( data , 'data should be read' ) ;
127126 t . deepEqual ( json , JSON . parse ( data ) , 'data should be equal' ) ;
128127 fs . unlinkSync ( NAME ) ;
129128 t . end ( ) ;
130129} ) ;
131130
132- test ( 'writejson.sync: no args' , t => {
131+ test ( 'writejson.sync: no args' , ( t ) => {
133132 t . throws ( writejson . sync , / n a m e s h o u l d b e s t r i n g ! / , 'NAME check' ) ;
134133 t . end ( ) ;
135134} ) ;
136135
137- test ( 'writejson.sync: no json' , t => {
138- let fn = ( ) => writejson . sync ( 'hello' ) ;
136+ test ( 'writejson.sync: no json' , ( t ) => {
137+ const fn = ( ) => writejson . sync ( 'hello' ) ;
139138
140139 t . throws ( fn , / j s o n s h o u l d b e o b j e c t ! / , 'json check' ) ;
141140 t . end ( ) ;
142141} ) ;
143142
144- test ( 'writejson.sync.try: no args' , t => {
143+ test ( 'writejson.sync.try: no args' , ( t ) => {
145144 t . throws ( writejson . sync . try , / n a m e s h o u l d b e s t r i n g ! / , 'NAME check' ) ;
146145 t . end ( ) ;
147146} ) ;
148147
149- test ( 'writejson.sync.try: no json' , t => {
150- let fn = ( ) => writejson . sync . try ( 'hello' ) ;
148+ test ( 'writejson.sync.try: no json' , ( t ) => {
149+ const fn = ( ) => writejson . sync . try ( 'hello' ) ;
151150
152151 t . throws ( fn , / j s o n s h o u l d b e o b j e c t ! / , 'json check' ) ;
153152 t . end ( ) ;
0 commit comments