Skip to content

Commit

Permalink
fix e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Varixo committed Aug 24, 2024
1 parent c22ec87 commit 0fdff56
Show file tree
Hide file tree
Showing 17 changed files with 55 additions and 62 deletions.
4 changes: 2 additions & 2 deletions packages/docs/src/routes/api/qwik/api.json
Original file line number Diff line number Diff line change
Expand Up @@ -1718,7 +1718,7 @@
}
],
"kind": "Function",
"content": "> This API is provided as an alpha preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.\n> \n\nLoad the prefetch graph for the container.\n\nEach Qwik container needs to include its own prefetch graph.\n\n\n```typescript\nPrefetchGraph: (opts?: {\n base?: string;\n manifestHash?: string;\n manifestURL?: string;\n nonce?: string;\n}) => JSXNode<string>\n```\n\n\n<table><thead><tr><th>\n\nParameter\n\n\n</th><th>\n\nType\n\n\n</th><th>\n\nDescription\n\n\n</th></tr></thead>\n<tbody><tr><td>\n\nopts\n\n\n</td><td>\n\n{ base?: string; manifestHash?: string; manifestURL?: string; nonce?: string; }\n\n\n</td><td>\n\n_(Optional)_ Options for the loading prefetch graph.\n\n- `base` - Base of the graph. For a default installation this will default to the q:base value `/build/`<!-- -->. But if more than one MFE is installed on the page, then each MFE needs to have its own base. - `manifestHash` - Hash of the manifest file to load. If not provided the hash will be extracted from the container attribute `q:manifest-hash` and assume the default build file `${base}/q-bundle-graph-${manifestHash}.json`<!-- -->. - `manifestURL` - URL of the manifest file to load if non-standard bundle graph location name.\n\n\n</td></tr>\n</tbody></table>\n**Returns:**\n\n[JSXNode](#jsxnode)<!-- -->&lt;string&gt;",
"content": "> This API is provided as an alpha preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.\n> \n\nLoad the prefetch graph for the container.\n\nEach Qwik container needs to include its own prefetch graph.\n\n\n```typescript\nPrefetchGraph: (opts?: {\n base?: string;\n manifestHash?: string;\n manifestURL?: string;\n nonce?: string;\n}) => JSXNode<string>\n```\n\n\n<table><thead><tr><th>\n\nParameter\n\n\n</th><th>\n\nType\n\n\n</th><th>\n\nDescription\n\n\n</th></tr></thead>\n<tbody><tr><td>\n\nopts\n\n\n</td><td>\n\n{ base?: string; manifestHash?: string; manifestURL?: string; nonce?: string; }\n\n\n</td><td>\n\n_(Optional)_ Options for the loading prefetch graph.\n\n- `base` - Base of the graph. For a default installation this will default to the q:base value `/build/`<!-- -->. But if more than one MFE is installed on the page, then each MFE needs to have its own base. - `manifestHash` - Hash of the manifest file to load. If not provided the hash will be extracted from the container attribute `q:manifest-hash` and assume the default build file `${base}/q-bundle-graph-${manifestHash}.json`<!-- -->. - `manifestURL` - URL of the manifest file to load if non-standard bundle graph location name.\n\n\n</td></tr>\n</tbody></table>\n**Returns:**\n\nJSXNode&lt;string&gt;",
"editUrl": "https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/components/prefetch.ts",
"mdFile": "qwik.prefetchgraph.md"
},
Expand All @@ -1732,7 +1732,7 @@
}
],
"kind": "Function",
"content": "> This API is provided as an alpha preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.\n> \n\nInstall a service worker which will prefetch the bundles.\n\nThere can only be one service worker per page. Because there can be many separate Qwik Containers on the page each container needs to load its prefetch graph using `PrefetchGraph` component.\n\n\n```typescript\nPrefetchServiceWorker: (opts: {\n base?: string;\n scope?: string;\n path?: string;\n verbose?: boolean;\n fetchBundleGraph?: boolean;\n nonce?: string;\n}) => JSXNode<'script'>\n```\n\n\n<table><thead><tr><th>\n\nParameter\n\n\n</th><th>\n\nType\n\n\n</th><th>\n\nDescription\n\n\n</th></tr></thead>\n<tbody><tr><td>\n\nopts\n\n\n</td><td>\n\n{ base?: string; scope?: string; path?: string; verbose?: boolean; fetchBundleGraph?: boolean; nonce?: string; }\n\n\n</td><td>\n\nOptions for the prefetch service worker.\n\n- `base` - Base URL for the service worker. Default is `import.meta.env.BASE_URL`<!-- -->, which is defined by Vite's `config.base` and defaults to `/`<!-- -->. - `scope` - Base URL for when the service-worker will activate. Default is `/` - `path` - Path to the service worker. Default is `qwik-prefetch-service-worker.js` unless you pass a path that starts with a `/` then the base is ignored. Default is `qwik-prefetch-service-worker.js` - `verbose` - Verbose logging for the service worker installation. Default is `false` - `nonce` - Optional nonce value for security purposes, defaults to `undefined`<!-- -->.\n\n\n</td></tr>\n</tbody></table>\n**Returns:**\n\n[JSXNode](#jsxnode)<!-- -->&lt;'script'&gt;",
"content": "> This API is provided as an alpha preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.\n> \n\nInstall a service worker which will prefetch the bundles.\n\nThere can only be one service worker per page. Because there can be many separate Qwik Containers on the page each container needs to load its prefetch graph using `PrefetchGraph` component.\n\n\n```typescript\nPrefetchServiceWorker: (opts: {\n base?: string;\n scope?: string;\n path?: string;\n verbose?: boolean;\n fetchBundleGraph?: boolean;\n nonce?: string;\n}) => JSXNode<'script'>\n```\n\n\n<table><thead><tr><th>\n\nParameter\n\n\n</th><th>\n\nType\n\n\n</th><th>\n\nDescription\n\n\n</th></tr></thead>\n<tbody><tr><td>\n\nopts\n\n\n</td><td>\n\n{ base?: string; scope?: string; path?: string; verbose?: boolean; fetchBundleGraph?: boolean; nonce?: string; }\n\n\n</td><td>\n\nOptions for the prefetch service worker.\n\n- `base` - Base URL for the service worker. Default is `import.meta.env.BASE_URL`<!-- -->, which is defined by Vite's `config.base` and defaults to `/`<!-- -->. - `scope` - Base URL for when the service-worker will activate. Default is `/` - `path` - Path to the service worker. Default is `qwik-prefetch-service-worker.js` unless you pass a path that starts with a `/` then the base is ignored. Default is `qwik-prefetch-service-worker.js` - `verbose` - Verbose logging for the service worker installation. Default is `false` - `nonce` - Optional nonce value for security purposes, defaults to `undefined`<!-- -->.\n\n\n</td></tr>\n</tbody></table>\n**Returns:**\n\nJSXNode&lt;'script'&gt;",
"editUrl": "https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/components/prefetch.ts",
"mdFile": "qwik.prefetchserviceworker.md"
},
Expand Down
4 changes: 2 additions & 2 deletions packages/docs/src/routes/api/qwik/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -3528,7 +3528,7 @@ _(Optional)_ Options for the loading prefetch graph.
</tbody></table>
**Returns:**
[JSXNode](#jsxnode)&lt;string&gt;
JSXNode&lt;string&gt;
[Edit this section](https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/components/prefetch.ts)
Expand Down Expand Up @@ -3582,7 +3582,7 @@ Options for the prefetch service worker.
</tbody></table>
**Returns:**
[JSXNode](#jsxnode)&lt;'script'&gt;
JSXNode&lt;'script'&gt;
[Edit this section](https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/components/prefetch.ts)
Expand Down
8 changes: 4 additions & 4 deletions packages/qwik-city/src/buildtime/vite/image-jsx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,21 +92,21 @@ export function imagePlugin(userOpts?: QwikCityVitePluginOptions): PluginOption[
code:
code.slice(0, index) +
`
import { _jsxQ } from '@builder.io/qwik';
import { _jsxSorted } from '@builder.io/qwik';
const PROPS = {srcSet, width, height};
export default function (props, key, _, dev) {
return _jsxQ('img', {...{decoding: 'async', loading: 'lazy'}, ...props}, PROPS, undefined, 3, key, dev);
return _jsxSorted('img', {...{decoding: 'async', loading: 'lazy'}, ...props}, PROPS, undefined, 3, key, dev);
}`,
map: null,
};
} else if (extension === '.svg') {
const { svgAttributes } = optimizeSvg({ code, path: pathId }, userOpts);
return {
code: `
import { _jsxQ } from '@builder.io/qwik';
import { _jsxSorted } from '@builder.io/qwik';
const PROPS = ${JSON.stringify(svgAttributes)};
export default function (props, key, _, dev) {
return _jsxQ('svg', props, PROPS, undefined, 3, key, dev);
return _jsxSorted('svg', props, PROPS, undefined, 3, key, dev);
}`,
map: null,
};
Expand Down
1 change: 1 addition & 0 deletions packages/qwik-labs/src/devtools/json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
export function runQwikJsonDebug(window: Window, document: Document, debug: typeof qwikJsonDebug) {
const parseQwikJSON = () => {
const rawData = JSON.parse(document.querySelector('script[type="qwik/json"]')!.textContent!);
// TODO: update qFuncs with hash!
const derivedFns =
(
document.querySelector('script[q\\:func="qwik/json"]') as any as {
Expand Down
5 changes: 4 additions & 1 deletion packages/qwik/src/core/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ export const _CONST_PROPS: unique symbol;
export interface _ContainerElement extends HTMLElement {
// (undocumented)
qContainer?: ClientContainer;
qFuncs?: Array<Function>;
qVnodeData?: string;
qVNodeRefs?: Map<number, Element | _ElementVNode>;
}
Expand Down Expand Up @@ -264,6 +263,8 @@ class DomContainer extends _SharedContainer implements ClientContainer, StoreTra
// (undocumented)
$getObjectById$: (id: number | string) => unknown;
// (undocumented)
$instanceHash$: string;
// (undocumented)
$journal$: VNodeJournal;
// Warning: (ae-forgotten-export) The symbol "ObjToProxyMap" needs to be exported by the entry point index.d.ts
//
Expand Down Expand Up @@ -1068,6 +1069,8 @@ export abstract class _SharedContainer implements Container2 {
// (undocumented)
readonly $getObjectById$: (id: number | string) => any;
// (undocumented)
$instanceHash$: string | null;
// (undocumented)
readonly $locale$: string;
// (undocumented)
readonly $proxyMap$: ObjToProxyMap;
Expand Down
4 changes: 2 additions & 2 deletions packages/qwik/src/core/container/resume.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { assertDefined, assertTrue } from '../error/assert';
import { getDocument } from '../util/dom';
import { isComment, isElement, isNode, isQwikElement, isText } from '../util/element';
import { logDebug, logWarn } from '../util/log';
import { ELEMENT_ID, QContainerAttr, QInstance, getQFuncs } from '../util/markers';
import { ELEMENT_ID, QContainerAttr, QInstanceAttr, getQFuncs } from '../util/markers';

import { emitEvent } from '../util/event';

Expand Down Expand Up @@ -99,7 +99,7 @@ export const resumeContainer = (containerEl: Element) => {
}

const doc = getDocument(containerEl);
const hash = containerEl.getAttribute(QInstance)!;
const hash = containerEl.getAttribute(QInstanceAttr)!;
const isDocElement = containerEl === doc.documentElement;
const parentJSON = isDocElement ? doc.body : containerEl;
if (qDev) {
Expand Down
4 changes: 2 additions & 2 deletions packages/qwik/src/core/qrl/qrl-class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
type InvokeContext,
type InvokeTuple,
} from '../use/use-core';
import { getQFuncs, QInstance } from '../util/markers';
import { getQFuncs, QInstanceAttr } from '../util/markers';
import { maybeThen } from '../util/promises';
import { qDev, qSerialize, qTest, seal } from '../util/qdev';
import { isArray, isFunction, type ValueOrPromise } from '../util/types';
Expand Down Expand Up @@ -137,7 +137,7 @@ export const createQRL = <TYPE>(
if (chunk === '') {
// Sync QRL
assertDefined(_containerEl, 'Sync QRL must have container element');
const hash = _containerEl.getAttribute(QInstance)!;
const hash = _containerEl.getAttribute(QInstanceAttr)!;
const doc = _containerEl.ownerDocument!;
const qFuncs = getQFuncs(doc, hash);
// No need to wrap, syncQRLs can't have captured scope
Expand Down
7 changes: 5 additions & 2 deletions packages/qwik/src/core/util/markers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@ export const QStylesAllSelector = QStyleSelector + ',' + QStyleSSelector;
export const QScopedStyle = 'q:sstyle';
export const QCtxAttr = 'q:ctx';
export const QManifestHash = 'q:manifest-hash';
export const QInstance = 'q:instance';
export const QFuncsPrefix = 'qFuncs_';

export const getQFuncs = (document: Document, hash: string): Function[] => {
export const getQFuncs = (
document: Document,
hash: string
): Array<(...args: unknown[]) => unknown> => {
return (document as any)[QFuncsPrefix + hash] || [];
};

Expand All @@ -39,6 +41,7 @@ export const QVersionAttr = 'q:version';
export const QBaseAttr = 'q:base';
export const QLocaleAttr = 'q:locale';
export const QManifestHashAttr = 'q:manifest-hash';
export const QInstanceAttr = 'q:instance';
export const QContainerIsland = 'q:container-island';
export const QContainerIslandEnd = '/' + QContainerIsland;
export const QIgnore = 'q:ignore';
Expand Down
9 changes: 7 additions & 2 deletions packages/qwik/src/core/v2/client/dom-container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@ import {
ELEMENT_PROPS,
ELEMENT_SEQ,
ELEMENT_SEQ_IDX,
getQFuncs,
OnRenderProp,
QBaseAttr,
QContainerAttr,
QContainerSelector,
QCtxAttr,
QInstanceAttr,
QScopedStyle,
QSlotParent,
QStyle,
Expand Down Expand Up @@ -112,6 +115,7 @@ export class DomContainer extends _SharedContainer implements IClientContainer,
public $rawStateData$: unknown[];
public $proxyMap$: ObjToProxyMap = new WeakMap();
public $qFuncs$: Array<(...args: unknown[]) => unknown>;
public $instanceHash$: string;

private stateData: unknown[];
private $styleIds$: Set<string> | null = null;
Expand Down Expand Up @@ -139,7 +143,8 @@ export class DomContainer extends _SharedContainer implements IClientContainer,
];
this.document = element.ownerDocument as QDocument;
this.element = element;
this.qBase = element.getAttribute('q:base')!;
this.qBase = element.getAttribute(QBaseAttr)!;
this.$instanceHash$ = element.getAttribute(QInstanceAttr)!;
// this.containerState = createContainerState(element, this.qBase);
this.qManifestHash = element.getAttribute('q:manifest-hash')!;
this.rootVNode = vnode_newUnMaterializedElement(this.element);
Expand All @@ -158,7 +163,7 @@ export class DomContainer extends _SharedContainer implements IClientContainer,
this.$rawStateData$ = JSON.parse(lastState.textContent!);
this.stateData = wrapDeserializerProxy(this, this.$rawStateData$) as unknown[];
}
this.$qFuncs$ = element.qFuncs || EMPTY_ARRAY;
this.$qFuncs$ = getQFuncs(document, this.$instanceHash$) || EMPTY_ARRAY;
}

$setRawState$(id: number, vParent: ElementVNode | VirtualVNode): void {
Expand Down
3 changes: 0 additions & 3 deletions packages/qwik/src/core/v2/client/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ export interface ContainerElement extends HTMLElement {

/** String from `<script type="qwik/vnode">` tag. */
qVnodeData?: string;

/** Map of Synchronous functions. */
qFuncs?: Array<Function>;
}

/** @internal */
Expand Down
1 change: 1 addition & 0 deletions packages/qwik/src/core/v2/shared/shared-container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export abstract class _SharedContainer implements Container2 {
readonly $getObjectById$: (id: number | string) => any;
$serverData$: Record<string, any>;
$currentUniqueId$ = 0;
$instanceHash$: string | null = null;

constructor(
scheduleDrain: () => void,
Expand Down
2 changes: 1 addition & 1 deletion packages/qwik/src/core/v2/tests/render-api.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ describe('render api', () => {
const qwikFuncScriptElements = document.querySelectorAll('script[q\\:func=qwik/json]');
expect(qwikFuncScriptElements).toHaveLength(1);
expect(qwikFuncScriptElements[0].textContent).toMatch(
/document\["qFuncs_(\w{11})"\]=\[\(p0\)=>p0\.value\]/
/document\["qFuncs_(\w{11})"\]=\[\(p0\)=>p0.value\]/
);
});
});
Expand Down
28 changes: 0 additions & 28 deletions packages/qwik/src/optimizer/src/qwik-binding-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,6 @@

// prettier-ignore
export const QWIK_BINDING_MAP = {
"darwin": {
"arm64": [
{
"platform": "darwin",
"arch": "arm64",
"abi": null,
"platformArchABI": "qwik.darwin-arm64.node"
}
],
"x64": [
{
"platform": "darwin",
"arch": "x64",
"abi": null,
"platformArchABI": "qwik.darwin-x64.node"
}
]
},
"win32": {
"x64": [
{
Expand All @@ -30,15 +12,5 @@ export const QWIK_BINDING_MAP = {
"platformArchABI": "qwik.win32-x64-msvc.node"
}
]
},
"linux": {
"x64": [
{
"platform": "linux",
"arch": "x64",
"abi": "gnu",
"platformArchABI": "qwik.linux-x64-gnu.node"
}
]
}
};
4 changes: 2 additions & 2 deletions packages/qwik/src/server/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import type {
StreamWriter,
} from './types';
import { createTimer, getBuildBase } from './utils';
import { QInstance } from '../core/util/markers';
import { QInstanceAttr } from '../core/util/markers';

const DOCTYPE = '<!DOCTYPE html>';

Expand Down Expand Up @@ -210,7 +210,7 @@ export async function renderToStream(
})
);
if (snapshotResult.funcs.length > 0) {
const hash = containerAttributes[QInstance];
const hash = containerAttributes[QInstanceAttr];
children.push(
jsx('script', {
'q:func': 'qwik/json',
Expand Down
8 changes: 4 additions & 4 deletions packages/qwik/src/server/v2-ssr-container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ import {
vNodeData_openFragment,
type VNodeData,
} from './v2-vnode-data';
import { QInstance } from '../core/util/markers';
import { QInstanceAttr } from '../core/util/markers';

export function ssrCreateContainer(
opts: {
Expand Down Expand Up @@ -205,7 +205,7 @@ class SSRContainer extends _SharedContainer implements ISSRContainer {
private unclaimedProjections: Array<ISsrComponentFrame | string | JSXChildren> = [];
unclaimedProjectionComponentFrameQueue: Array<ISsrComponentFrame> = [];
private cleanupQueue: CleanupQueue = [];
private instanceHash = hash();
$instanceHash$ = hash();

constructor(opts: Required<Required<Parameters<typeof ssrCreateContainer>>[0]>) {
super(
Expand Down Expand Up @@ -309,7 +309,7 @@ class SSRContainer extends _SharedContainer implements ISSRContainer {
[QBaseAttr]: this.buildBase,
[QLocaleAttr]: this.$locale$,
[QManifestHashAttr]: this.resolvedManifest.manifest.manifestHash,
[QInstance]: this.instanceHash,
[QInstanceAttr]: this.$instanceHash$,
};

const containerAttributeArray = Object.entries(containerAttributes).reduce<string[]>(
Expand Down Expand Up @@ -758,7 +758,7 @@ class SSRContainer extends _SharedContainer implements ISSRContainer {
scriptAttrs.push('nonce', this.renderOptions.serverData.nonce);
}
this.openElement('script', scriptAttrs);
this.write(Q_FUNCS_PREFIX.replace('HASH', this.instanceHash));
this.write(Q_FUNCS_PREFIX.replace('HASH', this.$instanceHash$));
this.write('[');
this.writeArray(fns, ',');
this.write(']');
Expand Down
6 changes: 4 additions & 2 deletions packages/qwik/src/testing/element-fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import type { MockDocument, MockWindow } from './types';
import { delay } from '../core/util/promises';
import type { QElement2, QwikLoaderEventScope } from '../core/v2/shared/types';
import { fromCamelToKebabCase } from '../core/v2/shared/event-names';
import { QFuncsPrefix, QInstanceAttr } from '../core/util/markers';

/**
* Creates a simple DOM structure for testing components.
Expand Down Expand Up @@ -49,8 +50,9 @@ export class ElementFixture {
if (code?.match(Q_FUNCS_PREFIX)) {
const equal = code.indexOf('=');
const qFuncs = (0, eval)(code.substring(equal + 1));
const container = this.host.closest(QContainerSelector);
(container as any as { qFuncs?: Function[] }).qFuncs = qFuncs;
const container = this.host.closest(QContainerSelector)!;
const hash = container.getAttribute(QInstanceAttr);
(document as any)[QFuncsPrefix + hash] = qFuncs;
}
});
this.child = null!;
Expand Down
19 changes: 14 additions & 5 deletions packages/qwik/src/testing/rendering.unit-util.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,15 @@ import type { QRL } from '../core/qrl/qrl.public';
import { ERROR_CONTEXT } from '../core/render/error-handling';
import { Slot } from '../core/render/jsx/slot.public';
import { useContextProvider } from '../core/use/use-context';
import { ELEMENT_PROPS, OnRenderProp, QScopedStyle, QStyle } from '../core/util/markers';
import {
ELEMENT_PROPS,
OnRenderProp,
QContainerSelector,
QFuncsPrefix,
QInstanceAttr,
QScopedStyle,
QStyle,
} from '../core/util/markers';
import { render2 } from '../core/v2/client/dom-render';
import {
vnode_getAttr,
Expand Down Expand Up @@ -170,12 +178,13 @@ export async function ssrRenderToDom(
/** @public */
export function emulateExecutionOfQwikFuncs(document: Document) {
const qFuncs = document.body.querySelector('[q\\:func]');
const containerElement = document.querySelector('[q\\:container]') as _ContainerElement;
if (qFuncs) {
const containerElement = document.querySelector(QContainerSelector) as _ContainerElement;
const hash = containerElement.getAttribute(QInstanceAttr);
if (qFuncs && hash) {
let code = qFuncs.textContent || '';
code = code.replace(Q_FUNCS_PREFIX, '');
code = code.replace(Q_FUNCS_PREFIX.replace('HASH', hash), '');
if (code) {
containerElement.qFuncs = eval(code);
(document as any)[QFuncsPrefix + hash] = eval(code);
}
}
}
Expand Down

0 comments on commit 0fdff56

Please sign in to comment.