Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More β†’
Socket
Sign inDemoInstall
Socket

next-page-tester

Package Overview
Dependencies
Maintainers
1
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

next-page-tester - npm Package Compare versions

Comparing version 0.28.0 to 0.29.0

dist/getPageObject/parseMatchingRoute/index.d.ts

2

dist/_app/DefaultApp.js

@@ -9,4 +9,4 @@ "use strict";

const DefaultApp = function DefaultApp({ Component, pageProps }) {
return react_1.default.createElement(Component, Object.assign({}, pageProps));
return react_1.default.createElement(Component, { ...pageProps });
};
exports.default = DefaultApp;

@@ -14,3 +14,3 @@ "use strict";

if (getInitialProps) {
const { asPath, pathname, query, route, basePath } = router_1.makeRouterMock({
const { asPath, pathname, query, route, basePath } = (0, router_1.makeRouterMock)({
options,

@@ -23,3 +23,3 @@ pageObject,

Component: pageObject.files.client.pageFile.default,
ctx: makeContextObject_1.makeGetInitialPropsContext({ pageObject, options }),
ctx: (0, makeContextObject_1.makeGetInitialPropsContext)({ pageObject, options }),
// @ts-expect-error incomplete router object

@@ -29,3 +29,3 @@ router: { asPath, pathname, query, route, basePath },

const appInitialProps = env === constants_1.RuntimeEnvironment.SERVER
? await server_1.executeAsIfOnServer(() => getInitialProps(ctx))
? await (0, server_1.executeAsIfOnServer)(() => getInitialProps(ctx))
: await getInitialProps(ctx);

@@ -32,0 +32,0 @@ return appInitialProps;

@@ -14,3 +14,3 @@ "use strict";

if (useApp) {
const customAppFile = page_1.getPageFileIfExists({
const customAppFile = (0, page_1.getPageFileIfExists)({
pagePath: constants_1.APP_PATH,

@@ -27,5 +27,5 @@ options,

function getDefaultAppFile() {
return loadFile_1.loadFile({
return (0, loadFile_1.loadFile)({
absolutePath: path_1.default.resolve(__dirname, 'DefaultApp'),
});
}

@@ -20,2 +20,5 @@ "use strict";

exports.default = renderApp;
/*
* Render App and Page component inside optional wrapper provided as options.wrapper
*/
function renderEnhancedApp({ App, Page, appProps, pageProps, options: { wrapper = {} }, }) {

@@ -30,4 +33,4 @@ let UserEnhancedPage = Page;

}
return (react_1.default.createElement(UserEnhancedApp, Object.assign({ Component: UserEnhancedPage, pageProps: pageProps }, appProps)));
return (react_1.default.createElement(UserEnhancedApp, { Component: UserEnhancedPage, pageProps: pageProps, ...appProps }));
}
exports.renderEnhancedApp = renderEnhancedApp;

@@ -13,3 +13,3 @@ "use strict";

const getDocumentInitialProps = Document.getInitialProps || document_1.default.getInitialProps;
return server_1.executeAsIfOnServer(() => getDocumentInitialProps({
return (0, server_1.executeAsIfOnServer)(() => getDocumentInitialProps({
renderPage,

@@ -16,0 +16,0 @@ pathname: pageObject.pagePath,

@@ -8,3 +8,3 @@ "use strict";

function getDocumentFile({ options, }) {
const customDocumentFile = page_1.getPageFileIfExists({
const customDocumentFile = (0, page_1.getPageFileIfExists)({
options,

@@ -20,5 +20,5 @@ pagePath: constants_1.DOCUMENT_PATH,

function getDefaultDocumentFile() {
return loadFile_1.loadFile({
return (0, loadFile_1.loadFile)({
absolutePath: 'next/document',
});
}

@@ -32,7 +32,7 @@ "use strict";

async function serverRenderDocument({ options, appProps, pageProps, pageObject, wrapWithRouter, }) {
return server_2.executeAsIfOnServer(async () => {
return (0, server_2.executeAsIfOnServer)(async () => {
const { useDocument } = options;
const { documentFile: { default: DocumentComponent }, appFile: { default: AppComponent }, pageFile: { default: PageComponent }, } = pageObject.files.server;
const render = (App, Page) => {
return _app_1.renderEnhancedApp({ App, Page, options, appProps, pageProps });
return (0, _app_1.renderEnhancedApp)({ App, Page, options, appProps, pageProps });
};

@@ -49,3 +49,3 @@ // Return an empty dummy document if useDocument is not enabled

let head = [];
const html = server_1.renderToString(
const html = (0, server_1.renderToString)(
// @NOTE: implemented from:

@@ -62,3 +62,3 @@ // https://github.com/vercel/next.js/blob/v10.0.3/packages/next/next-server/server/render.tsx#L561

};
const initialProps = await fetchDocumentData_1.default({
const initialProps = await (0, fetchDocumentData_1.default)({
Document: DocumentComponent,

@@ -99,2 +99,3 @@ renderPage,

};
// @ts-expect-error this method doesn't exist since Next.js v11.1.2 and useDocument option is currently disabled
return DocumentComponent.renderDocument(DocumentComponent, documentProps);

@@ -101,0 +102,0 @@ });

@@ -8,3 +8,3 @@ "use strict";

function getErrorPagePath({ options, }) {
const customErrorFile = page_1.getPagePathIfExists({
const customErrorFile = (0, page_1.getPagePathIfExists)({
pagePath: constants_1.ERROR_PATH,

@@ -11,0 +11,0 @@ options,

@@ -7,4 +7,4 @@ "use strict";

async function get404PageInfo({ options, }) {
const pageObject = makeNotFoundPageObject_1.makeNotFoundPageObject({ options });
const pageData = await fetchData_1.fetchPageData({ pageObject, options });
const pageObject = (0, makeNotFoundPageObject_1.makeNotFoundPageObject)({ options });
const pageData = await (0, fetchData_1.fetchPageData)({ pageObject, options });
pageData.props = {

@@ -11,0 +11,0 @@ ...pageData.props,

@@ -8,3 +8,3 @@ "use strict";

function get404PagePath({ options, }) {
const custom404file = page_1.getPagePathIfExists({
const custom404file = (0, page_1.getPagePathIfExists)({
pagePath: constants_1.FOUR_O_FOUR_PATH,

@@ -17,4 +17,4 @@ options,

// Fallback to "/pages/_error" if no "/pages/404" is present
return _error_1.getErrorPagePath({ options });
return (0, _error_1.getErrorPagePath)({ options });
}
exports.get404PagePath = get404PagePath;

@@ -12,8 +12,8 @@ "use strict";

const { route } = options;
const { pathname } = utils_1.parseRoute({ route }).urlObject;
const notFoundPageRouteInfo = getPageObject_1.makeRouteInfo({
const { pathname } = (0, utils_1.parseRoute)({ route }).urlObject;
const notFoundPageRouteInfo = (0, getPageObject_1.makeRouteInfo)({
route,
pagePath: pathname,
});
const absolutePagePath = index_1.get404PagePath({ options });
const absolutePagePath = (0, index_1.get404PagePath)({ options });
return {

@@ -23,5 +23,5 @@ ...notFoundPageRouteInfo,

absolutePagePath,
files: getNextFiles_1.loadErrorPageFiles({ absolutePagePath, options }),
files: (0, getNextFiles_1.loadErrorPageFiles)({ absolutePagePath, options }),
};
}
exports.makeNotFoundPageObject = makeNotFoundPageObject;

@@ -75,3 +75,3 @@ "use strict";

!appInitialProps) {
const ctx = makeContextObject_1.makeGetInitialPropsContext({
const ctx = (0, makeContextObject_1.makeGetInitialPropsContext)({
options,

@@ -85,3 +85,3 @@ pageObject,

else {
const initialProps = await server_1.executeAsIfOnServer(() => getInitialProps(ctx));
const initialProps = await (0, server_1.executeAsIfOnServer)(() => getInitialProps(ctx));
return { props: initialProps };

@@ -96,4 +96,4 @@ }

const { getServerSideProps } = serverPageFile;
const ctx = makeContextObject_1.makeGetServerSidePropsContext({ options, pageObject });
const pageData = await server_1.executeAsIfOnServer(() => getServerSideProps(ctx));
const ctx = (0, makeContextObject_1.makeGetServerSidePropsContext)({ options, pageObject });
const pageData = await (0, server_1.executeAsIfOnServer)(() => getServerSideProps(ctx));
ensurePageDataHasProps({ pageData });

@@ -104,3 +104,3 @@ return mergePageDataWithAppData({ pageData, appInitialProps });

const { getStaticProps } = serverPageFile;
const ctx = makeContextObject_1.makeStaticPropsContext({
const ctx = (0, makeContextObject_1.makeStaticPropsContext)({
pageObject,

@@ -110,3 +110,3 @@ });

// https://nextjs.org/docs/basic-features/data-fetching#getstaticpaths-static-generation
const pageData = await server_1.executeAsIfOnServer(() => getStaticProps(ctx));
const pageData = await (0, server_1.executeAsIfOnServer)(() => getStaticProps(ctx));
ensurePageDataHasProps({ pageData });

@@ -113,0 +113,0 @@ return mergePageDataWithAppData({ pageData, appInitialProps });

@@ -9,7 +9,7 @@ "use strict";

async function fetchRouteData({ pageObject, options, }) {
const appInitialProps = await _app_1.fetchAppData({
const appInitialProps = await (0, _app_1.fetchAppData)({
pageObject,
options,
});
const pageData = await fetchPageData_1.default({
const pageData = await (0, fetchPageData_1.default)({
pageObject,

@@ -16,0 +16,0 @@ options,

@@ -21,3 +21,3 @@ "use strict";

if (env === 'server') {
const { req, res } = makeHttpObjects_1.default({
const { req, res } = (0, makeHttpObjects_1.default)({
pageObject,

@@ -37,3 +37,3 @@ reqMocker,

const { params, query, resolvedUrl } = pageObject;
const { req, res } = makeHttpObjects_1.default({
const { req, res } = (0, makeHttpObjects_1.default)({
pageObject,

@@ -44,7 +44,7 @@ reqMocker,

});
const { locale, locales, defaultLocale } = utils_1.getLocales({ pageObject });
const { locale, locales, defaultLocale } = (0, utils_1.getLocales)({ pageObject });
// parsed "cookies" are only available in "getServerSideProps" data fetching method
// https://github.com/vercel/next.js/pull/19724/files#diff-f1cccfe490138be7dae0d63562f6a2834af92d21130e0ff10d6de7ad30613f6bR132
if (req.headers.cookie) {
req.cookies = cookie_1.parse(req.headers.cookie);
req.cookies = (0, cookie_1.parse)(req.headers.cookie);
}

@@ -67,3 +67,3 @@ // @TODO complete ctx object

const { params } = pageObject;
const { locale, locales, defaultLocale } = utils_1.getLocales({ pageObject });
const { locale, locales, defaultLocale } = (0, utils_1.getLocales)({ pageObject });
// @TODO complete ctx object

@@ -70,0 +70,0 @@ // https://nextjs.org/docs/basic-features/data-fetching#getstaticprops-static-generation

@@ -12,5 +12,5 @@ "use strict";

return {
documentFile: _document_1.getDocumentFile({ options }),
appFile: _app_1.getAppFile({ options }),
pageFile: loadFile_1.loadFile({
documentFile: (0, _document_1.getDocumentFile)({ options }),
appFile: (0, _app_1.getAppFile)({ options }),
pageFile: (0, loadFile_1.loadFile)({
absolutePath: absolutePagePath,

@@ -23,3 +23,3 @@ }),

client: loadPageFiles({ absolutePagePath, options }),
server: server_1.executeAsIfOnServerSync(() => utils_1.executeWithFreshModules(() => loadPageFiles({ absolutePagePath, options }), options)),
server: (0, server_1.executeAsIfOnServerSync)(() => (0, utils_1.executeWithFreshModules)(() => loadPageFiles({ absolutePagePath, options }), options)),
};

@@ -31,5 +31,5 @@ }

client: loadPageFiles({ absolutePagePath, options }),
server: server_1.executeAsIfOnServerSync(() => utils_1.executeWithFreshModules(() => loadPageFiles({ absolutePagePath, options }), options)),
server: (0, server_1.executeAsIfOnServerSync)(() => (0, utils_1.executeWithFreshModules)(() => loadPageFiles({ absolutePagePath, options }), options)),
};
}
exports.loadErrorPageFiles = loadErrorPageFiles;

@@ -22,9 +22,12 @@ "use strict";

const constants_1 = require("./constants");
function validateOptions({ nextRoot, route }) {
function validateOptions({ nextRoot, route, useDocument, }) {
if (!route.startsWith('/')) {
throw new _error_1.InternalError('"route" option should start with "/"');
}
if (!fs_1.existsSync(nextRoot)) {
if (!(0, fs_1.existsSync)(nextRoot)) {
throw new _error_1.InternalError('Cannot find "nextRoot" directory under: ${nextRoot}');
}
if (useDocument) {
throw new _error_1.InternalError('useDocument option was temporarily disabled since v0.29.0 due to issue #263');
}
}

@@ -45,17 +48,17 @@ async function getPage({ route, nextRoot = utils_1.defaultNextRoot, req = (req) => req, res = (res) => res, router = (router) => router, useApp = true, useDocument = false, dotenvFile, wrapper, sharedModules = [], }) {

validateOptions(optionsWithDefaults);
setEnvVars_1.loadBaseEnvironment({ nextRoot, dotenvFile });
await nextConfig_1.loadNextConfig({ nextRoot });
setNextRuntimeConfig_1.default({ runtimeEnv: constants_1.RuntimeEnvironment.CLIENT });
utils_1.setNextImageConfiguration();
setEnvVars_1.setEnvVars({ runtimeEnv: constants_1.RuntimeEnvironment.CLIENT });
(0, setEnvVars_1.loadBaseEnvironment)({ nextRoot, dotenvFile });
await (0, nextConfig_1.loadNextConfig)({ nextRoot });
(0, setNextRuntimeConfig_1.default)({ runtimeEnv: constants_1.RuntimeEnvironment.CLIENT });
(0, utils_1.setNextImageConfiguration)();
(0, setEnvVars_1.setEnvVars)({ runtimeEnv: constants_1.RuntimeEnvironment.CLIENT });
const options = {
...optionsWithDefaults,
pagesDirectory: utils_1.findPagesDirectory({ nextRoot }),
pageExtensions: utils_1.getPageExtensions(),
pagesDirectory: (0, utils_1.findPagesDirectory)({ nextRoot }),
pageExtensions: (0, utils_1.getPageExtensions)(),
env: constants_1.RuntimeEnvironment.SERVER,
};
// @TODO: Consider printing extended options value behind a debug flag
const headManager = useDocument && head_manager_1.default();
const headManager = useDocument && (0, head_manager_1.default)();
const makePage = async (options) => {
let { pageElement, pageObject } = await page_1.makePageElement({ options });
let { pageElement, pageObject } = await (0, page_1.makePageElement)({ options });
if (useDocument &&

@@ -68,7 +71,7 @@ options.env === constants_1.RuntimeEnvironment.CLIENT &&

};
const { pageData, pageObject } = await page_1.getPageInfo({ options });
const { pageData, pageObject } = await (0, page_1.getPageInfo)({ options });
const wrapWithRouter = (children) => {
return (react_1.default.createElement(router_1.RouterProvider, { options: options, pageObject: pageObject, makePage: (optionsOverrides) => makePage({ ...options, ...optionsOverrides }) }, children));
};
const serverPageElement = await _document_1.serverRenderDocument({
const serverPageElement = await (0, _document_1.serverRenderDocument)({
options,

@@ -80,3 +83,3 @@ pageObject,

});
const clientPageElement = wrapWithRouter(_app_1.renderApp({
const clientPageElement = wrapWithRouter((0, _app_1.renderApp)({
options: { ...options, env: constants_1.RuntimeEnvironment.CLIENT },

@@ -89,5 +92,5 @@ pageObject,

page: clientPageElement,
...makeRenderMethods_1.makeRenderMethods({ serverPageElement, clientPageElement }),
...(0, makeRenderMethods_1.makeRenderMethods)({ serverPageElement, clientPageElement }),
};
}
exports.default = getPage;

@@ -13,7 +13,7 @@ "use strict";

async function getPageObject({ options, }) {
const routeInfo = await getRouteInfo_1.default({ options });
const routeInfo = await (0, getRouteInfo_1.default)({ options });
if (routeInfo) {
const { pagePath } = routeInfo;
const absolutePagePath = page_1.getPagePath({ pagePath, options });
const files = getNextFiles_1.loadExistingPageFiles({
const absolutePagePath = (0, page_1.getPagePath)({ pagePath, options });
const files = (0, getNextFiles_1.loadExistingPageFiles)({
absolutePagePath,

@@ -33,4 +33,4 @@ options,

// Make a NotFoundPageObject for 404 page
return _404_1.makeNotFoundPageObject({ options });
return (0, _404_1.makeNotFoundPageObject)({ options });
}
exports.getPageObject = getPageObject;
import type { ExtendedOptions } from '../commonTypes';
/**
* Returns available page paths without file extension sorted by matching priority
*/
declare function getPagePaths({ options: { pagesDirectory, pageExtensions }, }: {

@@ -3,0 +6,0 @@ options: ExtendedOptions;

@@ -10,9 +10,11 @@ "use strict";

const sorted_routes_1 = require("next/dist/shared/lib/router/utils/sorted-routes");
// Returns available page paths without file extension
/**
* Returns available page paths without file extension sorted by matching priority
*/
async function getPagePaths({ options: { pagesDirectory, pageExtensions }, }) {
const files = await utils_1.glob(path_1.default.join(pagesDirectory, '**', '*'));
const files = await (0, utils_1.glob)(path_1.default.join(pagesDirectory, '**', '*'));
const extensionsRegex = new RegExp(`.(${pageExtensions.join('|')})$`);
return sorted_routes_1.getSortedRoutes(files
return (0, sorted_routes_1.getSortedRoutes)(files
// Make page paths relative
.map((filePath) => filePath.replace(normalize_path_1.default(pagesDirectory), ''))
.map((filePath) => filePath.replace((0, normalize_path_1.default)(pagesDirectory), ''))
// Filter out files with non-allowed extensions

@@ -19,0 +21,0 @@ .filter((filePath) => filePath.match(extensionsRegex))

@@ -6,22 +6,16 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
const getPagePaths_1 = __importDefault(require("./getPagePaths"));
const makeRouteInfo_1 = require("./makeRouteInfo");
const pagePathParser_1 = require("./pagePathParser");
const utils_1 = require("../utils");
const parseMatchingRoute_1 = __importDefault(require("./parseMatchingRoute"));
async function getRouteInfo({ options, }) {
const { route } = options;
const { pathname } = utils_1.parseRoute({ route }).urlObject;
const pagePaths = await getPagePaths_1.default({ options });
for (const pagePath of pagePaths) {
const pagePathRegex = pagePathParser_1.pagePathToRouteRegex(pagePath);
const result = pathname.match(pagePathRegex);
if (result) {
return makeRouteInfo_1.makeRouteInfo({
route,
pagePath,
routeRegexCaptureGroups: result.groups,
});
}
const parsedMatchingRoute = await (0, parseMatchingRoute_1.default)({ options });
if (parsedMatchingRoute) {
const { pagePath, params } = parsedMatchingRoute;
return (0, makeRouteInfo_1.makeRouteInfo)({
route,
pagePath,
params,
});
}
}
exports.default = getRouteInfo;

@@ -1,6 +0,6 @@

import type { RouteInfo } from '../commonTypes';
export declare function makeRouteInfo({ route, pagePath, routeRegexCaptureGroups, }: {
import type { PageParams, RouteInfo } from '../commonTypes';
export declare function makeRouteInfo({ route, pagePath, params, }: {
route: string;
pagePath: string;
routeRegexCaptureGroups?: Record<string, string>;
params?: PageParams;
}): RouteInfo;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.makeRouteInfo = void 0;
const pagePathParser_1 = require("./pagePathParser");
const utils_1 = require("../utils");
function makeRouteInfo({ route, pagePath, routeRegexCaptureGroups, }) {
const { urlObject, detectedLocale } = utils_1.parseRoute({ route });
function makeRouteInfo({ route, pagePath, params = {}, }) {
const { urlObject, detectedLocale } = (0, utils_1.parseRoute)({ route });
const { pathname, search } = urlObject;
const params = makeParamsObject({
pagePath,
routeRegexCaptureGroups,
});
const query = utils_1.parseQueryString({ queryString: search });
const query = (0, utils_1.parseQueryString)({ queryString: search });
return {

@@ -20,3 +15,3 @@ route,

resolvedUrl: pathname +
utils_1.stringifyQueryString({
(0, utils_1.stringifyQueryString)({
object: { ...params, ...query },

@@ -30,22 +25,1 @@ leadingQuestionMark: true,

exports.makeRouteInfo = makeRouteInfo;
function makeParamsObject({ pagePath, routeRegexCaptureGroups, }) {
const params = {};
const pagePathParams = pagePathParser_1.extractPagePathParamsType({
pagePath,
});
if (routeRegexCaptureGroups) {
for (const [key, value] of Object.entries(routeRegexCaptureGroups)) {
if (value !== undefined) {
const paramType = pagePathParams[key];
if (paramType === pagePathParser_1.ROUTE_PARAMS_TYPES.CATCH_ALL ||
paramType === pagePathParser_1.ROUTE_PARAMS_TYPES.OPTIONAL_CATCH_ALL) {
params[key] = value.split('/');
}
else {
params[key] = value;
}
}
}
}
return params;
}

@@ -21,3 +21,3 @@ "use strict";

if (!process.env.NPT_SKIP_AUTO_SETUP) {
pure_1.initTestHelpers();
(0, pure_1.initTestHelpers)();
}

@@ -16,3 +16,3 @@ "use strict";

return {
html: server_2.executeAsIfOnServerSync(() => server_1.default.renderToString(serverPageElement)),
html: (0, server_2.executeAsIfOnServerSync)(() => server_1.default.renderToString(serverPageElement)),
};

@@ -24,3 +24,3 @@ }

const originalBody = document.body;
const newDocument = utils_1.parseHTML(html);
const newDocument = (0, utils_1.parseHTML)(html);
document.replaceChild(newDocument.documentElement, document.documentElement);

@@ -27,0 +27,0 @@ // Replace new body element with original one

@@ -36,3 +36,3 @@ "use strict";

process.env.__NEXT_PROCESSED_ENV = 'true';
nextConfig = await config_1.default(constants_1.PHASE_DEVELOPMENT_SERVER, nextRoot);
nextConfig = await (0, config_1.default)(constants_1.PHASE_DEVELOPMENT_SERVER, nextRoot);
}

@@ -39,0 +39,0 @@ exports.loadNextConfig = loadNextConfig;

@@ -18,3 +18,3 @@ "use strict";

const pathWithExtension = absolutePath + `.${pageExtension}`;
if (fs_1.existsSync(pathWithExtension)) {
if ((0, fs_1.existsSync)(pathWithExtension)) {
return pathWithExtension;

@@ -41,10 +41,16 @@ }

try {
return loadFile_1.loadFile({ absolutePath });
return (0, loadFile_1.loadFile)({ absolutePath });
}
catch (e) {
const internalError = new _error_1.InternalError(`Failed to load "${pagePath}" file due to ${e.name}: ${e.message}`);
internalError.stack = e.stack;
throw internalError;
/* istanbul ignore else */
if (e instanceof Error) {
const internalError = new _error_1.InternalError(`Failed to load "${pagePath}" file due to ${e.name}: ${e.message}`);
internalError.stack = e.stack;
throw internalError;
}
else {
throw new _error_1.InternalError(`Failed to load "${pagePath}"`);
}
}
}
exports.getPageFileIfExists = getPageFileIfExists;

@@ -13,10 +13,10 @@ "use strict";

async function getPageInfo({ options, }) {
const pageObject = await getPageObject_1.getPageObject({ options });
const pageObject = await (0, getPageObject_1.getPageObject)({ options });
if (pageObject.type === 'notFound') {
if (utils_1.isExternalRoute(pageObject.route)) {
if ((0, utils_1.isExternalRoute)(pageObject.route)) {
throw new _error_1.InternalError(`External route: ${pageObject.route}`);
}
return _404_1.get404PageInfo({ options });
return (0, _404_1.get404PageInfo)({ options });
}
const pageData = await fetchData_1.fetchRouteData({ options, pageObject });
const pageData = await (0, fetchData_1.fetchRouteData)({ options, pageObject });
if (pageData.redirect) {

@@ -31,3 +31,3 @@ return getPageInfo({

if (pageData.notFound) {
return _404_1.get404PageInfo({ options });
return (0, _404_1.get404PageInfo)({ options });
}

@@ -34,0 +34,0 @@ return { pageObject, pageData };

@@ -7,4 +7,4 @@ "use strict";

async function makePageElement({ options, }) {
const { pageData, pageObject } = await getPageInfo_1.getPageInfo({ options });
const pageElement = _app_1.renderApp({
const { pageData, pageObject } = await (0, getPageInfo_1.getPageInfo)({ options });
const pageElement = (0, _app_1.renderApp)({
options,

@@ -11,0 +11,0 @@ pageObject,

@@ -39,9 +39,9 @@ "use strict";

const { pathname, search, hash } = urlObject;
const { locales, defaultLocale, locale } = utils_1.getLocales({ pageObject });
const { locales, defaultLocale, locale } = (0, utils_1.getLocales)({ pageObject });
const router = {
...makeDefaultRouterMock({ pushHandler }),
asPath: pathname + search + hash,
pathname: utils_1.removeFileExtension({ path: pagePath }),
pathname: (0, utils_1.removeFileExtension)({ path: pagePath }),
query: { ...params, ...query },
route: utils_1.removeFileExtension({ path: pagePath }),
route: (0, utils_1.removeFileExtension)({ path: pagePath }),
basePath: '',

@@ -48,0 +48,0 @@ locales,

@@ -32,6 +32,6 @@ "use strict";

function RouterProvider({ pageObject, options, children: initialChildren, makePage, }) {
const isMounted = utils_1.useMountedState();
const previousRouteRef = react_1.useRef(pageObject.route);
const pushHandler = react_1.useCallback(async (url, _$, transitionOptions) => {
let nextRoute = typeof url === 'string' ? url : format_url_1.formatUrl(url);
const isMounted = (0, utils_1.useMountedState)();
const previousRouteRef = (0, react_1.useRef)(pageObject.route);
const pushHandler = (0, react_1.useCallback)(async (url, _$, transitionOptions) => {
let nextRoute = typeof url === 'string' ? url : (0, format_url_1.formatUrl)(url);
if ((transitionOptions === null || transitionOptions === void 0 ? void 0 : transitionOptions.locale) && nextRoute.startsWith('/')) {

@@ -48,3 +48,3 @@ nextRoute = `/${transitionOptions.locale}${nextRoute}`;

previousRouteRef.current = nextRoute;
const nextRouter = makeRouterMock_1.default({
const nextRouter = (0, makeRouterMock_1.default)({
options: nextOptions,

@@ -62,5 +62,5 @@ pageObject,

}, []);
const [{ children, router }, setState] = react_1.useState(() => ({
const [{ children, router }, setState] = (0, react_1.useState)(() => ({
children: initialChildren,
router: makeRouterMock_1.default({
router: (0, makeRouterMock_1.default)({
options,

@@ -67,0 +67,0 @@ pageObject,

@@ -20,4 +20,4 @@ "use strict";

delete global.navigator;
setNextRuntimeConfig_1.default({ runtimeEnv: constants_1.RuntimeEnvironment.SERVER });
setEnvVars_1.setEnvVars({ runtimeEnv: constants_1.RuntimeEnvironment.SERVER });
(0, setNextRuntimeConfig_1.default)({ runtimeEnv: constants_1.RuntimeEnvironment.SERVER });
(0, setEnvVars_1.setEnvVars)({ runtimeEnv: constants_1.RuntimeEnvironment.SERVER });
return () => {

@@ -27,4 +27,4 @@ global.window = tmpWindow;

global.navigator = tmpNavigator;
setNextRuntimeConfig_1.default({ runtimeEnv: constants_1.RuntimeEnvironment.CLIENT });
setEnvVars_1.setEnvVars({ runtimeEnv: constants_1.RuntimeEnvironment.CLIENT });
(0, setNextRuntimeConfig_1.default)({ runtimeEnv: constants_1.RuntimeEnvironment.CLIENT });
(0, setEnvVars_1.setEnvVars)({ runtimeEnv: constants_1.RuntimeEnvironment.CLIENT });
};

@@ -31,0 +31,0 @@ }

@@ -38,5 +38,5 @@ "use strict";

const dotenvFilePath = path_1.default.resolve(nextRoot, dotenvFileRelativePath);
if (fs_1.existsSync(dotenvFilePath)) {
const dotenvResult = dotenv_expand_1.default({
parsed: dotenv_1.default.parse(fs_1.readFileSync(dotenvFilePath)),
if ((0, fs_1.existsSync)(dotenvFilePath)) {
const dotenvResult = (0, dotenv_expand_1.default)({
parsed: dotenv_1.default.parse((0, fs_1.readFileSync)(dotenvFilePath)),
// @ts-expect-error dotenv-expand type definition is out of date

@@ -59,3 +59,3 @@ ignoreProcessEnv: true,

function setEnvVars({ runtimeEnv, }) {
const { env: envVarsFromConfig } = nextConfig_1.getNextConfig();
const { env: envVarsFromConfig } = (0, nextConfig_1.getNextConfig)();
// Runtime and dotfile env vars are scoped by environment (via NEXT_PUBLIC_ prefix),

@@ -62,0 +62,0 @@ // while env vars coming from next.config.js are available in both environments

@@ -7,5 +7,5 @@ "use strict";

function setNextRuntimeConfig({ runtimeEnv, }) {
const config = nextConfig_1.getNextConfig();
const config = (0, nextConfig_1.getNextConfig)();
const { serverRuntimeConfig, publicRuntimeConfig } = config;
runtime_config_1.setConfig({
(0, runtime_config_1.setConfig)({
serverRuntimeConfig: runtimeEnv === constants_1.RuntimeEnvironment.SERVER ? serverRuntimeConfig : {},

@@ -12,0 +12,0 @@ publicRuntimeConfig,

@@ -34,3 +34,3 @@ "use strict";

if (typeof jest !== 'undefined') {
utils_1.preservePredefinedSharedModulesIdentity();
(0, utils_1.preservePredefinedSharedModulesIdentity)();
}

@@ -40,5 +40,5 @@ }

function cleanup() {
makeRenderMethods_1.cleanupDOM();
setEnvVars_1.cleanupEnvVars();
(0, makeRenderMethods_1.cleanupDOM)();
(0, setEnvVars_1.cleanupEnvVars)();
}
exports.cleanup = cleanup;

@@ -21,7 +21,7 @@ "use strict";

function parseRoute({ route, }) {
const { i18n } = nextConfig_1.getNextConfig();
const { i18n } = (0, nextConfig_1.getNextConfig)();
const locales = i18n === null || i18n === void 0 ? void 0 : i18n.locales;
const urlObject = new url_1.URL(`http://test.com${route}`);
const { pathname: localePath } = urlObject;
const { pathname, detectedLocale } = normalize_locale_path_1.normalizeLocalePath(localePath, locales);
const { pathname, detectedLocale } = (0, normalize_locale_path_1.normalizeLocalePath)(localePath, locales);
urlObject.pathname = pathname;

@@ -58,3 +58,3 @@ /*

exports.removeFileExtension = removeFileExtension;
exports.defaultNextRoot = find_root_1.default(process.cwd());
exports.defaultNextRoot = (0, find_root_1.default)(process.cwd());
function findPagesDirectory({ nextRoot }) {

@@ -66,3 +66,3 @@ const pagesPaths = [

for (const path of pagesPaths) {
if (fs_1.existsSync(path)) {
if ((0, fs_1.existsSync)(path)) {
return path;

@@ -75,3 +75,3 @@ }

function getPageExtensions() {
const config = nextConfig_1.getNextConfig();
const config = (0, nextConfig_1.getNextConfig)();
return config.pageExtensions;

@@ -81,5 +81,5 @@ }

function useMountedState() {
const mountedRef = react_1.useRef(false);
const get = react_1.useCallback(() => mountedRef.current, []);
react_1.useEffect(() => {
const mountedRef = (0, react_1.useRef)(false);
const get = (0, react_1.useCallback)(() => mountedRef.current, []);
(0, react_1.useEffect)(() => {
mountedRef.current = true;

@@ -127,3 +127,3 @@ return () => {

else {
return stealthy_require_1.default(require.cache, f, () => {
return (0, stealthy_require_1.default)(require.cache, f, () => {
for (const moduleName of [

@@ -153,3 +153,3 @@ ...predefinedSharedModules,

function getLocales({ pageObject: { detectedLocale }, }) {
const { i18n } = nextConfig_1.getNextConfig();
const { i18n } = (0, nextConfig_1.getNextConfig)();
return {

@@ -167,4 +167,4 @@ locales: i18n === null || i18n === void 0 ? void 0 : i18n.locales,

async function glob(pattern) {
const paths = await tiny_glob_1.default(normalize_path_1.default(pattern), { absolute: true });
return paths.map((path) => normalize_path_1.default(path));
const paths = await (0, tiny_glob_1.default)((0, normalize_path_1.default)(pattern), { absolute: true });
return paths.map((path) => (0, normalize_path_1.default)(path));
}

@@ -177,3 +177,3 @@ exports.glob = glob;

function setNextImageConfiguration() {
const config = nextConfig_1.getNextConfig();
const config = (0, nextConfig_1.getNextConfig)();
// @NOTE config.images is optional according to types but a default is always provided

@@ -180,0 +180,0 @@ const imageConfig = config.images

{
"name": "next-page-tester",
"description": "Enable DOM integration testing on Next.js pages",
"version": "0.28.0",
"version": "0.29.0",
"main": "dist/index.js",

@@ -15,2 +15,3 @@ "types": "dist/index.d.ts",

"test": "jest ./src",
"test:skip-use-document": "jest ./src",
"test:source": "npm run test:format && npm run test:ts && npm t -- --coverage",

@@ -52,5 +53,5 @@ "test:dist": "jest ./src --config ./jest/dist.config.js",

"@emotion/server": "^11.0.0",
"@testing-library/jest-dom": "^5.11.6",
"@testing-library/react": "^11.2.2",
"@testing-library/user-event": "^12.5.0",
"@testing-library/jest-dom": "^5.14.1",
"@testing-library/react": "^12.1.0",
"@testing-library/user-event": "^13.2.1",
"@types/cookie": "^0.4.1",

@@ -62,18 +63,18 @@ "@types/find-root": "^1.1.2",

"@types/normalize-path": "^3.0.0",
"@types/react": "^17.0.8",
"@types/react-dom": "^17.0.5",
"@types/styletron-engine-atomic": "^1.1.0",
"@types/styletron-react": "^5.0.2",
"@typescript-eslint/eslint-plugin": "^4.13.0",
"@typescript-eslint/parser": "^4.13.0",
"aws-amplify": "^3.4.3",
"@types/react": "^17.0.19",
"@types/react-dom": "^17.0.9",
"@types/styletron-engine-atomic": "^1.1.1",
"@types/styletron-react": "^5.0.3",
"@typescript-eslint/eslint-plugin": "^4.31.1",
"@typescript-eslint/parser": "^4.31.1",
"aws-amplify": "^4.2.5",
"babel-jest": "^27.0.2",
"cross-fetch": "^3.1.4",
"eslint": "^7.17.0",
"eslint-config-prettier": "^7.1.0",
"eslint-plugin-jest": "^24.1.3",
"eslint-plugin-prettier": "^3.3.1",
"eslint-plugin-react": "^7.22.0",
"eslint": "^7.32.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-jest": "^24.4.2",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-react": "^7.25.2",
"eslint-plugin-react-hooks": "^4.2.0",
"eslint-plugin-testing-library": "^3.10.1",
"eslint-plugin-testing-library": "^4.12.2",
"graphql": "^15.5.1",

@@ -85,3 +86,3 @@ "husky": "^4.3.8",

"lodash": "^4.17.21",
"next": "^11.1.0",
"next": "^11.1.2",
"next-page-tester-on-npm": "npm:next-page-tester@^0.25.0",

@@ -93,8 +94,8 @@ "prettier": "^2.2.1",

"styletron-engine-atomic": "^1.4.8",
"styletron-react": "^5.2.7",
"styletron-react": "^6.0.0",
"ts-jest": "^27.0.3",
"typescript": "^4.1.3"
"typescript": "^4.4.2"
},
"dependencies": {
"@types/express": "^4.17.12",
"@types/express": "^4.17.13",
"cookie": "^0.4.1",

@@ -121,3 +122,4 @@ "dotenv": "^8.2.0",

"testPathIgnorePatterns": [
"__fixtures__"
"__fixtures__",
"useDocument.test"
],

@@ -124,0 +126,0 @@ "coveragePathIgnorePatterns": [

@@ -108,14 +108,14 @@ # Next page tester

| Property | Description | type | Default |
| ------------------------------ | ---------------------------------------------------------------------------------- | ----------------------------------------------------------- | --------------- |
| **route** (mandatory) | Next route (must start with `/`) | `string` | - |
| **req** | Enhance default mocked [request object][req-docs] | `req => req` | - |
| **res** | Enhance default mocked [response object][res-docs] | `res => res` | - |
| **router** | Enhance default mocked [Next router object][next-docs-router] | `router => router` | - |
| **useApp** | Render [custom App component][next-docs-custom-app] | `boolean` | `true` |
| **useDocument** (experimental) | Render [Document component][next-docs-custom-document] | `boolean` | `false` |
| **nextRoot** | Absolute path to Next.js root folder | `string` | _auto detected_ |
| **dotenvFile** | Relative path to a `.env` file holding [environment variables][next-docs-env-vars] | `string` | - |
| **wrapper** | Map of render functions. Useful to decorate component tree with mocked providers. | `{ Page?: NextPage => NextPage; App?: NextApp => NextApp }` | - |
| **sharedModules** | List of modules that should preserve identity between client and server context. | `string[]` | [] |
| Property | Description | type | Default |
| ---------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------- | ----------------------------------------------------------- | --------------- |
| **route** (mandatory) | Next route (must start with `/`) | `string` | - |
| **req** | Enhance default mocked [request object][req-docs] | `req => req` | - |
| **res** | Enhance default mocked [response object][res-docs] | `res => res` | - |
| **router** | Enhance default mocked [Next router object][next-docs-router] | `router => router` | - |
| **useApp** | Render [custom App component][next-docs-custom-app] | `boolean` | `true` |
| ~**useDocument**~ (experimental. Temporarily disabled due to [this issue](https://github.com/toomuchdesign/next-page-tester/issues/263)) | Render [Document component][next-docs-custom-document] | `boolean` | `false` |
| **nextRoot** | Absolute path to Next.js root folder | `string` | _auto detected_ |
| **dotenvFile** | Relative path to a `.env` file holding [environment variables][next-docs-env-vars] | `string` | - |
| **wrapper** | Map of render functions. Useful to decorate component tree with mocked providers. | `{ Page?: NextPage => NextPage; App?: NextApp => NextApp }` | - |
| **sharedModules** | List of modules that should preserve identity between client and server context. | `string[]` | [] |

@@ -168,3 +168,4 @@ ## Setting up your dev environment

| v0.26.0 -> v0.27.X | v10.0.8 -> v11.0.X | v27.X.X |
| v0.28.0 + | v11.1.0 + | |
| v0.28.0 -> v0.28.X | v11.1.0 | |
| v0.29.0 + | v11.1.1 + | |

@@ -286,2 +287,3 @@ Since:

<td align="center"><a href="https://medium.com/@DoctorDerek"><img src="https://avatars.githubusercontent.com/u/761231?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Dr. Derek Austin</b></sub></a><br /><a href="https://github.com/toomuchdesign/next-page-tester/issues?q=author%3ADoctorDerek" title="Bug reports">πŸ›</a> <a href="https://github.com/toomuchdesign/next-page-tester/commits?author=DoctorDerek" title="Code">πŸ’»</a></td>
<td align="center"><a href="https://github.com/feargalWag"><img src="https://avatars.githubusercontent.com/u/61435828?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Feargal </b></sub></a><br /><a href="https://github.com/toomuchdesign/next-page-tester/issues?q=author%3AfeargalWag" title="Bug reports">πŸ›</a></td>
</tr>

@@ -288,0 +290,0 @@ </table>

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚑️ by Socket Inc