UNPKG

next-page-tester

Version:
54 lines (53 loc) 2.18 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.getNextConfig = exports.loadNextConfig = void 0; const constants_1 = require("next/constants"); const config_1 = __importDefault(require("next/dist/server/config")); const _error_1 = require("./_error"); /* * @HACK: `loadConfig` bootstraps Webpack in: * https://github.com/vercel/next.js/blob/v11.1.0/packages/next/server/config.ts#L451 * making execution times at least x4 slower. * Here we mock out "loadWebpackHook" called by `loadConfig` * * @NOTE: This is a very flaky temporary workaround */ try { // eslint-disable-next-line @typescript-eslint/no-var-requires const configUtils = require('next/dist/server/config-utils'); /* istanbul ignore next */ if (configUtils && configUtils.loadWebpackHook) { configUtils.loadWebpackHook = () => { }; } } catch (e) { /* istanbul ignore next */ console.warn(`[next-page-tester] Can't find Next.js "loadWebpackHook". This might be due to a Next.js internal change. Tests might become sensibly slower.`); } let nextConfig; async function loadNextConfig({ nextRoot, }) { // This env var lets Next.js skip default env vars loading at configuration load // We load env vars independently from Next.js // https://github.com/vercel/next.js/blob/v10.1.3/packages/next-env/index.ts#L28 process.env.__NEXT_PROCESSED_ENV = 'true'; nextConfig = await (0, config_1.default)(constants_1.PHASE_DEVELOPMENT_SERVER, nextRoot); } exports.loadNextConfig = loadNextConfig; /* * Retrieve Next.js config using Next.js internals * https://github.com/vercel/next.js/blob/v10.0.1/test/isolated/config.test.js#L12 * * Default config: * https://github.com/vercel/next.js/blob/canary/packages/next/next-server/server/config.ts */ function getNextConfig() { /* istanbul ignore if */ if (!nextConfig) { throw new _error_1.InternalError('getNextConfig called before loadNextConfig'); } return nextConfig; } exports.getNextConfig = getNextConfig;