1- import path from 'path' ;
2- import fs from 'fs' ;
3- import { lockFile , unlockFile , readFile } from '../index' ;
1+ import path from "path" ;
2+ import fs from "fs" ;
3+
4+ import { lockFile , unlockFile , readFile } from "../index" ;
45
56interface Error {
67 message : string ;
@@ -17,97 +18,109 @@ const removeTempFile = (filename: string): void => {
1718 } ) ;
1819} ;
1920
20- describe ( ' testing locking' , ( ) => {
21- test ( ' file should be found to be locked' , done => {
22- lockFile ( getFilePath ( ' package.json' ) , ( error : Error ) => {
21+ describe ( " testing locking" , ( ) => {
22+ test ( " file should be found to be locked" , done => {
23+ lockFile ( getFilePath ( " package.json" ) , ( error : Error ) => {
2324 expect ( error ) . toBeNull ( ) ;
24- removeTempFile ( ' package.json.lock' ) ;
25+ removeTempFile ( " package.json.lock" ) ;
2526 done ( ) ;
2627 } ) ;
2728 } ) ;
2829
29- test ( 'file should fail to be found to be locked' , done => {
30- lockFile ( getFilePath ( 'package.fail.json' ) , ( error : Error ) => {
31- expect ( error . message ) . toMatch ( / E N O E N T : n o s u c h f i l e o r d i r e c t o r y , s t a t ' ( .* ) p a c k a g e .f a i l .j s o n ' / ) ;
30+ test ( "file should fail to be found to be locked" , done => {
31+ lockFile ( getFilePath ( "package.fail.json" ) , ( error : Error ) => {
32+ expect ( error . message ) . toMatch (
33+ / E N O E N T : n o s u c h f i l e o r d i r e c t o r y , s t a t ' ( .* ) p a c k a g e .f a i l .j s o n ' /
34+ ) ;
3235 done ( ) ;
3336 } ) ;
3437 } ) ;
3538
36- test ( ' file should to be found to be unLock' , done => {
37- unlockFile ( getFilePath ( ' package.json.lock' ) , ( error : Error ) => {
39+ test ( " file should to be found to be unLock" , done => {
40+ unlockFile ( getFilePath ( " package.json.lock" ) , ( error : Error ) => {
3841 expect ( error ) . toBeNull ( ) ;
3942 done ( ) ;
4043 } ) ;
4144 } ) ;
4245
43- test ( ' read file with no options should to be found to be read it as string' , done => {
44- readFile ( getFilePath ( ' package.json' ) , ( error : Error , data : any ) => {
46+ test ( " read file with no options should to be found to be read it as string" , done => {
47+ readFile ( getFilePath ( " package.json" ) , ( error : Error , data : any ) => {
4548 expect ( error ) . toBeNull ( ) ;
4649 expect ( data ) . toMatchSnapshot ( ) ;
4750 done ( ) ;
4851 } ) ;
4952 } ) ;
5053
51- test ( ' read file with no options should to be found to be read it as object' , done => {
54+ test ( " read file with no options should to be found to be read it as object" , done => {
5255 const options = {
53- parse : true ,
56+ parse : true
5457 } ;
55- readFile ( getFilePath ( 'package.json' ) , options , ( error : Error , data : any ) => {
56- expect ( error ) . toBeNull ( ) ;
57- expect ( data ) . toMatchSnapshot ( ) ;
58- done ( ) ;
59- } ) ;
58+ readFile (
59+ getFilePath ( "package.json" ) ,
60+ options ,
61+ ( error : Error , data : any ) => {
62+ expect ( error ) . toBeNull ( ) ;
63+ expect ( data ) . toMatchSnapshot ( ) ;
64+ done ( ) ;
65+ }
66+ ) ;
6067 } ) ;
6168
62- test ( ' read file with options (parse) should to be not found to be read it' , done => {
69+ test ( " read file with options (parse) should to be not found to be read it" , done => {
6370 const options = {
64- parse : true ,
71+ parse : true
6572 } ;
66- readFile ( getFilePath ( 'package.fail.json' ) , options , ( error : Error ) => {
67- expect ( error . message ) . toMatch ( / E N O E N T : n o s u c h f i l e o r d i r e c t o r y , o p e n ' ( .* ) p a c k a g e .f a i l .j s o n ' / ) ;
73+ readFile ( getFilePath ( "package.fail.json" ) , options , ( error : Error ) => {
74+ expect ( error . message ) . toMatch (
75+ / E N O E N T : n o s u c h f i l e o r d i r e c t o r y , o p e n ' ( .* ) p a c k a g e .f a i l .j s o n ' /
76+ ) ;
6877 done ( ) ;
6978 } ) ;
7079 } ) ;
7180
72- test ( ' read file with options should to be found to be read it and fails to be parsed' , done => {
81+ test ( " read file with options should to be found to be read it and fails to be parsed" , done => {
7382 const options = {
74- parse : true ,
83+ parse : true
7584 } ;
7685 const errorMessage =
77- process . platform === ' win32'
78- ? ' Unexpected token } in JSON at position 47'
79- : ' Unexpected token } in JSON at position 44' ;
80- readFile ( getFilePath ( ' wrong.package.json' ) , options , ( error : Error ) => {
86+ process . platform === " win32"
87+ ? " Unexpected token } in JSON at position 47"
88+ : " Unexpected token } in JSON at position 44" ;
89+ readFile ( getFilePath ( " wrong.package.json" ) , options , ( error : Error ) => {
8190 expect ( error . message ) . toEqual ( errorMessage ) ;
8291 done ( ) ;
8392 } ) ;
8493 } ) ;
8594
86- test ( ' read file with options (parse, lock) should to be found to be read it as object' , done => {
95+ test ( " read file with options (parse, lock) should to be found to be read it as object" , done => {
8796 const options = {
8897 parse : true ,
89- lock : true ,
98+ lock : true
9099 } ;
91- readFile ( getFilePath ( 'package2.json' ) , options , ( error : Error , data : any ) => {
92- expect ( error ) . toBeNull ( ) ;
93- expect ( data ) . toMatchSnapshot ( ) ;
94- removeTempFile ( 'package2.json.lock' ) ;
95- done ( ) ;
96- } ) ;
100+ readFile (
101+ getFilePath ( "package2.json" ) ,
102+ options ,
103+ ( error : Error , data : any ) => {
104+ expect ( error ) . toBeNull ( ) ;
105+ expect ( data ) . toMatchSnapshot ( ) ;
106+ removeTempFile ( "package2.json.lock" ) ;
107+ done ( ) ;
108+ }
109+ ) ;
97110 } ) ;
98111
99- test ( ' read file with options (parse, lock) should to be found to be read it and fails to be parsed' , done => {
112+ test ( " read file with options (parse, lock) should to be found to be read it and fails to be parsed" , done => {
100113 const options = {
101114 parse : true ,
102- lock : true ,
115+ lock : true
103116 } ;
104117 const errorMessage =
105- process . platform === ' win32'
106- ? ' Unexpected token } in JSON at position 47'
107- : ' Unexpected token } in JSON at position 44' ;
108- readFile ( getFilePath ( ' wrong.package.json' ) , options , ( error : Error ) => {
118+ process . platform === " win32"
119+ ? " Unexpected token } in JSON at position 47"
120+ : " Unexpected token } in JSON at position 44" ;
121+ readFile ( getFilePath ( " wrong.package.json" ) , options , ( error : Error ) => {
109122 expect ( error . message ) . toEqual ( errorMessage ) ;
110- removeTempFile ( ' wrong.package.json.lock' ) ;
123+ removeTempFile ( " wrong.package.json.lock" ) ;
111124 done ( ) ;
112125 } ) ;
113126 } ) ;
0 commit comments