@@ -1255,12 +1255,10 @@ test(`should generate export {} when there are no exports in source file`, async
12551255} )
12561256
12571257test ( 'custom inject style function' , async ( ) => {
1258- const { outFiles, getFileContent } = await run (
1259- getTestName ( ) ,
1260- {
1261- 'input.ts' : `import './style.css'` ,
1262- 'style.css' : `.hello { color: red }` ,
1263- 'tsup.config.ts' : `
1258+ const { outFiles, getFileContent } = await run ( getTestName ( ) , {
1259+ 'input.ts' : `import './style.css'` ,
1260+ 'style.css' : `.hello { color: red }` ,
1261+ 'tsup.config.ts' : `
12641262 export default {
12651263 entry: ['src/input.ts'],
12661264 minify: true,
@@ -1269,13 +1267,30 @@ test('custom inject style function', async () => {
12691267 return "__custom_inject_style__(" + css +")";
12701268 }
12711269 }` ,
1272- } ,
1273- )
1270+ } )
12741271 expect ( outFiles ) . toEqual ( [ 'input.js' , 'input.mjs' ] )
1275- expect ( await getFileContent ( 'dist/input.mjs' ) ) . toContain ( '__custom_inject_style__(`.hello{color:red}\n`)' )
1276- expect ( await getFileContent ( 'dist/input.js' ) ) . toContain ( '__custom_inject_style__(`.hello{color:red}\n`)' )
1272+ expect ( await getFileContent ( 'dist/input.mjs' ) ) . toContain (
1273+ '__custom_inject_style__(`.hello{color:red}\n`)'
1274+ )
1275+ expect ( await getFileContent ( 'dist/input.js' ) ) . toContain (
1276+ '__custom_inject_style__(`.hello{color:red}\n`)'
1277+ )
12771278} )
12781279
1280+ test ( 'preserve top-level variable for IIFE format' , async ( ) => {
1281+ const { outFiles, getFileContent } = await run ( getTestName ( ) , {
1282+ 'input.ts' : `export default 'foo'` ,
1283+ 'tsup.config.ts' : `
1284+ export default {
1285+ entry: ['src/input.ts'],
1286+ globalName: 'globalFoo',
1287+ minify: 'terser',
1288+ format: ['iife']
1289+ }` ,
1290+ } )
1291+ expect ( outFiles ) . toEqual ( [ 'input.global.js' ] )
1292+ expect ( await getFileContent ( 'dist/input.global.js' ) ) . toMatch ( / g l o b a l F o o \s * = / )
1293+ } )
12791294
12801295test ( 'should load postcss esm config' , async ( ) => {
12811296 const { outFiles, getFileContent } = await run ( getTestName ( ) , {
@@ -1301,4 +1316,4 @@ test('should load postcss esm config', async () => {
13011316
13021317 expect ( outFiles ) . toEqual ( [ 'input.cjs' , 'input.css' ] )
13031318 expect ( await getFileContent ( 'dist/input.css' ) ) . toContain ( 'color: blue;' )
1304- } )
1319+ } )
0 commit comments