@@ -6,7 +6,6 @@ const del = require('del');
6
6
const { Command } = require ( 'commander' ) ;
7
7
const svgo = require ( '../../lib/svgo/coa.js' ) ;
8
8
9
- const svgPath = path . resolve ( __dirname , 'test.svg' ) ;
10
9
const svgFolderPath = path . resolve ( __dirname , 'testSvg' ) ;
11
10
const svgFolderPathRecursively = path . resolve ( __dirname , 'testSvgRecursively' ) ;
12
11
const svgFiles = [
@@ -28,10 +27,7 @@ function runProgram(args) {
28
27
}
29
28
30
29
describe ( 'coa' , function ( ) {
31
- let output ;
32
-
33
30
beforeEach ( async ( ) => {
34
- output = '' ;
35
31
await del ( tempFolder ) ;
36
32
await fs . promises . mkdir ( tempFolder ) ;
37
33
} ) ;
@@ -40,25 +36,10 @@ describe('coa', function () {
40
36
await del ( tempFolder ) ;
41
37
} ) ;
42
38
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
-
55
39
const initialConsoleError = global . console . error ;
56
40
const initialProcessExit = global . process . exit ;
57
41
58
42
function replaceConsoleError ( ) {
59
- global . console . error = ( message ) => {
60
- output += message ;
61
- } ;
62
43
global . process . exit = noop ;
63
44
}
64
45
@@ -83,17 +64,6 @@ describe('coa', function () {
83
64
) ;
84
65
}
85
66
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
-
97
67
it ( 'should optimize folder' , async ( ) => {
98
68
const initWeight = calcFolderSvgWeight ( svgFolderPath ) ;
99
69
await runProgram ( [
@@ -123,16 +93,6 @@ describe('coa', function () {
123
93
expect ( initWeight ) . toBeLessThanOrEqual ( optimizedWeight ) ;
124
94
} ) ;
125
95
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
-
136
96
it ( 'should optimize several files' , async ( ) => {
137
97
const initWeight = calcFolderSvgWeight ( svgFolderPath ) ;
138
98
await runProgram ( [
@@ -148,29 +108,6 @@ describe('coa', function () {
148
108
await del ( 'temp.svg' ) ;
149
109
} ) ;
150
110
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
-
174
111
it ( 'should optimize folder, when it stated in input' , async ( ) => {
175
112
const initWeight = calcFolderSvgWeight ( svgFolderPath ) ;
176
113
await runProgram ( [
@@ -200,23 +137,6 @@ describe('coa', function () {
200
137
} ) ;
201
138
202
139
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
-
220
140
it ( 'should show message when the folder is empty' , async ( ) => {
221
141
const emptyFolderPath = path . resolve ( __dirname , 'testSvgEmpty' ) ;
222
142
if ( ! fs . existsSync ( emptyFolderPath ) ) {
@@ -240,15 +160,5 @@ describe('coa', function () {
240
160
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 / ) ;
241
161
}
242
162
} ) ;
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
- } ) ;
253
163
} ) ;
254
164
} ) ;
0 commit comments