1- import { beforeAll , describe , expect , test } from '@rstest/core' ;
1+ import { expect , test } from '@rstest/core' ;
22import { buildAndGetResults } from 'test-helper' ;
33
44enum BannerFooter {
@@ -10,67 +10,54 @@ enum BannerFooter {
1010 DTS_FOOTER = '/*! hello footer dts */' ,
1111}
1212
13- // There are 5 cases included in both tsc and tsgo
14- // 1. bundle esm
15- // 2. bundle cjs
16- // 3. bundleless esm
17- // 4. bundleless cjs
18- // 5. bundle esm with minify enabled
19- const checkBannerAndFooter = (
20- contents : Record < string , string > [ ] ,
21- type : 'js' | 'css' | 'dts' ,
22- ) => {
23- for ( const content of Object . values ( contents ) ) {
24- if ( content ) {
25- const expectedBanner =
26- type === 'js'
27- ? BannerFooter . JS_BANNER
28- : type === 'css'
29- ? BannerFooter . CSS_BANNER
30- : BannerFooter . DTS_BANNER ;
31- const expectedFooter =
32- type === 'js'
33- ? BannerFooter . JS_FOOTER
34- : type === 'css'
35- ? BannerFooter . CSS_FOOTER
36- : BannerFooter . DTS_FOOTER ;
37-
38- for ( const value of Object . values ( content ) ) {
39- expect ( value ) . toContain ( expectedBanner ) ;
40- expect ( value ) . toContain ( expectedFooter ) ;
41- }
42- }
43- }
44- } ;
45-
46- describe ( 'banner and footer should work in js, css and dts' , ( ) => {
47- let jsContents : Record < string , string > [ ] ;
48- let cssContents : Record < string , string > [ ] ;
49- let dtsContents : Record < string , string > [ ] ;
50-
51- beforeAll ( async ( ) => {
13+ test . skipIf ( process . version . startsWith ( 'v18' ) ) (
14+ 'banner and footer should work in js, css and dts' ,
15+ async ( ) => {
5216 const fixturePath = __dirname ;
5317 const { js, css, dts } = await buildAndGetResults ( {
5418 fixturePath,
5519 type : 'all' ,
5620 } ) ;
57- jsContents = Object . values ( js . contents ) ;
58- cssContents = Object . values ( css . contents ) ;
59- dtsContents = Object . values ( dts . contents ) ;
60- } ) ;
6121
62- test ( 'tsc to generate declaration files' , ( ) => {
63- checkBannerAndFooter ( jsContents . slice ( 0 , 5 ) , 'js' ) ;
64- checkBannerAndFooter ( cssContents . slice ( 0 , 5 ) , 'css' ) ;
65- checkBannerAndFooter ( dtsContents . slice ( 0 , 5 ) , 'dts' ) ;
66- } ) ;
22+ const jsContents = Object . values ( js . contents ) ;
23+ const cssContents = Object . values ( css . contents ) ;
24+ const dtsContents = Object . values ( dts . contents ) ;
25+
26+ // There are 5 cases included in both tsc and tsgo
27+ // 1. bundle esm
28+ // 2. bundle cjs
29+ // 3. bundleless esm
30+ // 4. bundleless cjs
31+ // 5. bundle esm with minify enabled
32+ const checkBannerAndFooter = (
33+ contents : Record < string , string > [ ] ,
34+ type : 'js' | 'css' | 'dts' ,
35+ ) => {
36+ for ( const content of Object . values ( contents ) ) {
37+ if ( content ) {
38+ const expectedBanner =
39+ type === 'js'
40+ ? BannerFooter . JS_BANNER
41+ : type === 'css'
42+ ? BannerFooter . CSS_BANNER
43+ : BannerFooter . DTS_BANNER ;
44+ const expectedFooter =
45+ type === 'js'
46+ ? BannerFooter . JS_FOOTER
47+ : type === 'css'
48+ ? BannerFooter . CSS_FOOTER
49+ : BannerFooter . DTS_FOOTER ;
50+
51+ for ( const value of Object . values ( content ) ) {
52+ expect ( value ) . toContain ( expectedBanner ) ;
53+ expect ( value ) . toContain ( expectedFooter ) ;
54+ }
55+ }
56+ }
57+ } ;
6758
68- test . skipIf ( process . version . startsWith ( 'v18' ) ) (
69- 'tsgo to generate declaration files' ,
70- ( ) => {
71- checkBannerAndFooter ( jsContents . slice ( - 5 ) , 'js' ) ;
72- checkBannerAndFooter ( cssContents . slice ( - 5 ) , 'css' ) ;
73- checkBannerAndFooter ( dtsContents . slice ( - 5 ) , 'dts' ) ;
74- } ,
75- ) ;
76- } ) ;
59+ checkBannerAndFooter ( jsContents , 'js' ) ;
60+ checkBannerAndFooter ( cssContents , 'css' ) ;
61+ checkBannerAndFooter ( dtsContents , 'dts' ) ;
62+ } ,
63+ ) ;
0 commit comments