@@ -10,26 +10,33 @@ import { describe, expect, it } from 'vitest'
1010import defaultIntegrationExport , { shield } from '../main.mts'
1111
1212describe ( 'sriCSP' , ( ) => {
13- it ( 'is exported as default' , ( ) => {
14- expect ( defaultIntegrationExport ) . toBe ( shield )
15- expect ( shield ) . toBeInstanceOf ( Function )
16- } )
13+ const defaultIntegrationKeys = [
14+ 'astro:build:done' ,
15+ 'astro:config:setup' ,
16+ ] as Readonly < [ 'astro:build:done' , 'astro:config:setup' ] >
1717
1818 const checkIntegration = (
1919 integration : AstroIntegration ,
20- keys : ( keyof AstroIntegration [ 'hooks' ] ) [ ] = [ 'astro:config:setup' ] as const ,
20+ keys : Readonly <
21+ ( keyof AstroIntegration [ 'hooks' ] ) [ ]
22+ > = defaultIntegrationKeys ,
2123 ) => {
2224 expect ( Object . keys ( integration ) . sort ( ) ) . toEqual ( [ 'hooks' , 'name' ] )
2325 expect ( integration . name ) . toBe ( '@kindspells/astro-shield' )
2426
25- const sortedKeys = keys . sort ( )
27+ const sortedKeys = keys . slice ( ) . sort ( ) // TODO: use toSorted when widely available
2628 expect ( Object . keys ( integration . hooks ) . sort ( ) ) . toEqual ( sortedKeys )
2729 for ( const key of sortedKeys ) {
2830 expect ( integration . hooks [ key ] ) . toBeTruthy ( )
2931 expect ( integration . hooks [ key ] ) . toBeInstanceOf ( Function )
3032 }
3133 }
3234
35+ it ( 'is exported as default' , ( ) => {
36+ expect ( defaultIntegrationExport ) . toBe ( shield )
37+ expect ( shield ) . toBeInstanceOf ( Function )
38+ } )
39+
3340 it ( 'returns a valid AstroIntegration object for default config' , ( ) => {
3441 const integration = shield ( { } )
3542 checkIntegration ( integration )
@@ -44,12 +51,12 @@ describe('sriCSP', () => {
4451 const integration = shield ( { sri : { enableStatic : false } } )
4552
4653 // NOTE: it is too much work to verify that those hooks will do nothing
47- checkIntegration ( integration , [ 'astro:config:setup' ] )
54+ checkIntegration ( integration , defaultIntegrationKeys )
4855 } )
4956
5057 it ( 'returns hooks for static & dynamic content when we enable middleware' , ( ) => {
5158 const integration = shield ( { sri : { enableMiddleware : true } } )
52- checkIntegration ( integration , [ 'astro:config:setup' ] )
59+ checkIntegration ( integration , defaultIntegrationKeys )
5360 } )
5461
5562 it ( 'returns hooks only for dynamic content when we enable middleware and disable static sri' , ( ) => {
@@ -59,6 +66,20 @@ describe('sriCSP', () => {
5966 enableMiddleware : true ,
6067 } ,
6168 } )
69+ checkIntegration ( integration , defaultIntegrationKeys )
70+ } )
71+
72+ it ( 'removes build:done from base config when delayTransform=true' , ( ) => {
73+ const integration = shield ( {
74+ delayTransform : true ,
75+ } )
6276 checkIntegration ( integration , [ 'astro:config:setup' ] )
6377 } )
78+
79+ it ( 'keeps build:done in base config when delayTransform=false' , ( ) => {
80+ const integration = shield ( {
81+ delayTransform : false ,
82+ } )
83+ checkIntegration ( integration , [ 'astro:build:done' , 'astro:config:setup' ] )
84+ } )
6485} )
0 commit comments