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

Racer 2 #629

Merged
merged 86 commits into from
May 1, 2024
Merged
Changes from 1 commit
Commits
Show all changes
86 commits
Select commit Hold shift + click to select a range
3bbe67f
Use racer-2 branch for racer dep
craigbeck Dec 19, 2023
60fe345
Remove generic params for derby classes; Add typedef extending racer …
craigbeck Jan 11, 2024
e542d37
Fix remaining types
craigbeck Jan 11, 2024
eb1a5e0
Use beta @derbyjs scoped racer
craigbeck Jan 17, 2024
2962c75
Use @derbyjs package scope
craigbeck Jan 17, 2024
0269bf9
Add missing scope for racer
craigbeck Jan 17, 2024
aa6e89b
4.0.0-beta.1
craigbeck Jan 17, 2024
9cfa69c
Add publishConfig public to package.json
craigbeck Jan 17, 2024
767980a
Use unscoped package name for ease of intergration testing
craigbeck Jan 18, 2024
7e163b2
Use unscoped package name for ease of integration testing
craigbeck Jan 18, 2024
9c7c21d
4.0.0-beta.2
craigbeck Jan 18, 2024
b3f108f
Export as namespace
craigbeck Jan 18, 2024
d01dd46
Refacor Page to interface and use clearer PageForClient internally
craigbeck Jan 18, 2024
4226dab
Use RootModel in tests
craigbeck Jan 18, 2024
8310868
Export App, PageParam types
craigbeck Jan 18, 2024
43c0ca5
Refine singleton component type
craigbeck Jan 26, 2024
28f7bfd
Move racer dep to dev dependency add peer dep
craigbeck Feb 12, 2024
331987c
Resolve type errors form racer v2
craigbeck Feb 16, 2024
611030f
Rename files for ts conversion
craigbeck Feb 16, 2024
941f9a7
Convert test-utils to typescript
craigbeck Feb 16, 2024
fe3e242
Move test-utils under src directory for build
craigbeck Feb 16, 2024
a5d5ca9
Update test-utils for publish to dist
craigbeck Feb 16, 2024
7c72e60
Fix test requires for moved test-utils
craigbeck Feb 17, 2024
9e89a63
Setup tests w ts-node
craigbeck Feb 17, 2024
2a9a678
Run tests on typescript source
craigbeck Feb 21, 2024
bfb4c14
Fix calling functions form views
craigbeck Feb 21, 2024
fc2591c
Lint typescript
craigbeck Feb 21, 2024
69849f3
Mollify linter
craigbeck Feb 21, 2024
63ab9d3
4.0.0-beta.4
craigbeck Feb 21, 2024
46b495d
Add additonal exports for test-utils
craigbeck Feb 22, 2024
4b0c045
Expose types and export file-utils
craigbeck Mar 6, 2024
f474fca
4.0.0-beta.5
craigbeck Mar 6, 2024
e1fea4e
Rename files.js to ts
craigbeck Mar 6, 2024
612ae43
Convert files to typescript
craigbeck Mar 6, 2024
025704d
4.0.0-beta.6
craigbeck Mar 6, 2024
867675c
Rename PageBase to Page
craigbeck Mar 8, 2024
161fae2
Fix disparities with ModelData and ComponentModelData
craigbeck Mar 8, 2024
5c6e173
Remove legacy event listeners; extend racer modele events
craigbeck Mar 8, 2024
39976a4
Add @types/resolve dev dependency
craigbeck Mar 18, 2024
b6bffd1
Update min racer version (beta) for new exported types
craigbeck Mar 18, 2024
61935d9
Add createApp funciton to namespace; add additional type exports
craigbeck Mar 18, 2024
13941e8
AppOptions as optional argument
craigbeck Mar 18, 2024
8de6f6d
Fix issues with incorrect Root/Child model types
craigbeck Mar 18, 2024
bdbb99e
Fix type issues with loadStyles options and compiler types
craigbeck Mar 18, 2024
f11c661
Change Component default type param to object from unknown model type
craigbeck Apr 3, 2024
b437dac
Use new event handlers for immediate events
craigbeck Apr 3, 2024
988cefd
Add overload signatures for special immediate events
craigbeck Apr 3, 2024
bb8d4a8
4.0.0-beta.7
craigbeck Apr 3, 2024
27cc1af
Add missing test file for components
craigbeck Apr 8, 2024
4b1c37b
Add use to exports
craigbeck Apr 9, 2024
98e36cf
Merge branch 'master' of github.com:derbyjs/derby into racer-2
craigbeck Apr 9, 2024
c1426a0
Fix path for domTestRunner in test file
craigbeck Apr 9, 2024
c490abf
4.0.0-beta.8
craigbeck Apr 9, 2024
b611b98
Set isProduction in AppForServer
craigbeck Apr 9, 2024
604e38a
4.0.0-beta.9
craigbeck Apr 9, 2024
f3284b0
Fix client app init by switching to racer.createModel() since racer.M…
ericyhwang Apr 11, 2024
51f441d
4.0.0-beta.10
ericyhwang Apr 11, 2024
285439a
Merge branch 'master' into racer-2
ericyhwang Apr 17, 2024
2074552
4.0.0-beta.11
ericyhwang Apr 17, 2024
f1b6578
Rename App -> AppForClient, and AppBase -> App in same pattern as Page
craigbeck Apr 18, 2024
2bcc102
Merge branch 'racer-2' of github.com:derbyjs/derby into racer-2
craigbeck Apr 18, 2024
530ca5c
3.0.3
ericyhwang Apr 18, 2024
dc973c8
Merge branch 'master' into racer-2
ericyhwang Apr 18, 2024
8b763ff
4.0.0-beta.12
ericyhwang Apr 18, 2024
8d798ab
Merge branch 'racer-2' of github.com:derbyjs/derby into racer-2
craigbeck Apr 18, 2024
fa3aa28
Rename AppBase -> App, App -> AppForClient, same for Derby/DerbyForCl…
craigbeck Apr 18, 2024
b2867f3
Update test for renamed class
craigbeck Apr 18, 2024
030d8f9
4.0.0-beta.13
craigbeck Apr 18, 2024
fd5d86c
Remove DerbyStandalone; plan to update as separate package
craigbeck Apr 19, 2024
190249d
Fix type; remove outdate comment; remove export of instance
craigbeck Apr 19, 2024
6c4daa9
Fix ComponentHarnes that was using instance from root export that was…
craigbeck Apr 19, 2024
8d2b281
Add deprecation note to bundle and writeScript methods on AppForServer
craigbeck Apr 22, 2024
6cd1ecd
Remove unused tepe defs
craigbeck Apr 23, 2024
b7344bf
Fix OnRouteCallback Page types
craigbeck Apr 23, 2024
9d0c67c
Fix types for onRoute
craigbeck Apr 23, 2024
40a1509
Ensure addViews on base App
craigbeck Apr 23, 2024
76dbf00
More complete typing of history methods
craigbeck Apr 24, 2024
1a45fdc
4.0.0-beta.14
craigbeck Apr 24, 2024
b84cdd7
Change derby property type to Derby base class
craigbeck Apr 25, 2024
3a70f3a
Improve error message when incorrect component constructor passed to …
craigbeck Apr 26, 2024
a2081ba
Remove *Immediate typings from Derby since they were moved to Racer
ericyhwang Apr 29, 2024
5d89ba9
4.0.0-beta.16
craigbeck Apr 29, 2024
2f281bb
Ensure only type exports for Page and App classes at package root
craigbeck Apr 29, 2024
3cef3df
4.0.0-beta.17
craigbeck Apr 29, 2024
1ee854d
Publish classes for client code (not type only) -- used in some testi…
craigbeck Apr 29, 2024
a3c17fd
4.0.0-beta.18
craigbeck Apr 29, 2024
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
Prev Previous commit
Next Next commit
Update test-utils for publish to dist
  • Loading branch information
craigbeck committed Feb 16, 2024
commit a5d5ca93780e11e7ac666e5f4f810600cd588c9f
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -20,8 +20,8 @@
"./AppForServer": "./dist/AppForServer.js",
"./server": "./dist/server.js",
"./Page": "./dist/Page.js",
"./test-utils": "./test-utils/index.js",
"./test-utils/*": "./test-utils/*.js"
"./test-utils": "./dist/test-utils/index.js",
"./test-utils/*": "./dist/test-utils/*.js"
},
"files": [
"dist/",
@@ -52,6 +52,7 @@
"@types/estree": "^1.0.1",
"@types/express": "^4.17.18",
"@types/node": "^20.3.1",
"@types/qs": "^6.9.11",
"@types/sharedb": "^3.3.10",
"@typescript-eslint/eslint-plugin": "^6.2.1",
"@typescript-eslint/parser": "^6.2.1",
4 changes: 2 additions & 2 deletions src/App.ts
Original file line number Diff line number Diff line change
@@ -237,8 +237,8 @@ export class App extends AppBase {
page: PageForClient;
history: {
refresh(): void,
push(): void,
replace(): void,
push(url: string): void,
replace(url: string): void,
};

constructor(derby, name, filename, options: AppOptions) {
2 changes: 1 addition & 1 deletion src/Page.ts
Original file line number Diff line number Diff line change
@@ -100,7 +100,7 @@ export abstract class PageBase extends Controller {
this.model.set('$render.prefix', prefix);
}

_setRenderParams(ns) {
_setRenderParams(ns?: string) {
this.model.set('$render.ns', ns);
this.model.set('$render.params', this.params);
this.model.set('$render.url', this.params && this.params.url);
75 changes: 40 additions & 35 deletions src/test-utils/ComponentHarness.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import qs from 'qs';
import { EventEmitter } from 'events';
import { parse as urlParse } from 'url';
import { RootModel, util as racerUtil } from 'racer';
import { App } from '../src/App';
import { AppForServer } from '../src/AppForServer';
import { Component, ComponentConstructor } from '../src/components';
import { Page, PageForClient } from '../src/Page';
import { instance as derby } from '../src';

import * as qs from 'qs';
import { RootModel } from 'racer';

import { instance as derby } from '..';
import { App } from '../App';
import { AppForServer } from '../AppForServer';
import { Component, ComponentConstructor } from '../components';
import { PageForClient } from '../Page';

class PageForHarness extends PageForClient {
component?: Component;
fragment?: any;
html?: any;
}
@@ -24,10 +27,10 @@ class AppForHarness extends App {
}

createPage() {
var page = new PageForHarness(this, this._harness.model);
const page = new PageForHarness(this, this._harness.model);
this._pages.push(page);
return page;
};
}

// Load views by filename. The client version of this method is a no-op
loadViews(...args) {
@@ -63,12 +66,13 @@ export class ComponentHarness extends EventEmitter {
this.model = new RootModel();

if (arguments.length > 0) {
// eslint-disable-next-line prefer-spread, prefer-rest-params
this.setup.apply(this, arguments);
}
}

/** @typedef { {view: {is: string, source?: string}} } InlineComponent */
/**
/** @typedef { {view: {is: string, source?: string}} } InlineComponent */
/**
* Sets up the harness with a HTML template, which should contain a `<view is="..."/>` for the
* component under test, and the components to register for the test.
*
@@ -83,7 +87,7 @@ export class ComponentHarness extends EventEmitter {
// Remaining variable arguments are components
components.forEach(constructor => this.app.component(constructor));
return this;
};
}

/**
* Stubs out view names with empty view or the provided source.
@@ -98,8 +102,9 @@ export class ComponentHarness extends EventEmitter {
* );
*/
stub() {
for (var i = 0; i < arguments.length; i++) {
var arg = arguments[i];
for (let i = 0; i < arguments.length; i++) {
// eslint-disable-next-line prefer-rest-params
const arg = arguments[i];
if (typeof arg === 'string') {
this.app.views.register(arg, '');
} else if (arg && arg.is) {
@@ -109,7 +114,7 @@ export class ComponentHarness extends EventEmitter {
}
}
return this;
};
}

/**
* Stubs out view names as components.
@@ -121,14 +126,15 @@ export class ComponentHarness extends EventEmitter {
* .stubComponent('common:file-picker', {is: 'footer', as: 'stubFooter'});
*/
stubComponent() {
for (var i = 0; i < arguments.length; i++) {
var arg = arguments[i];
var options = (typeof arg === 'string') ? {is: arg} : arg;
var Stub = createStubComponent(options);
for (let i = 0; i < arguments.length; i++) {
// eslint-disable-next-line prefer-rest-params
const arg = arguments[i];
const options = (typeof arg === 'string') ? {is: arg} : arg;
const Stub = createStubComponent(options);
this.app.component(Stub);
}
return this;
};
}

/**
* @typedef {Object} RenderOptions
@@ -145,7 +151,7 @@ export class ComponentHarness extends EventEmitter {
return this._get(function(page) {
page.html = page.get('$harness');
}, options);
};
}

/**
* Renders the harness into a `DocumentFragment`, as client-side rendering would do.
@@ -158,25 +164,25 @@ export class ComponentHarness extends EventEmitter {
return this._get(function(page) {
page.fragment = page.getFragment('$harness');
}, options);
};
}

attachTo(parentNode, node) {
return this._get(function(page) {
var view = page.getView('$harness');
var targetNode = node || parentNode.firstChild;
const view = page.getView('$harness');
const targetNode = node || parentNode.firstChild;
view.attachTo(parentNode, targetNode, page.context);
});
};
}

/**
* @param {(page: PageForHarness) => void} render
* @param {RenderOptions} [options]
*/
_get(renderFn: (page: PageForHarness) => void, options?) {
options = options || {};
var url = options.url || '';
const url = options.url || '';

var page = this.app.createPage();
const page = this.app.createPage();
// Set `page.params`, which is usually created in tracks during `Page#render`:
// https://github.com/derbyjs/tracks/blob/master/lib/index.js
function setPageUrl(url) {
@@ -192,7 +198,7 @@ export class ComponentHarness extends EventEmitter {
// Fake some methods from tracks/lib/History.js.
// JSDOM doesn't really support updating the window URL, but this should work for Derby code that
// pulls URL info from the model or page.
this.app.history = { push: setPageUrl, replace: setPageUrl };
this.app.history = { push: setPageUrl, replace: setPageUrl, refresh: () => {} };

// The `#render` assertion in assertions.js wants to compare the results of HTML and DOM
// rendering, to make sure they match. However, component `create()` methods can modify the DOM
@@ -202,7 +208,7 @@ export class ComponentHarness extends EventEmitter {
// get called. This is done by pausing the context, which prevents create() methods from getting
// called until the pause-count drops to 0.
page.context.pause();
render(page);
renderFn(page);
this.emit('pageRendered', page);
page.context.unpause();

@@ -219,7 +225,7 @@ export class ComponentHarness extends EventEmitter {
// This may need to be updated if the internal workings of Derby change.
page.component = page._components._1;
return page;
};
}

static createStubComponent(options) {
return createStubComponent(options);
@@ -248,22 +254,21 @@ function createStubComponent(options) {
}

function pageArrayInit() {
var page = this.page;
var component = this;
const page = this.page;
if (page[asArray]) {
page[asArray].push(this);
} else {
page[asArray] = [this];
}
this.on('destroy', function() {
var index = page[asArray].indexOf(component);
this.on('destroy', () => {
const index = page[asArray].indexOf(this);
if (index === -1) return;
page[asArray].splice(index, 1);
});
}

function pageInit() {
var page = this.page;
const page = this.page;
page[as] = this;
this.on('destroy', function() {
page[as] = undefined;
32 changes: 16 additions & 16 deletions src/test-utils/domTestRunner.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { util } from 'racer';
import { assertions as registerAssertions } from "./assertions";
import { ComponentHarness } from "./ComponentHarness";

import { assertions as registerAssertions } from './assertions';
import { ComponentHarness } from './ComponentHarness';

export class DomTestRunner{
window?: any;
@@ -15,7 +16,7 @@ export class DomTestRunner{

installMochaHooks(options) {
options = options || {};
var jsdomOptions = options.jsdomOptions;
const jsdomOptions = options.jsdomOptions;

// Set up runner's `window` and `document`.
if (util.isServer) {
@@ -25,27 +26,28 @@ export class DomTestRunner{
} else {
mochaHooksForBrowser(this);
}
};
}

createHarness() {
var harness = new ComponentHarness();
const harness = new ComponentHarness();
if (arguments.length > 0) {
// eslint-disable-next-line prefer-spread, prefer-rest-params
harness.setup.apply(harness, arguments);
}
this.harnesses.push(harness);
return harness;
};
}
}

function mochaHooksForNode(runner, options) {
var jsdomOptions = options.jsdomOptions;
const jsdomOptions = options.jsdomOptions;

// Use an indirect require so that Browserify doesn't try to bundle JSDOM.
var JSDOM = util.serverRequire(module, 'jsdom').JSDOM;
const JSDOM = util.serverRequire(module, 'jsdom').JSDOM;

var nodeGlobal = global;
const nodeGlobal = global;
// Keep a direct reference so that we're absolutely sure we clean up our own JSDOM.
var jsdom;
let jsdom;

global.beforeEach(function() {
jsdom = new JSDOM('', jsdomOptions);
@@ -55,7 +57,7 @@ function mochaHooksForNode(runner, options) {
nodeGlobal.window = runner.window;
nodeGlobal.document = runner.document;
// Initialize "input" and "change" listeners on the document.
require('../dist/documentListeners').add(runner.document);
module.require('../documentListeners').add(runner.document);
});

global.afterEach(function() {
@@ -71,9 +73,7 @@ function mochaHooksForNode(runner, options) {
jsdom.window.close();
runner.window = null;
runner.document = null;
// @ts-expect-error delete on non-optional attr
delete nodeGlobal.window;
// @ts-expect-error delete on non-optional attr
delete nodeGlobal.document;
});
}
@@ -90,11 +90,11 @@ function mochaHooksForBrowser(runner) {
});
}

var runner = new DomTestRunner();
const runner = new DomTestRunner();
// Set up Chai assertion chain methods: `#html` and `#render`
registerAssertions(runner, require('chai').Assertion);
registerAssertions(runner, module.require('chai').Assertion);

export function install(options) {
runner.installMochaHooks(options);
return runner;
};
}