import * as fs from 'fs';
import * as path from 'path';
import * as tmp from 'tmp';
import { generateEntryPoints } from './generateEntryPoints';
describe('generateEntryPoints', () => {
it('creates entry point files', async () => {
const filesDir = tmp.dirSync({ unsafeCleanup: true }).name;
const cjsEntryPoint = path.resolve(filesDir, 'cjs.js');
const esmEntryPoint = path.resolve(filesDir, 'esm.js');
const storiesDir = path.resolve(filesDir, 'stories', 'Module');
await fs.promises.mkdir(storiesDir, { recursive: true });
await fs.promises.writeFile(
path.resolve(storiesDir, 'FooBar.stories.tsx'),
'export const FooBar = () =>
FooBar
',
);
await fs.promises.writeFile(
path.resolve(storiesDir, 'FooBaz.stories.tsx'),
'export const FooBaz = () => FooBaz
',
);
await generateEntryPoints({
cjsEntryPoint,
esmEntryPoint,
storiesPaths: [path.resolve(storiesDir, 'FooBar.stories.tsx'), path.resolve(storiesDir, 'FooBaz.stories.tsx')],
});
const storiesFile = await fs.promises.readFile(cjsEntryPoint, { encoding: 'utf8' });
const appFile = await fs.promises.readFile(esmEntryPoint, { encoding: 'utf8' });
expect(storiesFile).toMatchInlineSnapshot(`
"import {
FluentProvider,
teamsLightTheme,
SSRProvider,
} from \\"@fluentui/react-components\\";
import * as React from \\"react\\";
import { FooBar as ModuleFooBar } from \\"stories/Module/FooBar.stories.tsx\\";
import { FooBaz as ModuleFooBaz } from \\"stories/Module/FooBaz.stories.tsx\\";
export const App = () => (
);
"
`);
expect(appFile).toMatchInlineSnapshot(`
"import { RendererProvider, createDOMRenderer } from \\"@griffel/react\\";
import * as React from \\"react\\";
import { hydrateRoot } from \\"react-dom/client\\";
import { App } from \\"./stories\\";
const renderer = createDOMRenderer();
// .hydrate() is used to trigger hydration on pre-generated markup in \\"index.html\\"
hydrateRoot(
document.querySelector(\\"#root\\"),
);
"
`);
});
});