Skip to content

Commit

Permalink
@enonic/mock-xp 1.0.0-RC1
Browse files Browse the repository at this point in the history
  • Loading branch information
ComLock committed Apr 15, 2024
1 parent 61bf182 commit 1a30ce8
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 35 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"@enonic-types/lib-project": "^7",
"@enonic-types/lib-task": "^7",
"@enonic/js-utils": "^1.7.1",
"@enonic/mock-xp": "^1.0.0-B1",
"@enonic/mock-xp": "^1.0.0-RC1",
"@swc/core": "^1.4.12",
"@types/node": "^20.12.5",
"@types/react": "^18.2.74",
Expand Down
23 changes: 19 additions & 4 deletions src/jest/server/mockXP.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import type {
assetUrl as assetUrlType,
getContent as getContentType,
imageUrl as imageUrlType,
assetUrl as assetUrlType,
getContent as getContentType,
imageUrl as imageUrlType,
} from '@enonic-types/lib-portal';
import type {Log, Resolve} from './global';


import {
App,
LibContent,
LibPortal,
mockResolve,
Server
} from '@enonic/mock-xp';
import {jest} from '@jest/globals';
Expand All @@ -31,6 +33,19 @@ export const server = new Server({
projectName: PROJECT_NAME
});

// Avoid type errors below.
// eslint-disable-next-line @typescript-eslint/no-namespace
declare module globalThis {
let log: Log
let resolve: Resolve
}

globalThis.log = server.log as Log;
globalThis.resolve = mockResolve({
applicationKey: APP_KEY,
basePath: __dirname
});

const app = new App({
key: APP_KEY
});
Expand All @@ -51,4 +66,4 @@ jest.mock('/lib/xp/portal', () => {
getContent: jest.fn<typeof getContentType>(() => libPortal.getContent()),
imageUrl: jest.fn<typeof imageUrlType>((params) => libPortal.imageUrl(params)),
}
}, { virtual: true });
}, { virtual: true });
27 changes: 1 addition & 26 deletions src/jest/server/preview.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type {ByteSource} from '@enonic-types/core';
import type {Log, Resolve} from './global';


import {
Expand All @@ -15,31 +14,7 @@ import {
} from './mockXP';
import './mockLibThymeleaf';
import {readFileSync} from 'fs';
import {
join,
resolve as pathResolve
} from 'path';


//──────────────────────────────────────────────────────────────────────────────
// Mock globals
//──────────────────────────────────────────────────────────────────────────────
// Avoid type errors below.
// eslint-disable-next-line @typescript-eslint/no-namespace
declare module globalThis {
let log: Log
let resolve: Resolve
}
globalThis.log = server.log as Log;
globalThis.resolve = (path: string): ReturnType<Resolve> => {
// console.debug('resolve called with path:', path);
if (path === 'preview.html') {
const resolvedPath = pathResolve(__dirname, path);
// console.debug('Resolved path:', resolvedPath);
return resolvedPath as unknown as ReturnType<Resolve>;
}
throw new Error(`Unable to resolve path:${path}`);
}
import {join} from 'path';


//──────────────────────────────────────────────────────────────────────────────
Expand Down

0 comments on commit 1a30ce8

Please sign in to comment.