Skip to content

Commit

Permalink
Merge pull request #1338 from capricorn86/1336-use-getter-and-setter-…
Browse files Browse the repository at this point in the history
…for-windowlocation

chore: [#1336] Changes console to be a value again according to spec
  • Loading branch information
capricorn86 committed Mar 20, 2024
2 parents ea6a01c + f0fadb1 commit 7e006f5
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 16 deletions.
1 change: 0 additions & 1 deletion packages/happy-dom/src/PropertySymbol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ export const nodeStream = Symbol('nodeStream');
export const location = Symbol('location');
export const history = Symbol('history');
export const navigator = Symbol('navigator');
export const console = Symbol('console');
export const screen = Symbol('screen');
export const sessionStorage = Symbol('sessionStorage');
export const localStorage = Symbol('localStorage');
12 changes: 3 additions & 9 deletions packages/happy-dom/src/window/BrowserWindow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,7 @@ export default class BrowserWindow extends EventTarget implements INodeJSGlobal
public readonly screenY: number = 0;
public readonly crypto: typeof webcrypto = webcrypto;
public readonly closed = false;
public console: Console;
public name = '';

// Node.js Globals
Expand Down Expand Up @@ -493,7 +494,6 @@ export default class BrowserWindow extends EventTarget implements INodeJSGlobal
public [PropertySymbol.location]: Location;
public [PropertySymbol.history]: History;
public [PropertySymbol.navigator]: Navigator;
public [PropertySymbol.console]: Console;
public [PropertySymbol.screen]: Screen;
public [PropertySymbol.sessionStorage]: Storage;
public [PropertySymbol.localStorage]: Storage;
Expand Down Expand Up @@ -525,7 +525,8 @@ export default class BrowserWindow extends EventTarget implements INodeJSGlobal
this[PropertySymbol.sessionStorage] = new Storage();
this[PropertySymbol.localStorage] = new Storage();
this[PropertySymbol.location] = new Location(this.#browserFrame, options?.url ?? 'about:blank');
this[PropertySymbol.console] = browserFrame.page.console;

this.console = browserFrame.page.console;

WindowBrowserSettingsReader.setSettings(this, this.#browserFrame.page.context.browser.settings);

Expand Down Expand Up @@ -703,13 +704,6 @@ export default class BrowserWindow extends EventTarget implements INodeJSGlobal
return this[PropertySymbol.navigator];
}

/**
* Returns console.
*/
public get console(): Console {
return this[PropertySymbol.console];
}

/**
* Returns screen.
*/
Expand Down
1 change: 1 addition & 0 deletions packages/happy-dom/test/window/BrowserWindow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import CSSStyleSheet from '../../src/css/CSSStyleSheet.js';
import Location from '../../src/location/Location.js';

import '../types.d.js';
import VirtualConsole from '../../src/console/VirtualConsole.js';

const PLATFORM =
'X11; ' +
Expand Down
7 changes: 1 addition & 6 deletions packages/jest-environment/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export default class HappyDOMEnvironment implements JestEnvironment {
this.window = new Window({
url: 'http://localhost/',
...projectConfig.testEnvironmentOptions,
console: options.console,
console: options.console || console,
settings: {
...(<IOptionalBrowserSettings>projectConfig.testEnvironmentOptions?.settings),
errorCapture: BrowserErrorCaptureEnum.disabled
Expand All @@ -74,11 +74,6 @@ export default class HappyDOMEnvironment implements JestEnvironment {
// For some reason Jest removes the global setImmediate, so we need to add it back.
this.global.setImmediate = global.setImmediate;

if (options && options.console) {
this.global.console = options.console;
this.global.window['console'] = options.console;
}

this.fakeTimers = new LegacyFakeTimers({
config: projectConfig,
global: <typeof globalThis>(<unknown>this.window),
Expand Down

0 comments on commit 7e006f5

Please sign in to comment.