@@ -4,10 +4,38 @@ jest.setTimeout(10e6);
4
4
/* eslint-disable node/no-unsupported-features */
5
5
/* eslint-disable node/no-unsupported-features/es-syntax */
6
6
7
- const { runWatch, extractSummary } = require ( "../../../testUtils" ) ;
7
+ const { extractSummary, extractHash, appendDataIfFileExists, runAndGetWatchProc } = require ( "../../../testUtils" ) ;
8
+ const fs = require ( "fs" ) ;
9
+ const path = require ( "path" ) ;
8
10
9
- test ( "info-verbosity-off" , async done => {
10
- const result = await runWatch ( __dirname , [
11
+ const fileToChange = "index.js" ;
12
+ const copyFile = "index_copy.js" ;
13
+ const fileToChangePath = path . resolve ( __dirname , fileToChange ) ;
14
+ const copyFilePath = path . resolve ( __dirname , copyFile ) ;
15
+
16
+ // create copy of "index.js" => "index_copy.js"
17
+ beforeEach ( ( ) => {
18
+ // fs.copyFileSync was added in Added in: v8.5.0
19
+ // We should migrate it once we stop support for v6.x
20
+ fs . createReadStream ( fileToChangePath ) . pipe ( fs . createWriteStream ( copyFilePath ) ) ;
21
+ } ) ;
22
+
23
+ afterEach ( ( ) => {
24
+ try {
25
+ // deleting the file as it is modified by the test
26
+ // subsequent test-case runs won't pass as snapshot is not matched
27
+ fs . unlinkSync ( fileToChangePath ) ;
28
+ } catch ( e ) {
29
+ console . warn ( "could not remove the file:" + fileToChangePath + "\n" + e . message ) ;
30
+ } finally {
31
+ fs . renameSync ( copyFilePath , fileToChangePath ) ;
32
+ }
33
+ } ) ;
34
+
35
+ // It is modifying the index.js
36
+ // Which breaks the test-cases second time
37
+ test . only ( "info-verbosity-off" , async done => {
38
+ var webpackProc = runAndGetWatchProc ( __dirname , [
11
39
"--entry " ,
12
40
"./index.js" ,
13
41
"--config" ,
@@ -22,15 +50,39 @@ test("info-verbosity-off", async done => {
22
50
"--info-verbosity" ,
23
51
"none"
24
52
] ) ;
25
- const { stdout, stderr } = result ;
26
53
27
- const summary = extractSummary ( stdout ) ;
54
+ var outputCount = 0 ;
55
+ var hash1 ;
56
+
57
+ webpackProc . stdout . on ( "data" , data => {
58
+ data = data . toString ( ) ;
59
+
60
+ if ( outputCount === 0 ) {
61
+ hash1 = extractHash ( data ) ;
62
+
63
+ const summary = extractSummary ( data ) ;
64
+
65
+ expect ( summary ) . toEqual ( expect . anything ( ) ) ;
66
+ expect ( summary ) . toContain ( "" ) ;
67
+ expect ( summary ) . not . toContain ( "webpack is watching the files…" ) ;
68
+ expect ( summary ) . toMatchSnapshot ( ) ;
69
+
70
+ // change file
71
+ appendDataIfFileExists ( __dirname , fileToChange , "//junk-comment" ) ;
72
+
73
+ outputCount ++ ;
74
+ } else {
75
+ const hash2 = extractHash ( data ) ;
28
76
29
- expect ( summary ) . toEqual ( expect . anything ( ) ) ;
30
- expect ( summary ) . toContain ( "" ) ;
31
- expect ( summary ) . not . toContain ( "webpack is watching the files…" ) ;
77
+ expect ( hash2 . hash ) . not . toBe ( hash1 . hash ) ;
78
+ webpackProc . kill ( ) ;
79
+ done ( ) ;
80
+ }
81
+ } ) ;
32
82
33
- expect ( stderr ) . toHaveLength ( 0 ) ;
34
- expect ( summary ) . toMatchSnapshot ( ) ;
35
- done ( ) ;
83
+ webpackProc . stderr . on ( "data" , error => {
84
+ // fail test case if there is any error
85
+ expect ( true ) . toBe ( false ) ;
86
+ done ( ) ;
87
+ } ) ;
36
88
} ) ;
0 commit comments