Skip to content

Commit 43fda3b

Browse files
Fatmerosen-vladimirov
authored andcommitted
fix: respect the schema only from nsconfig file
1 parent 69442c9 commit 43fda3b

File tree

6 files changed

+36
-99
lines changed

6 files changed

+36
-99
lines changed

lib/commands/preview.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export class PreviewCommand implements ICommand {
3030
});
3131

3232
await this.$previewQrCodeService.printLiveSyncQrCode({
33-
nsConfigPreviewAppSchema: this.$projectData.previewAppSchema,
33+
projectDir: this.$projectData.projectDir,
3434
useHotModuleReload: this.$options.hmr,
3535
link: this.$options.link
3636
});

lib/definitions/preview-app-livesync.d.ts

+3-15
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,7 @@ declare global {
1818
filesToRemove?: string[];
1919
}
2020

21-
interface IPreviewAppLiveSyncData extends IProjectDir, IHasUseHotModuleReloadOption, IBundle, IEnvOptions {
22-
qrCodeData?: IPreviewAppQrCodeData;
23-
}
24-
25-
interface IPreviewAppQrCodeData {
26-
publishKey?: string;
27-
subscribeKey?: string;
28-
schemaName?: string;
29-
}
21+
interface IPreviewAppLiveSyncData extends IProjectDir, IHasUseHotModuleReloadOption, IBundle, IEnvOptions { }
3022

3123
interface IPreviewSdkService extends EventEmitter {
3224
getQrCodeUrl(options: IGetQrCodeUrlOptions): string;
@@ -35,10 +27,7 @@ declare global {
3527
stop(): void;
3628
}
3729

38-
interface IGetQrCodeUrlOptions extends IHasUseHotModuleReloadOption {
39-
nsConfigPreviewAppSchema?: string;
40-
qrCodeData?: IPreviewAppQrCodeData;
41-
}
30+
interface IGetQrCodeUrlOptions extends IHasUseHotModuleReloadOption, IProjectDir { }
4231

4332
interface IPreviewAppPluginsService {
4433
getPluginsUsageWarnings(data: IPreviewAppLiveSyncData, device: Device): string[];
@@ -60,8 +49,7 @@ declare global {
6049
platform?: string;
6150
}
6251

63-
interface IPrintLiveSyncOptions extends IHasUseHotModuleReloadOption {
64-
nsConfigPreviewAppSchema?: string;
52+
interface IPrintLiveSyncOptions extends IGetQrCodeUrlOptions {
6553
/**
6654
* If set to true, a link will be shown on console instead of QR code
6755
* Default value is false.

lib/services/livesync/livesync-service.ts

+1-6
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,7 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
6666
env: data.env,
6767
});
6868

69-
const projectData = this.$projectDataService.getProjectData(data.projectDir);
70-
const url = this.$previewSdkService.getQrCodeUrl({
71-
nsConfigPreviewAppSchema: projectData.previewAppSchema,
72-
qrCodeData: data.qrCodeData,
73-
useHotModuleReload: data.useHotModuleReload
74-
});
69+
const url = this.$previewSdkService.getQrCodeUrl({ projectDir: data.projectDir, useHotModuleReload: data.useHotModuleReload });
7570
const result = await this.$previewQrCodeService.getLiveSyncQrCode(url);
7671
return result;
7772
}

lib/services/livesync/playground/preview-sdk-service.ts

+10-6
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,21 @@ export class PreviewSdkService extends EventEmitter implements IPreviewSdkServic
1212
private $httpClient: Server.IHttpClient,
1313
private $logger: ILogger,
1414
private $previewDevicesService: IPreviewDevicesService,
15-
private $previewAppLogProvider: IPreviewAppLogProvider) {
15+
private $previewAppLogProvider: IPreviewAppLogProvider,
16+
private $projectDataService: IProjectDataService) {
1617
super();
1718
}
1819

1920
public getQrCodeUrl(options: IGetQrCodeUrlOptions): string {
20-
const { nsConfigPreviewAppSchema, qrCodeData = { }, useHotModuleReload } = options;
21-
const schema = qrCodeData.schemaName || nsConfigPreviewAppSchema || "nsplay";
22-
const publishKey = qrCodeData.publishKey || PubnubKeys.PUBLISH_KEY;
23-
const subscribeKey = qrCodeData.subscribeKey || PubnubKeys.SUBSCRIBE_KEY;
21+
const { projectDir, useHotModuleReload } = options;
22+
const projectData = this.$projectDataService.getProjectData(projectDir);
23+
const schema = projectData.previewAppSchema || "nsplay";
24+
// TODO: Use the correct keys for the schema
25+
const publishKey = PubnubKeys.PUBLISH_KEY;
26+
const subscribeKey = PubnubKeys.SUBSCRIBE_KEY;
2427
const hmrValue = useHotModuleReload ? "1" : "0";
25-
return `${schema}://boot?instanceId=${this.instanceId}&pKey=${publishKey}&sKey=${subscribeKey}&template=play-ng&hmr=${hmrValue}`;
28+
const result = `${schema}://boot?instanceId=${this.instanceId}&pKey=${publishKey}&sKey=${subscribeKey}&template=play-ng&hmr=${hmrValue}`;
29+
return result;
2630
}
2731

2832
public async initialize(getInitialFiles: (device: Device) => Promise<FilesPayload>): Promise<void> {

lib/services/platform-environment-requirements.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ export class PlatformEnvironmentRequirements implements IPlatformEnvironmentRequ
194194
useHotModuleReload: options.hmr
195195
});
196196

197-
await this.$previewQrCodeService.printLiveSyncQrCode({ useHotModuleReload: options.hmr, link: options.link });
197+
await this.$previewQrCodeService.printLiveSyncQrCode({ projectDir, useHotModuleReload: options.hmr, link: options.link });
198198
}
199199
}
200200

test/services/preview-sdk-service.ts

+20-70
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@ import { PreviewSdkService } from "../../lib/services/livesync/playground/previe
22
import { Yok } from "../../lib/common/yok";
33
import { assert } from "chai";
44
import { LoggerStub } from "../stubs";
5-
import { PubnubKeys } from "../../lib/services/livesync/playground/preview-app-constants";
65

7-
const getPreviewSdkService = (): IPreviewSdkService => {
6+
const createTestInjector = (): IInjector => {
87
const testInjector = new Yok();
98
testInjector.register("logger", LoggerStub);
109
testInjector.register("config", {});
@@ -14,114 +13,65 @@ const getPreviewSdkService = (): IPreviewSdkService => {
1413
testInjector.register("httpClient", {
1514
httpRequest: async (options: any, proxySettings?: IProxySettings): Promise<Server.IResponse> => undefined
1615
});
16+
testInjector.register("projectDataService", {
17+
getProjectData: () => ({})
18+
});
1719

18-
return testInjector.resolve("previewSdkService");
20+
return testInjector;
1921
};
2022

2123
describe('PreviewSdkService', () => {
24+
let injector: IInjector, previewSdkService: IPreviewSdkService;
25+
26+
beforeEach(() => {
27+
injector = createTestInjector();
28+
previewSdkService = injector.resolve("previewSdkService");
29+
});
30+
2231
describe('getQrCodeUrl', () => {
2332
describe("hmr", () => {
2433
it('sets hmr to 1 when useHotModuleReload is true', async () => {
25-
const sdk = getPreviewSdkService();
26-
27-
const previewUrl = sdk.getQrCodeUrl({ useHotModuleReload: true });
34+
const previewUrl = previewSdkService.getQrCodeUrl({ projectDir: "", useHotModuleReload: true });
2835

2936
assert.isTrue(previewUrl.indexOf("hmr=1") > -1);
3037
});
3138
it('sets hmr to 0 when useHotModuleReload is false', async () => {
32-
const sdk = getPreviewSdkService();
33-
34-
const previewUrl = sdk.getQrCodeUrl({ useHotModuleReload: false });
39+
const previewUrl = previewSdkService.getQrCodeUrl({ projectDir: "", useHotModuleReload: false });
3540

3641
assert.isTrue(previewUrl.indexOf("hmr=0") > -1);
3742
});
3843
});
3944

4045
describe("schema", () => {
41-
const testCases: [{ name: string, schemaFromApi: string, schemaFromNsConfig: string, expectedSchemaName: string }] = [
46+
const testCases = [
4247
{
4348
name: "should return the schema from api",
44-
schemaFromApi: "ksplay",
45-
schemaFromNsConfig: null,
46-
expectedSchemaName: "ksplay"
49+
schemaFromNsConfig: "nsplay",
50+
expectedSchemaName: "nsplay"
4751
},
4852
{
4953
name: "should return the schema from nsconfig",
50-
schemaFromApi: null,
5154
schemaFromNsConfig: "ksplay",
5255
expectedSchemaName: "ksplay"
5356
},
5457
{
5558
name: "should return the default schema",
56-
schemaFromApi: null,
5759
schemaFromNsConfig: null,
5860
expectedSchemaName: "nsplay"
5961
}
6062
];
6163

6264
_.each(testCases, testCase => {
6365
it(`${testCase.name}`, () => {
64-
const qrCodeData = { schemaName: testCase.schemaFromApi };
65-
const qrCodeOptions = { nsConfigPreviewAppSchema: testCase.schemaFromNsConfig, qrCodeData, useHotModuleReload: true };
66-
const previewSdkService = getPreviewSdkService();
66+
const qrCodeOptions = { projectDir: "myTestDir", useHotModuleReload: true };
67+
const projectDataService = injector.resolve("projectDataService");
68+
projectDataService.getProjectData = () => ({ previewAppSchema: testCase.schemaFromNsConfig });
6769

6870
const qrCodeUrl = previewSdkService.getQrCodeUrl(qrCodeOptions);
6971

7072
assert.deepEqual(qrCodeUrl.split(":")[0], testCase.expectedSchemaName);
7173
});
7274
});
7375
});
74-
75-
describe("publishKey", () => {
76-
const testCases = [
77-
{
78-
name: "should return the provided key from api",
79-
publishKeyFromApi: "myTestPublishKey",
80-
expectedPublishKey: "myTestPublishKey"
81-
},
82-
{
83-
name: "should return the default key",
84-
publishKeyFromApi: null,
85-
expectedPublishKey: PubnubKeys.PUBLISH_KEY
86-
}
87-
];
88-
89-
_.each(testCases, testCase => {
90-
it(`${testCase.name}`, () => {
91-
const qrCodeOptions = { projectData: <any>{}, qrCodeData: <any>{ publishKey: testCase.publishKeyFromApi }, useHotModuleReload: true };
92-
const previewSdkService = getPreviewSdkService();
93-
94-
const qrCodeUrl = previewSdkService.getQrCodeUrl(qrCodeOptions);
95-
96-
assert.isTrue(qrCodeUrl.indexOf(`&pKey=${testCase.expectedPublishKey}`) > -1);
97-
});
98-
});
99-
});
100-
101-
describe("subscribeKey", () => {
102-
const testCases = [
103-
{
104-
name: "should return the provided key from api",
105-
subscribeKeyFromApi: "myTestSubscribeKey",
106-
expectedSubscribeKey: "myTestSubscribeKey"
107-
},
108-
{
109-
name: "should return the default key",
110-
subscribeKeyFromApi: null,
111-
expectedSubscribeKey: PubnubKeys.SUBSCRIBE_KEY
112-
}
113-
];
114-
115-
_.each(testCases, testCase => {
116-
it(`${testCase.name}`, () => {
117-
const qrCodeOptions = { projectData: <any>{}, qrCodeData: <any>{ subscribeKey: testCase.subscribeKeyFromApi }, useHotModuleReload: true };
118-
const previewSdkService = getPreviewSdkService();
119-
120-
const qrCodeUrl = previewSdkService.getQrCodeUrl(qrCodeOptions);
121-
122-
assert.isTrue(qrCodeUrl.indexOf(`&sKey=${testCase.expectedSubscribeKey}`) > -1);
123-
});
124-
});
125-
});
12676
});
12777
});

0 commit comments

Comments
 (0)