11'use strict' ;
22
33const { test, stub} = require ( 'supertape' ) ;
4- const mockRequire = require ( 'mock-require' ) ;
54
65const {
76 NO_FORMATTER ,
109
1110const { getFormatter} = require ( './formatter.cjs' ) ;
1211
13- const { reRequire, stopAll} = mockRequire ;
14-
1512test ( 'putout: cli: formatter: get formatter' , async ( t ) => {
1613 const exit = stub ( ) ;
1714
@@ -53,15 +50,10 @@ test('putout: cli: formatter: get formatter: options', async (t) => {
5350
5451test ( 'putout: cli: formatter: get reporter: exit: NO_FORMATTER' , async ( t ) => {
5552 const exit = stub ( ) ;
56- const { getFormatter} = reRequire ( './formatter.cjs' ) ;
57-
5853 await getFormatter ( 'xxx' , exit ) ;
5954
6055 const expected = [ NO_FORMATTER , Error ( `Cannot find package 'putout-formatter-xxx'` ) ] ;
6156
62- stopAll ( ) ;
63- reRequire ( './formatter.cjs' ) ;
64-
6557 t . calledWith ( exit , expected , 'should call exit' ) ;
6658 t . end ( ) ;
6759} ) ;
@@ -70,18 +62,12 @@ test('putout: cli: formatter: get reporter: exit: CANNOT_LOAD_FORMATTER', async
7062 const exit = stub ( ) ;
7163 const createAsyncLoader = stub ( ) . returns ( stub ( ) . rejects ( Error ( '@putout/formatter-xxx: Syntax error' ) ) ) ;
7264
73- mockRequire ( '@putout/engine-loader' , {
65+ await getFormatter ( 'xxx' , exit , {
7466 createAsyncLoader,
7567 } ) ;
7668
77- const { getFormatter} = reRequire ( './formatter.cjs' ) ;
78- await getFormatter ( 'xxx' , exit ) ;
79-
8069 const expected = [ CANNOT_LOAD_FORMATTER , Error ( `@putout/formatter-xxx: Syntax error` ) ] ;
8170
82- stopAll ( ) ;
83- reRequire ( './formatter.cjs' ) ;
84-
8571 t . calledWith ( exit , expected , 'should call exit' ) ;
8672 t . end ( ) ;
8773} ) ;
@@ -90,18 +76,12 @@ test('putout: cli: formatter: get reporter: pass load', async (t) => {
9076 const exit = stub ( ) ;
9177 const simpleImport = stub ( ) . rejects ( Error ( 'simple import' ) ) ;
9278
93- mockRequire ( 'putout/simple-import' , {
79+ await getFormatter ( 'xxx' , exit , {
9480 simpleImport,
9581 } ) ;
9682
97- const { getFormatter} = reRequire ( './formatter.cjs' ) ;
98- await getFormatter ( 'xxx' , exit ) ;
99-
10083 const expected = [ CANNOT_LOAD_FORMATTER , Error ( `@putout/formatter-xxx: simple import` ) ] ;
10184
102- stopAll ( ) ;
103- reRequire ( './formatter.cjs' ) ;
104-
10585 t . calledWith ( exit , expected , 'should call exit' ) ;
10686 t . end ( ) ;
10787} ) ;
0 commit comments