@@ -57,7 +57,22 @@ function distFileExists(
57
57
}
58
58
59
59
describe ( 'extension build' , ( ) => {
60
+ afterAll ( async ( ) => {
61
+ // Clean up any mocks
62
+ jest . clearAllMocks ( )
63
+ // Clean up any remaining test artifacts
64
+ await removeAllTemplateDistFolders ( )
65
+ // Clear all timers
66
+ jest . useRealTimers ( )
67
+ // Clear any hanging handles
68
+ await new Promise ( resolve => setTimeout ( resolve , 0 ) )
69
+ // Force garbage collection if available
70
+ if ( global . gc ) global . gc ( )
71
+ } , 30000 )
72
+
60
73
beforeEach ( async ( ) => {
74
+ // Reset timers before each test
75
+ jest . useRealTimers ( )
61
76
await removeAllTemplateDistFolders ( )
62
77
} , 30000 )
63
78
@@ -75,75 +90,77 @@ describe('extension build', () => {
75
90
76
91
const postCssConfig = path . join ( templatePath , 'postcss.config.js' )
77
92
78
- // Dynamically mock the postcss.config.js file if it exists.
79
- // Since the file is dynamically imported in the webpack config,
80
- // we need to mock it before the webpack config is created.
81
- if ( fs . existsSync ( postCssConfig ) ) {
82
- jest . mock ( postCssConfig , ( ) => jest . fn ( ) )
83
- }
84
-
85
- await extensionBuild ( templatePath , {
86
- browser : SUPPORTED_BROWSERS [ 0 ] as 'chrome'
87
- } )
88
-
89
- expect (
90
- path . join (
91
- templatePath ,
92
- 'dist' ,
93
- SUPPORTED_BROWSERS [ 0 ] ,
94
- 'manifest.json'
95
- )
96
- ) . toBeTruthy ( )
97
-
98
- const manifestText = fs . readFileSync (
99
- path . join (
100
- templatePath ,
101
- 'dist' ,
102
- SUPPORTED_BROWSERS [ 0 ] ,
103
- 'manifest.json'
104
- ) ,
105
- 'utf-8'
106
- )
93
+ try {
94
+ // Dynamically mock the postcss.config.js file if it exists
95
+ if ( fs . existsSync ( postCssConfig ) ) {
96
+ jest . mock ( postCssConfig , ( ) => jest . fn ( ) )
97
+ }
107
98
108
- const manifest : Manifest = JSON . parse ( manifestText )
109
- expect ( manifest . name ) . toBeTruthy
110
- expect ( manifest . version ) . toBeTruthy
111
- expect ( manifest . manifest_version ) . toBeTruthy
99
+ await extensionBuild ( templatePath , {
100
+ browser : SUPPORTED_BROWSERS [ 0 ] as 'chrome'
101
+ } )
112
102
113
- if ( template . name . includes ( 'content' ) ) {
114
- // Since extension@2.0.0-beta-6, the content script is injected
115
- // into the shadow DOM. Including in production mode.
116
- // expect(manifest.content_scripts![0].css![0]).toEqual(
117
- // 'content_scripts/content-0.css'
118
- // )
103
+ expect (
104
+ path . join (
105
+ templatePath ,
106
+ 'dist' ,
107
+ SUPPORTED_BROWSERS [ 0 ] ,
108
+ 'manifest.json'
109
+ )
110
+ ) . toBeTruthy ( )
119
111
120
- expect ( manifest . content_scripts ! [ 0 ] . js ! [ 0 ] ) . toEqual (
121
- 'content_scripts/content-0.js'
112
+ const manifestText = fs . readFileSync (
113
+ path . join (
114
+ templatePath ,
115
+ 'dist' ,
116
+ SUPPORTED_BROWSERS [ 0 ] ,
117
+ 'manifest.json'
118
+ ) ,
119
+ 'utf-8'
122
120
)
123
121
124
- // Since extension@2.0.0-beta-6, the content script is injected
125
- // into the shadow DOM. Including in production mode.
126
- // expect(
127
- // distFileExists(
128
- // template.name,
129
- // SUPPORTED_BROWSERS[0],
130
- // 'content_scripts/content-0.css'
131
- // )
132
- // ).toBeTruthy()
122
+ const manifest : Manifest = JSON . parse ( manifestText )
123
+ expect ( manifest . name ) . toBeTruthy ( )
124
+ expect ( manifest . version ) . toBeTruthy ( )
125
+ expect ( manifest . manifest_version ) . toBeTruthy ( )
133
126
134
- expect (
135
- distFileExists (
136
- template . name ,
137
- SUPPORTED_BROWSERS [ 0 ] ,
127
+ if ( template . name . includes ( 'content' ) ) {
128
+ expect ( manifest . content_scripts ! [ 0 ] . js ! [ 0 ] ) . toEqual (
138
129
'content_scripts/content-0.js'
139
130
)
140
- ) . toBeTruthy ( )
131
+ expect (
132
+ distFileExists (
133
+ template . name ,
134
+ SUPPORTED_BROWSERS [ 0 ] ,
135
+ 'content_scripts/content-0.css'
136
+ )
137
+ ) . toBeTruthy ( )
138
+
139
+ expect (
140
+ distFileExists (
141
+ template . name ,
142
+ SUPPORTED_BROWSERS [ 0 ] ,
143
+ 'content_scripts/content-0.js'
144
+ )
145
+ ) . toBeTruthy ( )
146
+
147
+ }
148
+ } finally {
149
+ // Clean up mocks after each test
150
+ if ( fs . existsSync ( postCssConfig ) ) {
151
+ jest . unmock ( postCssConfig )
152
+ }
141
153
}
142
154
} ,
143
155
80000
144
156
)
145
157
} )
146
158
159
+ afterEach ( async ( ) => {
160
+ jest . clearAllTimers ( )
161
+ await new Promise ( resolve => setImmediate ( resolve ) )
162
+ } )
163
+
147
164
describe ( 'using the --browser flag' , ( ) => {
148
165
it . each ( ALL_TEMPLATES ) (
149
166
`builds the "$name" extension template across all supported browsers` ,
@@ -157,16 +174,21 @@ describe('extension build', () => {
157
174
)
158
175
159
176
// Running browsers in parallel by invoking them sequentially
160
- await Promise . all (
161
- SUPPORTED_BROWSERS . filter ( ( browser ) => browser !== 'chrome' ) . map (
162
- async ( browser ) => {
163
- await extensionBuild ( templatePath , { browser : browser as any } )
164
- expect (
165
- path . join ( templatePath , SUPPORTED_BROWSERS [ 0 ] , 'manifest.json' )
166
- ) . toBeTruthy ( )
167
- }
177
+ try {
178
+ await Promise . all (
179
+ SUPPORTED_BROWSERS . filter ( ( browser ) => browser !== 'chrome' ) . map (
180
+ async ( browser ) => {
181
+ await extensionBuild ( templatePath , { browser : browser as any } )
182
+ expect (
183
+ path . join ( templatePath , SUPPORTED_BROWSERS [ 0 ] , 'manifest.json' )
184
+ ) . toBeTruthy ( )
185
+ }
186
+ )
168
187
)
169
- )
188
+ } finally {
189
+ // Ensure promises are settled
190
+ await new Promise ( resolve => setImmediate ( resolve ) )
191
+ }
170
192
} ,
171
193
80000
172
194
)
0 commit comments