import * as fs from 'fs'; import * as path from 'path'; import * as tmp from 'tmp'; import { renderToHTML } from './renderToHTML'; /** * Used to evaluate fixtures in the same module context. */ const REQUIRE_CALL = (moduleName: string): string => `require(require.resolve('${moduleName}', { paths: ${JSON.stringify(module.paths)} }))`; describe('renderToHTML', () => { it('successfully renders a component with styles into HTML file', async () => { const template = ` const { makeStyles } = ${REQUIRE_CALL('@griffel/react')}; const React = ${REQUIRE_CALL('react')}; const useClasses = makeStyles({ root: { color: 'red' }, }); function App() { const classes = useClasses(); return React.createElement('div', { className: classes.root }, 'Hello world!'); } exports.App = App; `; const filesDir = tmp.dirSync({ unsafeCleanup: true }).name; const cjsOutfile = path.resolve(filesDir, 'cjs.js'); const esmOutfile = path.resolve(filesDir, 'esm.js'); const htmlOutfile = path.resolve(filesDir, 'index.html'); await fs.promises.writeFile(cjsOutfile, template); await renderToHTML({ cjsOutfile, esmOutfile, htmlOutfile }); const htmlContent = await fs.promises.readFile(htmlOutfile, { encoding: 'utf8' }); //