var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
import { basename, join } from 'path';
import * as tempy from 'tempy';
import { createIndexHtml } from './createIndexHtml';
import { generateTestBundle } from './generateTestBundle';
import { bundleFileOrExit } from './webpack';
export function setupBrowser(cwd, port, timeout, logger, testMetadata, extendConfiguration) {
    return __awaiter(this, void 0, void 0, function* () {
        const outputDirectory = tempy.directory();
        const temporaryPath = join(outputDirectory, basename(tempy.file({ extension: 'ts' })));
        const bundlePath = join(outputDirectory, basename(tempy.file({ extension: 'js' })));
        const browserApiFile = generateTestBundle(cwd, outputDirectory, port, timeout, testMetadata);
        const indexHtmlPath = join(outputDirectory, 'index.html');
        const { writeFileSync } = require('fs');
        writeFileSync(temporaryPath, browserApiFile);
        yield bundleFileOrExit(cwd, temporaryPath, bundlePath, logger, extendConfiguration);
        writeFileSync(indexHtmlPath, createIndexHtml(basename(bundlePath)));
        return { outputDirectory, bundlePath, indexHtmlPath };
    });
}
//# sourceMappingURL=setupBrowser.js.map