Skip to content
8,201 changes: 4,100 additions & 4,101 deletions package-lock.json

Large diffs are not rendered by default.

28 changes: 10 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nascentdigital/scene",
"version": "1.5.1",
"version": "2.0.0-rc-21062024",
"description": "Still in progress.",
"license": "MIT",
"author": "Simeon de Dios <simeon@nascentdigital.com>",
Expand All @@ -19,26 +19,18 @@
"clean": "rimraf ./lib ./es5"
},
"dependencies": {
"@nascentdigital/errors": "^1.0.1",
"@nascentdigital/scribe": "^0.11.3",
"mkdirp": "^1.0.4",
"playwright": "^1.6.1"
},
"peerDependencies": {
"jest": "^26.6.3",
"jest-environment-node": "^26.6.2"
"@nascentdigital/errors": "^1.2.1",
"@nascentdigital/scribe": "^0.11.4",
"mkdirp": "^3.0.1",
"playwright": "^1.44.1"
},
"devDependencies": {
"@types/jest": "^26.0.15",
"@types/mkdirp": "^1.0.1",
"jest": "^26.6.3",
"jest-environment-node": "^26.6.2",
"@types/jest": "^29.5.12",
"jest": "^29.7.0",
"jest-environment-node": "^29.7.0",
"npm-run-all": "^4.1.5",
"rimraf": "^3.0.2",
"rimraf": "^5.0.7",
"tslint": "^6.1.3",
"typescript": "^4.0.5"
},
"engines": {
"node": ">=14"
"typescript": "^5.5.2"
}
}
12 changes: 4 additions & 8 deletions src/core/Scene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,17 +92,15 @@ export class Scene {

// initialize ref (beforeAll vs beforeEach based on ref sharing)
const initialize = shared ? beforeAll : beforeEach;
initialize(async (done) => {
initialize( async () => {
browserContextRef.current = await this.browser.newContext(options);
done();
});

// finalize ref (afterAll vs afterEach based on ref sharing)
const finalize = shared ? afterAll : afterEach;
finalize(async (done) => {
finalize(async () => {
await browserContextRef.value.close();
browserContextRef.current = undefined;
done();
});

// return context
Expand All @@ -120,17 +118,15 @@ export class Scene {

// initialize ref (beforeAll vs beforeEach based on ref sharing)
const initialize = shared ? beforeAll : beforeEach;
initialize(async (done) => {
initialize(async () => {
pageRef.current = await browserContext.newPage();
done();
});

// finalize ref (afterAll vs afterEach based on ref sharing)
const finalize = shared ? afterAll : afterEach;
finalize(async (done) => {
finalize(async () => {
await pageRef.value.close();
pageRef.current = undefined;
done();
});

// return context
Expand Down
2 changes: 1 addition & 1 deletion src/core/Selector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export class Selector<T extends string> implements ISelectable {
return this as Selector<T | K>;
}

private static createSelectable(type: SceneMarker, name: string, id?: string, css?: string, parent?: Selector<string>): ISelectable {
private static createSelectable<T extends string>(type: SceneMarker, name: string, id?: string, css?: string, parent?: Selector<T>): ISelectable {

// initialize data attributes
const dataAttributes: Record<string, string> = {
Expand Down
5 changes: 5 additions & 0 deletions src/jest/GlobalWithBrowserServer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import {BrowserServer} from "playwright";

export type GlobalWithBrowserServer = typeof global & {
browserServer: BrowserServer
}
11 changes: 7 additions & 4 deletions src/jest/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
import type { Config as JestConfig } from "@jest/types";
import fs from "fs";
import path from "path";
import mkdirp from "mkdirp";
import { mkdirp } from 'mkdirp'
import { BrowserServer } from "playwright";
import { getBrowserClass, SCENE_CONFIG, SERVER_ENDPOINT_FILE, TEMP_DIRECTORY } from "./Constants";

import {GlobalWithBrowserServer} from "./GlobalWithBrowserServer";

// declaration merging
declare global {
Expand All @@ -27,15 +27,18 @@ export async function setup(jestConfig: JestConfig.GlobalConfig) {
// launch a browser server + save reference
const browserClass = getBrowserClass();
const browserServer = await browserClass.launchServer(config.browserOptions);
global.browserServer = browserServer;

const globalWithBrowserServer = global as GlobalWithBrowserServer
globalWithBrowserServer.browserServer = browserServer;

// write server endpoint to disk
await mkdirp(TEMP_DIRECTORY);
fs.writeFileSync(SERVER_ENDPOINT_FILE, browserServer.wsEndpoint());
}

export async function teardown() {
const globalWithBrowserServer = global as GlobalWithBrowserServer

// launch a browser server + save reference
await global.browserServer.close();
await globalWithBrowserServer.browserServer.close();
}
15 changes: 8 additions & 7 deletions src/jest/env.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
// imports
import fs from "fs";
import NodeEnvironment from "jest-environment-node";
import { Script } from "vm";
import { getBrowserClass, SERVER_ENDPOINT_FILE } from "./Constants";
import "./types";
import {Browser} from "playwright";


// define class
export class SceneEnvironment extends NodeEnvironment {
private _browser?: Browser

async setup() {

Expand All @@ -22,15 +23,15 @@ export class SceneEnvironment extends NodeEnvironment {

// connect to the server, and capture the browser instance for tests
const browserClass = getBrowserClass();
this.global.browser = await browserClass.connect({ wsEndpoint: serverEndpoint });
this._browser = await browserClass.connect(serverEndpoint);
}

async teardown() {
await this.global.browser.close();
await super.teardown();
}
if (this._browser) {
await this._browser.close()
delete this._browser
}

runScript<T = unknown>(script: Script): T | null {
return super.runScript(script);
await super.teardown();
}
}