@@ -6,7 +6,6 @@ const del = require('del');
66const { Command } = require ( 'commander' ) ;
77const svgo = require ( '../../lib/svgo/coa.js' ) ;
88
9- const svgPath = path . resolve ( __dirname , 'test.svg' ) ;
109const svgFolderPath = path . resolve ( __dirname , 'testSvg' ) ;
1110const svgFolderPathRecursively = path . resolve ( __dirname , 'testSvgRecursively' ) ;
1211const svgFiles = [
@@ -28,10 +27,7 @@ function runProgram(args) {
2827}
2928
3029describe ( 'coa' , function ( ) {
31- let output ;
32-
3330 beforeEach ( async ( ) => {
34- output = '' ;
3531 await del ( tempFolder ) ;
3632 await fs . promises . mkdir ( tempFolder ) ;
3733 } ) ;
@@ -40,25 +36,10 @@ describe('coa', function () {
4036 await del ( tempFolder ) ;
4137 } ) ;
4238
43- const initialConsoleLog = global . console . log ;
44-
45- function replaceConsoleLog ( ) {
46- global . console . log = ( message ) => {
47- output += message ;
48- } ;
49- }
50-
51- function restoreConsoleLog ( ) {
52- global . console . log = initialConsoleLog ;
53- }
54-
5539 const initialConsoleError = global . console . error ;
5640 const initialProcessExit = global . process . exit ;
5741
5842 function replaceConsoleError ( ) {
59- global . console . error = ( message ) => {
60- output += message ;
61- } ;
6243 global . process . exit = noop ;
6344 }
6445
@@ -83,17 +64,6 @@ describe('coa', function () {
8364 ) ;
8465 }
8566
86- it ( 'should work properly with string input' , async ( ) => {
87- await runProgram ( [
88- '--string' ,
89- fs . readFileSync ( svgPath , 'utf8' ) ,
90- '--output' ,
91- 'temp.svg' ,
92- '--quiet' ,
93- ] ) ;
94- await del ( 'temp.svg' ) ;
95- } ) ;
96-
9767 it ( 'should optimize folder' , async ( ) => {
9868 const initWeight = calcFolderSvgWeight ( svgFolderPath ) ;
9969 await runProgram ( [
@@ -123,16 +93,6 @@ describe('coa', function () {
12393 expect ( initWeight ) . toBeLessThanOrEqual ( optimizedWeight ) ;
12494 } ) ;
12595
126- it ( 'should optimize file' , async ( ) => {
127- const initialFileLength = fs . readFileSync (
128- path . resolve ( __dirname , 'test.svg' )
129- ) . length ;
130- await runProgram ( [ '--input' , svgPath , '--output' , 'temp.svg' , '--quiet' ] ) ;
131- const optimizedFileLength = fs . readFileSync ( 'temp.svg' ) . length ;
132- expect ( optimizedFileLength ) . toBeLessThanOrEqual ( initialFileLength ) ;
133- await del ( 'temp.svg' ) ;
134- } ) ;
135-
13696 it ( 'should optimize several files' , async ( ) => {
13797 const initWeight = calcFolderSvgWeight ( svgFolderPath ) ;
13898 await runProgram ( [
@@ -148,29 +108,6 @@ describe('coa', function () {
148108 await del ( 'temp.svg' ) ;
149109 } ) ;
150110
151- it ( 'should optimize file from process.stdin' , async ( ) => {
152- const initialFile = fs . readFileSync ( path . resolve ( __dirname , 'test.svg' ) ) ;
153- const stdin = require ( 'mock-stdin' ) . stdin ( ) ;
154- setTimeout ( ( ) => {
155- stdin . send ( initialFile , 'ascii' ) . end ( ) ;
156- } , 1000 ) ;
157- try {
158- await runProgram ( [
159- '--input' ,
160- '-' ,
161- '--output' ,
162- 'temp.svg' ,
163- '--string' ,
164- fs . readFileSync ( svgPath , 'utf8' ) ,
165- '--quiet' ,
166- ] ) ;
167- } finally {
168- const optimizedFileLength = fs . readFileSync ( 'temp.svg' ) . length ;
169- expect ( optimizedFileLength ) . toBeLessThanOrEqual ( initialFile . length ) ;
170- await del ( 'temp.svg' ) ;
171- }
172- } ) ;
173-
174111 it ( 'should optimize folder, when it stated in input' , async ( ) => {
175112 const initWeight = calcFolderSvgWeight ( svgFolderPath ) ;
176113 await runProgram ( [
@@ -200,23 +137,6 @@ describe('coa', function () {
200137 } ) ;
201138
202139 describe ( 'stdout' , ( ) => {
203- it ( 'should show file content when no output set' , async ( ) => {
204- replaceConsoleLog ( ) ;
205- try {
206- await runProgram ( [
207- '--string' ,
208- fs . readFileSync ( svgPath , 'utf8' ) ,
209- '--output' ,
210- '-' ,
211- '--datauri' ,
212- 'unenc' ,
213- ] ) ;
214- } finally {
215- restoreConsoleLog ( ) ;
216- expect ( output ) . toMatch ( / w w w \. w 3 \. o r g \/ 2 0 0 0 \/ s v g / ) ;
217- }
218- } ) ;
219-
220140 it ( 'should show message when the folder is empty' , async ( ) => {
221141 const emptyFolderPath = path . resolve ( __dirname , 'testSvgEmpty' ) ;
222142 if ( ! fs . existsSync ( emptyFolderPath ) ) {
@@ -240,15 +160,5 @@ describe('coa', function () {
240160 expect ( error . message ) . toMatch ( / N o S V G f i l e s h a v e b e e n f o u n d / ) ;
241161 }
242162 } ) ;
243-
244- it ( 'should show plugins' , async ( ) => {
245- replaceConsoleLog ( ) ;
246- try {
247- await runProgram ( [ '--show-plugins' ] ) ;
248- } finally {
249- restoreConsoleLog ( ) ;
250- expect ( output ) . toMatch ( / C u r r e n t l y a v a i l a b l e p l u g i n s : / ) ;
251- }
252- } ) ;
253163 } ) ;
254164} ) ;
0 commit comments