1
1
import { join , relative } from 'node:path'
2
- import { statSync } from 'node:fs'
2
+ import { readFileSync , statSync } from 'node:fs'
3
3
import { cwd } from '../scripts/script-utils.js'
4
4
5
5
// path helpers
6
6
const ROOT = join ( cwd ( import . meta. url ) , '..' )
7
7
const BUILD = join ( ROOT , 'build' )
8
8
const APPLE_BUILD = join ( ROOT , 'Sources/ContentScopeScripts/dist' )
9
- const CSS_OUTPUT_SIZE = 512000
9
+ const CSS_OUTPUT_SIZE = 530000
10
10
const CSS_OUTPUT_SIZE_CHROME = CSS_OUTPUT_SIZE * 1.45 // 45% larger for Chrome MV2 due to base64 encoding
11
11
12
12
const checks = {
@@ -17,10 +17,12 @@ const checks = {
17
17
{ kind : 'maxFileSize' , value : CSS_OUTPUT_SIZE_CHROME , path : join ( BUILD , 'chrome/inject.js' ) }
18
18
] ,
19
19
'chrome-mv3' : [
20
- { kind : 'maxFileSize' , value : CSS_OUTPUT_SIZE , path : join ( BUILD , 'chrome-mv3/inject.js' ) }
20
+ { kind : 'maxFileSize' , value : CSS_OUTPUT_SIZE , path : join ( BUILD , 'chrome-mv3/inject.js' ) } ,
21
+ { kind : 'containsString' , text : 'cloneInto(' , path : join ( BUILD , 'chrome-mv3/inject.js' ) , includes : false }
21
22
] ,
22
23
firefox : [
23
- { kind : 'maxFileSize' , value : CSS_OUTPUT_SIZE , path : join ( BUILD , 'firefox/inject.js' ) }
24
+ { kind : 'maxFileSize' , value : CSS_OUTPUT_SIZE , path : join ( BUILD , 'firefox/inject.js' ) } ,
25
+ { kind : 'containsString' , text : 'cloneInto(' , path : join ( BUILD , 'firefox/inject.js' ) , includes : true }
24
26
] ,
25
27
integration : [
26
28
{ kind : 'maxFileSize' , value : CSS_OUTPUT_SIZE , path : join ( BUILD , 'integration/contentScope.js' ) }
@@ -36,13 +38,24 @@ const checks = {
36
38
describe ( 'checks' , ( ) => {
37
39
for ( const [ platformName , platformChecks ] of Object . entries ( checks ) ) {
38
40
for ( const check of platformChecks ) {
41
+ const localPath = relative ( ROOT , check . path )
39
42
if ( check . kind === 'maxFileSize' ) {
40
- const localPath = relative ( ROOT , check . path )
41
43
it ( `${ platformName } : '${ localPath } ' is smaller than ${ check . value } ` , ( ) => {
42
44
const stats = statSync ( check . path )
43
45
expect ( stats . size ) . toBeLessThan ( check . value )
44
46
} )
45
47
}
48
+ if ( check . kind === 'containsString' ) {
49
+ it ( `${ platformName } : '${ localPath } ' contains ${ check . text } ` , ( ) => {
50
+ const fileContents = readFileSync ( localPath ) . toString ( )
51
+ const includes = fileContents . includes ( check . text )
52
+ if ( check . includes ) {
53
+ expect ( includes ) . toBeTrue ( )
54
+ } else {
55
+ expect ( includes ) . toBeFalse ( )
56
+ }
57
+ } )
58
+ }
46
59
}
47
60
}
48
61
} )
0 commit comments