Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BREAKING CHANGE: [#1330] Removes interfaces for Node's, as they are n… #1331

Merged
merged 5 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/happy-dom/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@
"access": "public"
},
"scripts": {
"compile": "tsc && rm -rf ./cjs && tsc --moduleResolution Node --module CommonJS --outDir cjs && npm run change-cjs-file-extension && npm run build-version-file",
"compile": "npm run compile:esm && npm run compile:cjs npm run build-version-file",
"compile:esm": "tsc",
"compile:cjs": "rm -rf ./cjs && tsc --moduleResolution Node --module CommonJS --outDir cjs && npm run change-cjs-file-extension",
"change-cjs-file-extension": "node ./bin/change-file-extension.cjs --dir=./cjs --fromExt=.js --toExt=.cjs",
"build-version-file": "node ./bin/build-version-file.cjs",
"watch": "tsc -w --preserveWatchOutput",
Expand Down
4 changes: 2 additions & 2 deletions packages/happy-dom/src/browser/BrowserContext.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import CookieContainer from '../cookie/CookieContainer.js';
import ICookieContainer from '../cookie/types/ICookieContainer.js';
import ResponseCache from '../fetch/cache/response/ResponseCache.js';
import ICookieContainer from '../cookie/ICookieContainer.js';
import IResponseCache from '../fetch/cache/response/IResponseCache.js';
import ResponseCache from '../fetch/cache/response/ResponseCache.js';
import Browser from './Browser.js';
import BrowserPage from './BrowserPage.js';
import IBrowserContext from './types/IBrowserContext.js';
Expand Down
15 changes: 7 additions & 8 deletions packages/happy-dom/src/browser/BrowserFrame.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ import * as PropertySymbol from '../PropertySymbol.js';
import AsyncTaskManager from '../async-task-manager/AsyncTaskManager.js';
import IBrowserFrame from './types/IBrowserFrame.js';
import BrowserWindow from '../window/BrowserWindow.js';
import IBrowserWindow from '../window/IBrowserWindow.js';
import ICrossOriginBrowserWindow from '../window/ICrossOriginBrowserWindow.js';
import IResponse from '../fetch/types/IResponse.js';
import CrossOriginBrowserWindow from '../window/CrossOriginBrowserWindow.js';
import Response from '../fetch/Response.js';
import IGoToOptions from './types/IGoToOptions.js';
import { Script } from 'vm';
import BrowserFrameURL from './utilities/BrowserFrameURL.js';
Expand All @@ -14,7 +13,7 @@ import BrowserFrameNavigator from './utilities/BrowserFrameNavigator.js';
import IReloadOptions from './types/IReloadOptions.js';
import BrowserFrameExceptionObserver from './utilities/BrowserFrameExceptionObserver.js';
import BrowserErrorCaptureEnum from './enums/BrowserErrorCaptureEnum.js';
import IDocument from '../nodes/document/IDocument.js';
import Document from '../nodes/document/Document.js';

/**
* Browser frame.
Expand All @@ -28,7 +27,7 @@ export default class BrowserFrame implements IBrowserFrame {
public [PropertySymbol.exceptionObserver]: BrowserFrameExceptionObserver | null = null;
public [PropertySymbol.listeners]: { navigation: Array<() => void> } = { navigation: [] };
public [PropertySymbol.openerFrame]: IBrowserFrame | null = null;
public [PropertySymbol.openerWindow]: IBrowserWindow | ICrossOriginBrowserWindow | null = null;
public [PropertySymbol.openerWindow]: BrowserWindow | CrossOriginBrowserWindow | null = null;
public [PropertySymbol.popup] = false;

/**
Expand Down Expand Up @@ -94,7 +93,7 @@ export default class BrowserFrame implements IBrowserFrame {
*
* @returns Document.
*/
public get document(): IDocument {
public get document(): Document {
return this.window?.document ?? null;
}

Expand Down Expand Up @@ -151,7 +150,7 @@ export default class BrowserFrame implements IBrowserFrame {
* @param [options] Options.
* @returns Response.
*/
public goto(url: string, options?: IGoToOptions): Promise<IResponse | null> {
public goto(url: string, options?: IGoToOptions): Promise<Response | null> {
return BrowserFrameNavigator.navigate({
windowClass: BrowserWindow,
frame: this,
Expand All @@ -166,7 +165,7 @@ export default class BrowserFrame implements IBrowserFrame {
* @param [options] Options.
* @returns Response.
*/
public reload(options: IReloadOptions): Promise<IResponse | null> {
public reload(options: IReloadOptions): Promise<Response | null> {
return BrowserFrameNavigator.navigate({
windowClass: BrowserWindow,
frame: this,
Expand Down
6 changes: 3 additions & 3 deletions packages/happy-dom/src/browser/BrowserPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import IBrowserPage from './types/IBrowserPage.js';
import BrowserPageUtility from './utilities/BrowserPageUtility.js';
import { Script } from 'vm';
import IGoToOptions from './types/IGoToOptions.js';
import IResponse from '../fetch/types/IResponse.js';
import Response from '../fetch/Response.js';
import IReloadOptions from './types/IReloadOptions.js';
import IBrowserPageViewport from './types/IBrowserPageViewport.js';
import IOptionalBrowserPageViewport from './types/IOptionalBrowserPageViewport.js';
Expand Down Expand Up @@ -137,7 +137,7 @@ export default class BrowserPage implements IBrowserPage {
* @param [options] Options.
* @returns Response.
*/
public goto(url: string, options?: IGoToOptions): Promise<IResponse | null> {
public goto(url: string, options?: IGoToOptions): Promise<Response | null> {
return this.mainFrame.goto(url, options);
}

Expand All @@ -147,7 +147,7 @@ export default class BrowserPage implements IBrowserPage {
* @param [options] Options.
* @returns Response.
*/
public reload(options: IReloadOptions): Promise<IResponse | null> {
public reload(options: IReloadOptions): Promise<Response | null> {
return this.mainFrame.reload(options);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import BrowserSettingsFactory from '../BrowserSettingsFactory.js';
import DetachedBrowserPage from './DetachedBrowserPage.js';
import IBrowser from '../types/IBrowser.js';
import IBrowserFrame from '../types/IBrowserFrame.js';
import IBrowserWindow from '../../window/IBrowserWindow.js';
import BrowserWindow from '../../window/BrowserWindow.js';

/**
* Detached browser used when constructing a Window instance without a browser.
Expand All @@ -19,7 +19,7 @@ export default class DetachedBrowser implements IBrowser {
public readonly windowClass: new (
browserFrame: IBrowserFrame,
options?: { url?: string; width?: number; height?: number }
) => IBrowserWindow | null;
) => BrowserWindow | null;

/**
* Constructor.
Expand All @@ -33,7 +33,7 @@ export default class DetachedBrowser implements IBrowser {
windowClass: new (
browserFrame: IBrowserFrame,
options?: { url?: string; width?: number; height?: number }
) => IBrowserWindow,
) => BrowserWindow,
options?: { settings?: IOptionalBrowserSettings; console?: Console }
) {
this.windowClass = windowClass;
Expand Down Expand Up @@ -62,7 +62,7 @@ export default class DetachedBrowser implements IBrowser {
await Promise.all(this.contexts.slice().map((context) => context.close()));
(<DetachedBrowserContext[]>this.contexts) = [];
(<Console | null>this.console) = null;
(<new (browserFrame: IBrowserFrame) => IBrowserWindow | null>this.windowClass) = null;
(<new (browserFrame: IBrowserFrame) => BrowserWindow | null>this.windowClass) = null;
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import DetachedBrowser from './DetachedBrowser.js';
import DetachedBrowserPage from './DetachedBrowserPage.js';
import IBrowserContext from '../types/IBrowserContext.js';
import ICookieContainer from '../../cookie/types/ICookieContainer.js';
import ICookieContainer from '../../cookie/ICookieContainer.js';
import CookieContainer from '../../cookie/CookieContainer.js';
import ResponseCache from '../../fetch/cache/response/ResponseCache.js';
import IResponseCache from '../../fetch/cache/response/IResponseCache.js';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ import DetachedBrowserPage from './DetachedBrowserPage.js';
import * as PropertySymbol from '../../PropertySymbol.js';
import AsyncTaskManager from '../../async-task-manager/AsyncTaskManager.js';
import IBrowserFrame from '../types/IBrowserFrame.js';
import IResponse from '../../fetch/types/IResponse.js';
import Response from '../../fetch/Response.js';
import IGoToOptions from '../types/IGoToOptions.js';
import { Script } from 'vm';
import BrowserFrameURL from '../utilities/BrowserFrameURL.js';
import BrowserFrameScriptEvaluator from '../utilities/BrowserFrameScriptEvaluator.js';
import BrowserFrameNavigator from '../utilities/BrowserFrameNavigator.js';
import IBrowserWindow from '../../window/IBrowserWindow.js';
import BrowserWindow from '../../window/BrowserWindow.js';
import IReloadOptions from '../types/IReloadOptions.js';
import BrowserErrorCaptureEnum from '../enums/BrowserErrorCaptureEnum.js';
import BrowserFrameExceptionObserver from '../utilities/BrowserFrameExceptionObserver.js';
import IDocument from '../../nodes/document/IDocument.js';
import ICrossOriginBrowserWindow from '../../window/ICrossOriginBrowserWindow.js';
import Document from '../../nodes/document/Document.js';
import CrossOriginBrowserWindow from '../../window/CrossOriginBrowserWindow.js';

/**
* Browser frame used when constructing a Window instance without a browser.
Expand All @@ -23,12 +23,12 @@ export default class DetachedBrowserFrame implements IBrowserFrame {
public readonly parentFrame: DetachedBrowserFrame | null = null;
public readonly page: DetachedBrowserPage;
// Needs to be injected from the outside when the browser frame is constructed.
public window: IBrowserWindow;
public window: BrowserWindow;
public [PropertySymbol.asyncTaskManager] = new AsyncTaskManager();
public [PropertySymbol.exceptionObserver]: BrowserFrameExceptionObserver | null = null;
public [PropertySymbol.listeners]: { navigation: Array<() => void> } = { navigation: [] };
public [PropertySymbol.openerFrame]: IBrowserFrame | null = null;
public [PropertySymbol.openerWindow]: IBrowserWindow | ICrossOriginBrowserWindow | null = null;
public [PropertySymbol.openerWindow]: BrowserWindow | CrossOriginBrowserWindow | null = null;
public [PropertySymbol.popup] = false;

/**
Expand Down Expand Up @@ -109,7 +109,7 @@ export default class DetachedBrowserFrame implements IBrowserFrame {
*
* @returns Document.
*/
public get document(): IDocument {
public get document(): Document {
return this.window?.document ?? null;
}

Expand Down Expand Up @@ -166,7 +166,7 @@ export default class DetachedBrowserFrame implements IBrowserFrame {
* @param [options] Options.
* @returns Response.
*/
public goto(url: string, options?: IGoToOptions): Promise<IResponse | null> {
public goto(url: string, options?: IGoToOptions): Promise<Response | null> {
return BrowserFrameNavigator.navigate({
windowClass: this.page.context.browser.windowClass,
frame: this,
Expand All @@ -181,7 +181,7 @@ export default class DetachedBrowserFrame implements IBrowserFrame {
* @param [options] Options.
* @returns Response.
*/
public reload(options: IReloadOptions): Promise<IResponse | null> {
public reload(options: IReloadOptions): Promise<Response | null> {
return BrowserFrameNavigator.navigate({
windowClass: this.page.context.browser.windowClass,
frame: this,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import VirtualConsole from '../../console/VirtualConsole.js';
import IBrowserPage from '../types/IBrowserPage.js';
import { Script } from 'vm';
import IGoToOptions from '../types/IGoToOptions.js';
import IResponse from '../../fetch/types/IResponse.js';
import Response from '../../fetch/Response.js';
import BrowserPageUtility from '../utilities/BrowserPageUtility.js';
import IReloadOptions from '../types/IReloadOptions.js';
import DefaultBrowserPageViewport from '../DefaultBrowserPageViewport.js';
Expand Down Expand Up @@ -150,7 +150,7 @@ export default class DetachedBrowserPage implements IBrowserPage {
* @param [options] Options.
* @returns Response.
*/
public goto(url: string, options?: IGoToOptions): Promise<IResponse | null> {
public goto(url: string, options?: IGoToOptions): Promise<Response | null> {
return this.mainFrame.goto(url, options);
}

Expand All @@ -160,7 +160,7 @@ export default class DetachedBrowserPage implements IBrowserPage {
* @param [options] Options.
* @returns Response.
*/
public reload(options: IReloadOptions): Promise<IResponse | null> {
public reload(options: IReloadOptions): Promise<Response | null> {
return this.mainFrame.reload(options);
}
}
2 changes: 1 addition & 1 deletion packages/happy-dom/src/browser/types/IBrowserContext.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import ICookieContainer from '../../cookie/types/ICookieContainer.js';
import ICookieContainer from '../../cookie/ICookieContainer.js';
import IResponseCache from '../../fetch/cache/response/IResponseCache.js';
import IBrowser from './IBrowser.js';
import IBrowserPage from './IBrowserPage.js';
Expand Down
18 changes: 9 additions & 9 deletions packages/happy-dom/src/browser/types/IBrowserFrame.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import AsyncTaskManager from '../../async-task-manager/AsyncTaskManager.js';
import * as PropertySymbol from '../../PropertySymbol.js';
import IBrowserWindow from '../../window/IBrowserWindow.js';
import IDocument from '../../nodes/document/IDocument.js';
import BrowserWindow from '../../window/BrowserWindow.js';
import Document from '../../nodes/document/Document.js';
import IBrowserPage from './IBrowserPage.js';
import IResponse from '../../fetch/types/IResponse.js';
import Response from '../../fetch/Response.js';
import IGoToOptions from './IGoToOptions.js';
import { Script } from 'vm';
import IReloadOptions from './IReloadOptions.js';
import BrowserFrameExceptionObserver from '../utilities/BrowserFrameExceptionObserver.js';
import ICrossOriginBrowserWindow from '../../window/ICrossOriginBrowserWindow.js';
import CrossOriginBrowserWindow from '../../window/CrossOriginBrowserWindow.js';

/**
* Browser frame.
Expand All @@ -17,15 +17,15 @@ export default interface IBrowserFrame {
readonly childFrames: IBrowserFrame[];
readonly parentFrame: IBrowserFrame | null;
readonly page: IBrowserPage;
readonly window: IBrowserWindow;
readonly document: IDocument;
readonly window: BrowserWindow;
readonly document: Document;
content: string;
url: string;
[PropertySymbol.asyncTaskManager]: AsyncTaskManager;
[PropertySymbol.exceptionObserver]: BrowserFrameExceptionObserver | null;
[PropertySymbol.listeners]: { navigation: Array<() => void> };
[PropertySymbol.openerFrame]: IBrowserFrame | null;
[PropertySymbol.openerWindow]: IBrowserWindow | ICrossOriginBrowserWindow | null;
[PropertySymbol.openerWindow]: BrowserWindow | CrossOriginBrowserWindow | null;
[PropertySymbol.popup]: boolean;

/**
Expand Down Expand Up @@ -57,12 +57,12 @@ export default interface IBrowserFrame {
* @param url URL.
* @param [options] Options.
*/
goto(url: string, options?: IGoToOptions): Promise<IResponse | null>;
goto(url: string, options?: IGoToOptions): Promise<Response | null>;

/**
* Reloads the current frame.
*
* @param [options] Options.
*/
reload(options: IReloadOptions): Promise<IResponse | null>;
reload(options: IReloadOptions): Promise<Response | null>;
}
6 changes: 3 additions & 3 deletions packages/happy-dom/src/browser/types/IBrowserPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import IBrowserFrame from './IBrowserFrame.js';
import IBrowserContext from './IBrowserContext.js';
import { Script } from 'vm';
import IGoToOptions from './IGoToOptions.js';
import IResponse from '../../fetch/types/IResponse.js';
import Response from '../../fetch/Response.js';
import IReloadOptions from './IReloadOptions.js';
import IOptionalBrowserPageViewport from './IOptionalBrowserPageViewport.js';

Expand Down Expand Up @@ -59,13 +59,13 @@ export default interface IBrowserPage {
* @param url URL.
* @param [options] Options.
*/
goto(url: string, options?: IGoToOptions): Promise<IResponse | null>;
goto(url: string, options?: IGoToOptions): Promise<Response | null>;

/**
* Reloads the current page.
*
* @param [options] Options.
* @returns Response.
*/
reload(options: IReloadOptions): Promise<IResponse | null>;
reload(options: IReloadOptions): Promise<Response | null>;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import IBrowserFrame from '../types/IBrowserFrame.js';
import * as PropertySymbol from '../../PropertySymbol.js';
import IBrowserWindow from '../../window/IBrowserWindow.js';
import BrowserWindow from '../../window/BrowserWindow.js';
import IBrowserPage from '../types/IBrowserPage.js';
/**
* Browser frame factory.
Expand Down Expand Up @@ -49,7 +49,7 @@ export default class BrowserFrameFactory {
if (frame.window) {
frame.window[PropertySymbol.destroy]();
(<IBrowserPage | null>frame.page) = null;
(<IBrowserWindow | null>frame.window) = null;
(<BrowserWindow | null>frame.window) = null;
frame[PropertySymbol.openerFrame] = null;
frame[PropertySymbol.openerWindow] = null;
}
Expand All @@ -67,7 +67,7 @@ export default class BrowserFrameFactory {

frame.window[PropertySymbol.destroy]();
(<IBrowserPage | null>frame.page) = null;
(<IBrowserWindow | null>frame.window) = null;
(<BrowserWindow | null>frame.window) = null;
frame[PropertySymbol.listeners] = null;
frame[PropertySymbol.openerFrame] = null;
frame[PropertySymbol.openerWindow] = null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import IBrowserFrame from '../types/IBrowserFrame.js';
import * as PropertySymbol from '../../PropertySymbol.js';
import IGoToOptions from '../types/IGoToOptions.js';
import IResponse from '../../fetch/types/IResponse.js';
import Response from '../../fetch/Response.js';
import DocumentReadyStateManager from '../../nodes/document/DocumentReadyStateManager.js';
import IBrowserWindow from '../../window/IBrowserWindow.js';
import BrowserWindow from '../../window/BrowserWindow.js';
import WindowErrorUtility from '../../window/WindowErrorUtility.js';
import AbortController from '../../fetch/AbortController.js';
import BrowserFrameFactory from './BrowserFrameFactory.js';
Expand Down Expand Up @@ -34,13 +34,13 @@ export default class BrowserFrameNavigator {
windowClass: new (
browserFrame: IBrowserFrame,
options?: { url?: string; width?: number; height?: number }
) => IBrowserWindow;
) => BrowserWindow;
frame: IBrowserFrame;
url: string;
goToOptions?: IGoToOptions;
method?: string;
formData?: FormData;
}): Promise<IResponse | null> {
}): Promise<Response | null> {
const { windowClass, frame, url, formData, method, goToOptions } = options;
const referrer = goToOptions?.referrer || frame.window.location.origin;
const targetURL = BrowserFrameURL.getRelativeURL(frame, url);
Expand Down Expand Up @@ -103,7 +103,7 @@ export default class BrowserFrameNavigator {
frame[PropertySymbol.asyncTaskManager].destroy();
frame[PropertySymbol.asyncTaskManager] = new AsyncTaskManager();

(<IBrowserWindow>frame.window) = new windowClass(frame, { url: targetURL.href, width, height });
(<BrowserWindow>frame.window) = new windowClass(frame, { url: targetURL.href, width, height });
(<number>frame.window.devicePixelRatio) = devicePixelRatio;

if (referrer) {
Expand All @@ -121,7 +121,7 @@ export default class BrowserFrameNavigator {
readyStateManager.startTask();

const abortController = new AbortController();
let response: IResponse;
let response: Response;
let responseText: string;

const timeout = frame.window.setTimeout(
Expand Down
Loading
Loading