1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-21 09:38:01 +02:00

Fixed tests and server build

This commit is contained in:
Laurent Cozic 2021-05-25 17:50:51 +02:00
parent 71a7fc015a
commit cde25fad92
10 changed files with 60 additions and 54 deletions

View File

@ -104,6 +104,9 @@ packages/app-cli/tests/services/plugins/api/JoplinWorkspace.js.map
packages/app-cli/tests/services/plugins/sandboxProxy.d.ts packages/app-cli/tests/services/plugins/sandboxProxy.d.ts
packages/app-cli/tests/services/plugins/sandboxProxy.js packages/app-cli/tests/services/plugins/sandboxProxy.js
packages/app-cli/tests/services/plugins/sandboxProxy.js.map packages/app-cli/tests/services/plugins/sandboxProxy.js.map
packages/app-cli/tests/testUtils.d.ts
packages/app-cli/tests/testUtils.js
packages/app-cli/tests/testUtils.js.map
packages/app-desktop/ElectronAppWrapper.d.ts packages/app-desktop/ElectronAppWrapper.d.ts
packages/app-desktop/ElectronAppWrapper.js packages/app-desktop/ElectronAppWrapper.js
packages/app-desktop/ElectronAppWrapper.js.map packages/app-desktop/ElectronAppWrapper.js.map

3
.gitignore vendored
View File

@ -90,6 +90,9 @@ packages/app-cli/tests/services/plugins/api/JoplinWorkspace.js.map
packages/app-cli/tests/services/plugins/sandboxProxy.d.ts packages/app-cli/tests/services/plugins/sandboxProxy.d.ts
packages/app-cli/tests/services/plugins/sandboxProxy.js packages/app-cli/tests/services/plugins/sandboxProxy.js
packages/app-cli/tests/services/plugins/sandboxProxy.js.map packages/app-cli/tests/services/plugins/sandboxProxy.js.map
packages/app-cli/tests/testUtils.d.ts
packages/app-cli/tests/testUtils.js
packages/app-cli/tests/testUtils.js.map
packages/app-desktop/ElectronAppWrapper.d.ts packages/app-desktop/ElectronAppWrapper.d.ts
packages/app-desktop/ElectronAppWrapper.js packages/app-desktop/ElectronAppWrapper.js
packages/app-desktop/ElectronAppWrapper.js.map packages/app-desktop/ElectronAppWrapper.js.map

View File

@ -7,8 +7,8 @@ import Setting from '@joplin/lib/models/Setting';
import * as fs from 'fs-extra'; import * as fs from 'fs-extra';
import Note from '@joplin/lib/models/Note'; import Note from '@joplin/lib/models/Note';
import Folder from '@joplin/lib/models/Folder'; import Folder from '@joplin/lib/models/Folder';
import { newPluginScript } from '@joplin/lib/testing/test-utils';
import { expectNotThrow, setupDatabaseAndSynchronizer, switchClient, expectThrow, createTempDir, supportDir } from '@joplin/lib/testing/test-utils'; import { expectNotThrow, setupDatabaseAndSynchronizer, switchClient, expectThrow, createTempDir, supportDir } from '@joplin/lib/testing/test-utils';
import { newPluginScript } from '../../testUtils';
const testPluginDir = `${supportDir}/plugins`; const testPluginDir = `${supportDir}/plugins`;

View File

@ -1,7 +1,7 @@
import Setting from '@joplin/lib/models/Setting'; import Setting from '@joplin/lib/models/Setting';
import PluginService from '@joplin/lib/services/plugins/PluginService'; import { waitForFolderCount, setupDatabaseAndSynchronizer, switchClient, afterEachCleanUp } from '@joplin/lib/testing/test-utils';
const { waitForFolderCount, newPluginService, newPluginScript, setupDatabaseAndSynchronizer, switchClient, afterEachCleanUp } = require('@joplin/lib/testing/test-utils');
import Folder from '@joplin/lib/models/Folder'; import Folder from '@joplin/lib/models/Folder';
import { newPluginScript, newPluginService } from '../../../testUtils';
describe('JoplinSettings', () => { describe('JoplinSettings', () => {
@ -16,7 +16,7 @@ describe('JoplinSettings', () => {
}); });
test('should listen to setting change event', async () => { test('should listen to setting change event', async () => {
const service = new newPluginService() as PluginService; const service = newPluginService();
const pluginScript = newPluginScript(` const pluginScript = newPluginScript(`
joplin.plugins.register({ joplin.plugins.register({
@ -68,7 +68,7 @@ describe('JoplinSettings', () => {
}); });
test('should allow registering multiple settings', async () => { test('should allow registering multiple settings', async () => {
const service = new newPluginService() as PluginService; const service = newPluginService();
const pluginScript = newPluginScript(` const pluginScript = newPluginScript(`
joplin.plugins.register({ joplin.plugins.register({

View File

@ -1,6 +1,6 @@
import KeymapService from '@joplin/lib/services/KeymapService'; import KeymapService from '@joplin/lib/services/KeymapService';
import PluginService from '@joplin/lib/services/plugins/PluginService'; import { setupDatabaseAndSynchronizer, switchClient, afterEachCleanUp } from '@joplin/lib/testing/test-utils';
const { newPluginService, newPluginScript, setupDatabaseAndSynchronizer, switchClient, afterEachCleanUp } = require('@joplin/lib/testing/test-utils'); import { newPluginScript, newPluginService } from '../../../testUtils';
describe('JoplinViewMenuItem', () => { describe('JoplinViewMenuItem', () => {
@ -15,7 +15,7 @@ describe('JoplinViewMenuItem', () => {
}); });
test('should register commands with the keymap service', async () => { test('should register commands with the keymap service', async () => {
const service = new newPluginService() as PluginService; const service = newPluginService();
KeymapService.instance().initialize(); KeymapService.instance().initialize();

View File

@ -1,8 +1,9 @@
import Setting from '@joplin/lib/models/Setting'; import Setting from '@joplin/lib/models/Setting';
import { newPluginService, newPluginScript, setupDatabaseAndSynchronizer, switchClient, afterEachCleanUp } from '@joplin/lib/testing/test-utils'; import { setupDatabaseAndSynchronizer, switchClient, afterEachCleanUp } from '@joplin/lib/testing/test-utils';
import Note from '@joplin/lib/models/Note'; import Note from '@joplin/lib/models/Note';
import Folder from '@joplin/lib/models/Folder'; import Folder from '@joplin/lib/models/Folder';
import ItemChange from '@joplin/lib/models/ItemChange'; import ItemChange from '@joplin/lib/models/ItemChange';
import { newPluginScript, newPluginService } from '../../../testUtils';
describe('JoplinWorkspace', () => { describe('JoplinWorkspace', () => {

View File

@ -1,6 +1,5 @@
import sandboxProxy, { Target } from '@joplin/lib/services/plugins/sandboxProxy'; import sandboxProxy, { Target } from '@joplin/lib/services/plugins/sandboxProxy';
import { setupDatabaseAndSynchronizer, switchClient } from '@joplin/lib/testing/test-utils';
const { setupDatabaseAndSynchronizer, switchClient } = require('@joplin/lib/testing/test-utils.js');
describe('services_plugins_sandboxProxy', function() { describe('services_plugins_sandboxProxy', function() {

View File

@ -0,0 +1,41 @@
import PluginService from '@joplin/lib/services/plugins/PluginService';
import PluginRunner from '../app/services/plugins/PluginRunner';
export interface PluginServiceOptions {
getState?(): Record<string, any>;
}
export function newPluginService(appVersion = '1.4', options: PluginServiceOptions = null): PluginService {
options = options || {};
const runner = new PluginRunner();
const service = new PluginService();
service.initialize(
appVersion,
{
joplin: {},
},
runner,
{
dispatch: () => {},
getState: options.getState ? options.getState : () => {},
}
);
return service;
}
export function newPluginScript(script: string) {
return `
/* joplin-manifest:
{
"id": "org.joplinapp.plugins.PluginTest",
"manifest_version": 1,
"app_min_version": "1.4",
"name": "JS Bundle test",
"version": "1.0.0"
}
*/
${script}
`;
}

View File

@ -13,8 +13,6 @@ import KeymapService from '../services/KeymapService';
import KvStore from '../services/KvStore'; import KvStore from '../services/KvStore';
import KeychainServiceDriver from '../services/keychain/KeychainServiceDriver.node'; import KeychainServiceDriver from '../services/keychain/KeychainServiceDriver.node';
import KeychainServiceDriverDummy from '../services/keychain/KeychainServiceDriver.dummy'; import KeychainServiceDriverDummy from '../services/keychain/KeychainServiceDriver.dummy';
import PluginRunner from '../../app-cli/app/services/plugins/PluginRunner';
import PluginService from '../services/plugins/PluginService';
import FileApiDriverJoplinServer from '../file-api-driver-joplinServer'; import FileApiDriverJoplinServer from '../file-api-driver-joplinServer';
import OneDriveApi from '../onedrive-api'; import OneDriveApi from '../onedrive-api';
import SyncTargetOneDrive from '../SyncTargetOneDrive'; import SyncTargetOneDrive from '../SyncTargetOneDrive';
@ -766,45 +764,6 @@ async function createTempDir() {
return tempDirPath; return tempDirPath;
} }
interface PluginServiceOptions {
getState?(): Record<string, any>;
}
function newPluginService(appVersion = '1.4', options: PluginServiceOptions = null): PluginService {
options = options || {};
const runner = new PluginRunner();
const service = new PluginService();
service.initialize(
appVersion,
{
joplin: {},
},
runner,
{
dispatch: () => {},
getState: options.getState ? options.getState : () => {},
}
);
return service;
}
function newPluginScript(script: string) {
return `
/* joplin-manifest:
{
"id": "org.joplinapp.plugins.PluginTest",
"manifest_version": 1,
"app_min_version": "1.4",
"name": "JS Bundle test",
"version": "1.0.0"
}
*/
${script}
`;
}
async function waitForFolderCount(count: number) { async function waitForFolderCount(count: number) {
const timeout = 2000; const timeout = 2000;
const startTime = Date.now(); const startTime = Date.now();
@ -901,4 +860,4 @@ class TestApp extends BaseApplication {
} }
} }
export { supportDir, waitForFolderCount, afterAllCleanUp, exportDir, newPluginService, newPluginScript, synchronizerStart, afterEachCleanUp, syncTargetName, setSyncTargetName, syncDir, createTempDir, isNetworkSyncTarget, kvStore, expectThrow, logger, expectNotThrow, resourceService, resourceFetcher, tempFilePath, allSyncTargetItemsEncrypted, msleep, setupDatabase, revisionService, setupDatabaseAndSynchronizer, db, synchronizer, fileApi, sleep, clearDatabase, switchClient, syncTargetId, objectsEqual, checkThrowAsync, checkThrow, encryptionService, loadEncryptionMasterKey, fileContentEqual, decryptionWorker, currentClientId, id, ids, sortedIds, at, createNTestNotes, createNTestFolders, createNTestTags, TestApp }; export { supportDir, waitForFolderCount, afterAllCleanUp, exportDir, synchronizerStart, afterEachCleanUp, syncTargetName, setSyncTargetName, syncDir, createTempDir, isNetworkSyncTarget, kvStore, expectThrow, logger, expectNotThrow, resourceService, resourceFetcher, tempFilePath, allSyncTargetItemsEncrypted, msleep, setupDatabase, revisionService, setupDatabaseAndSynchronizer, db, synchronizer, fileApi, sleep, clearDatabase, switchClient, syncTargetId, objectsEqual, checkThrowAsync, checkThrow, encryptionService, loadEncryptionMasterKey, fileContentEqual, decryptionWorker, currentClientId, id, ids, sortedIds, at, createNTestNotes, createNTestFolders, createNTestTags, TestApp };

View File

@ -168,7 +168,7 @@ export async function execRequest(routes: Routers, ctx: AppContext) {
if (!match) throw new ErrorNotFound(); if (!match) throw new ErrorNotFound();
const endPoint = match.route.findEndPoint(ctx.request.method as HttpMethod, match.subPath.schema); const endPoint = match.route.findEndPoint(ctx.request.method as HttpMethod, match.subPath.schema);
if (ctx.URL.origin !== baseUrl(endPoint.type)) throw new ErrorNotFound('Invalid origin', 'invalidOrigin'); if (ctx.URL && ctx.URL.origin !== baseUrl(endPoint.type)) throw new ErrorNotFound('Invalid origin', 'invalidOrigin');
// This is a generic catch-all for all private end points - if we // This is a generic catch-all for all private end points - if we
// couldn't get a valid session, we exit now. Individual end points // couldn't get a valid session, we exit now. Individual end points