@@ -4,15 +4,16 @@ import { validateTransform, loadTransform, Transform } from '../src/transform';
44jest . mock ( 'bundle-require' , ( ) => ( { bundleRequire : jest . fn ( ) } ) ) ;
55
66describe ( 'transform' , ( ) => {
7- let exit : jest . SpyInstance ;
7+ let consoleError : jest . SpyInstance ;
8+ let processExit : jest . SpyInstance ;
89
910 beforeEach ( ( ) => {
10- console . error = jest . fn ( ) ;
11- exit = jest . spyOn ( process , 'exit' ) . mockImplementation ( ) ;
11+ consoleError = jest . spyOn ( console , 'error' ) . mockImplementation ( ) ;
12+ processExit = jest . spyOn ( process , 'exit' ) . mockImplementation ( ) ;
1213 } ) ;
1314
1415 afterEach ( ( ) => {
15- exit . mockRestore ( ) ;
16+ jest . restoreAllMocks ( ) ;
1617 } ) ;
1718
1819 describe ( '#validateTransform' , ( ) => {
@@ -26,25 +27,25 @@ describe('transform', () => {
2627 const twoArg : Transform = ( _fileInfo , _api ) => null ;
2728 expect ( validateTransform ( twoArg ) ) . toBe ( twoArg ) ;
2829
29- expect ( console . error ) . not . toHaveBeenCalled ( ) ;
30- expect ( exit ) . not . toHaveBeenCalled ( ) ;
30+ expect ( consoleError ) . not . toHaveBeenCalled ( ) ;
31+ expect ( processExit ) . not . toHaveBeenCalled ( ) ;
3132 } ) ;
3233
3334 it ( 'should exit if an invalid transform is provided since there is no way to recover' , ( ) => {
34- expect ( console . error ) . toHaveBeenCalledTimes ( 0 ) ;
35- expect ( exit ) . toHaveBeenCalledTimes ( 0 ) ;
35+ expect ( consoleError ) . toHaveBeenCalledTimes ( 0 ) ;
36+ expect ( processExit ) . toHaveBeenCalledTimes ( 0 ) ;
3637
3738 validateTransform ( null ) ;
38- expect ( console . error ) . toHaveBeenCalledTimes ( 1 ) ;
39- expect ( exit ) . toHaveBeenCalledTimes ( 1 ) ;
39+ expect ( consoleError ) . toHaveBeenCalledTimes ( 1 ) ;
40+ expect ( processExit ) . toHaveBeenCalledTimes ( 1 ) ;
4041
4142 validateTransform ( undefined ) ;
42- expect ( console . error ) . toHaveBeenCalledTimes ( 2 ) ;
43- expect ( exit ) . toHaveBeenCalledTimes ( 2 ) ;
43+ expect ( consoleError ) . toHaveBeenCalledTimes ( 2 ) ;
44+ expect ( processExit ) . toHaveBeenCalledTimes ( 2 ) ;
4445
4546 validateTransform ( ( _fileInfo : any , _api : any , _invalid : any ) => null ) ;
46- expect ( console . error ) . toHaveBeenCalledTimes ( 3 ) ;
47- expect ( exit ) . toHaveBeenCalledTimes ( 3 ) ;
47+ expect ( consoleError ) . toHaveBeenCalledTimes ( 3 ) ;
48+ expect ( processExit ) . toHaveBeenCalledTimes ( 3 ) ;
4849 } ) ;
4950 } ) ;
5051
@@ -58,8 +59,8 @@ describe('transform', () => {
5859 } ) ;
5960
6061 expect ( await loadTransform ( './transform.ts' ) ) . toBe ( transform ) ;
61- expect ( console . error ) . not . toHaveBeenCalled ( ) ;
62- expect ( exit ) . not . toHaveBeenCalled ( ) ;
62+ expect ( consoleError ) . not . toHaveBeenCalled ( ) ;
63+ expect ( processExit ) . not . toHaveBeenCalled ( ) ;
6364 } ) ;
6465
6566 it ( 'should load the transform file and fallback to the default export' , async ( ) => {
@@ -70,8 +71,8 @@ describe('transform', () => {
7071 } ) ;
7172
7273 expect ( await loadTransform ( './transform.ts' ) ) . toBe ( transform ) ;
73- expect ( console . error ) . not . toHaveBeenCalled ( ) ;
74- expect ( exit ) . not . toHaveBeenCalled ( ) ;
74+ expect ( consoleError ) . not . toHaveBeenCalled ( ) ;
75+ expect ( processExit ) . not . toHaveBeenCalled ( ) ;
7576 } ) ;
7677
7778 it ( 'should exit if an error occurs loading the transform file' , async ( ) => {
@@ -80,8 +81,8 @@ describe('transform', () => {
8081 ) ;
8182
8283 await loadTransform ( './transform.ts' ) ;
83- expect ( console . error ) . toHaveBeenCalledTimes ( 1 ) ;
84- expect ( exit ) . toHaveBeenCalledTimes ( 1 ) ;
84+ expect ( consoleError ) . toHaveBeenCalledTimes ( 1 ) ;
85+ expect ( processExit ) . toHaveBeenCalledTimes ( 1 ) ;
8586 } ) ;
8687 } ) ;
8788} ) ;
0 commit comments