@@ -464,4 +464,62 @@ describe('Init command', () => {
464464 ` )
465465 )
466466 } )
467+
468+ test ( '--help in ESM package' , async ( ) => {
469+ let pkg = await readOutputFile ( '../package.json' )
470+
471+ await writeInputFile ( '../package.json' , JSON . stringify ( {
472+ ...JSON . parse ( pkg ) ,
473+ type : 'module' ,
474+ } ) )
475+
476+ let { combined } = await $ ( `${ EXECUTABLE } init --help` )
477+
478+ expect ( dedent ( combined ) ) . toEqual (
479+ dedent ( `
480+ tailwindcss v${ version }
481+
482+ Usage:
483+ tailwindcss init [options]
484+
485+ Options:
486+ -f, --full Initialize a full \`tailwind.config.cjs\` file
487+ -p, --postcss Initialize a \`postcss.config.cjs\` file
488+ --types Add TypeScript types for the \`tailwind.config.cjs\` file
489+ -h, --help Display usage information
490+ ` )
491+ )
492+
493+ await writeInputFile ( '../package.json' , pkg )
494+ } )
495+
496+ test ( 'cjs config created when in ESM package' , async ( ) => {
497+ cleanupFile ( 'tailwind.config.cjs' )
498+
499+ let pkg = await readOutputFile ( '../package.json' )
500+
501+ await writeInputFile ( '../package.json' , JSON . stringify ( {
502+ ...JSON . parse ( pkg ) ,
503+ type : 'module' ,
504+ } ) )
505+
506+ let { combined } = await $ ( `${ EXECUTABLE } init` )
507+
508+ expect ( combined ) . toMatchInlineSnapshot ( `
509+ "
510+ Created Tailwind CSS config file: tailwind.config.cjs
511+ "
512+ ` )
513+
514+ expect ( await fileExists ( './tailwind.config.cjs' ) ) . toBe ( true )
515+
516+ // Not a clean way to test this.
517+ expect ( await readOutputFile ( '../tailwind.config.cjs' ) ) . toContain ( 'module.exports =' )
518+
519+ expect ( await readOutputFile ( '../tailwind.config.cjs' ) ) . not . toContain (
520+ `/** @type {import('tailwindcss/types').Config} */`
521+ )
522+
523+ await writeInputFile ( '../package.json' , pkg )
524+ } )
467525} )
0 commit comments