Skip to content

Commit 13206fb

Browse files
committed
avoid app command coverage tdz
1 parent e247682 commit 13206fb

5 files changed

Lines changed: 68 additions & 55 deletions

File tree

src/app.ts

Lines changed: 39 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -119,40 +119,42 @@ async function selectApp({
119119
);
120120
}
121121

122-
export const appCommands = {
123-
createApp: async ({
124-
options,
125-
}: {
126-
options: { name: string; downloadUrl: string; platform?: Platform | '' };
127-
}) => {
128-
const name = options.name || (await question(t('appNameQuestion')));
129-
const { downloadUrl } = options;
130-
const platform = await getPlatform(options.platform);
131-
const { id } = await post('/app/create', { name, platform, downloadUrl });
132-
console.log(t('createAppSuccess', { id }));
133-
await selectApp({
134-
args: [String(id)],
135-
options: { platform },
136-
});
137-
},
138-
deleteApp: async ({
139-
args,
140-
options,
141-
}: {
142-
args: string[];
143-
options: { platform: Platform };
144-
}) => {
145-
const { platform } = options;
146-
const id = args[0] || (await chooseApp(platform)).id;
147-
if (!id) {
148-
console.log(t('cancelled'));
149-
}
150-
await doDelete(`/app/${id}`);
151-
console.log(t('operationSuccess'));
152-
},
153-
apps: async ({ options }: { options: { platform?: Platform | '' } }) => {
154-
const { platform = '' } = options;
155-
await listApp(platform);
156-
},
157-
selectApp,
158-
};
122+
export function getAppCommands() {
123+
return {
124+
createApp: async ({
125+
options,
126+
}: {
127+
options: { name: string; downloadUrl: string; platform?: Platform | '' };
128+
}) => {
129+
const name = options.name || (await question(t('appNameQuestion')));
130+
const { downloadUrl } = options;
131+
const platform = await getPlatform(options.platform);
132+
const { id } = await post('/app/create', { name, platform, downloadUrl });
133+
console.log(t('createAppSuccess', { id }));
134+
await selectApp({
135+
args: [String(id)],
136+
options: { platform },
137+
});
138+
},
139+
deleteApp: async ({
140+
args,
141+
options,
142+
}: {
143+
args: string[];
144+
options: { platform: Platform };
145+
}) => {
146+
const { platform } = options;
147+
const id = args[0] || (await chooseApp(platform)).id;
148+
if (!id) {
149+
console.log(t('cancelled'));
150+
}
151+
await doDelete(`/app/${id}`);
152+
console.log(t('operationSuccess'));
153+
},
154+
apps: async ({ options }: { options: { platform?: Platform | '' } }) => {
155+
const { platform = '' } = options;
156+
await listApp(platform);
157+
},
158+
selectApp,
159+
};
160+
}

src/bin.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env node
22

33
import { loadSession } from './api';
4-
import { appCommands } from './app';
4+
import { getAppCommands } from './app';
55
import { bundleCommands } from './bundle';
66
import { diffCommands } from './diff';
77
import { installCommands } from './install';
@@ -43,7 +43,7 @@ const commandHandlers: Record<string, CliCommandHandler> = {
4343
...userCommands,
4444
...bundleCommands,
4545
...diffCommands,
46-
...appCommands,
46+
...getAppCommands(),
4747
...packageCommands,
4848
...versionCommands,
4949
...installCommands,

src/provider.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,10 @@ export class CLIProviderImpl implements CLIProvider {
171171
return this.runMessageCommand(
172172
async () => {
173173
const resolvedPlatform = await this.getPlatform(platform);
174-
const { appCommands } = await import('./app');
175-
await appCommands.apps({ options: { platform: resolvedPlatform } });
174+
const { getAppCommands } = await import('./app');
175+
await getAppCommands().apps({
176+
options: { platform: resolvedPlatform },
177+
});
176178
},
177179
'Unknown error listing apps',
178180
'Apps listed successfully',
@@ -182,8 +184,8 @@ export class CLIProviderImpl implements CLIProvider {
182184
async createApp(name: string, platform: Platform): Promise<CommandResult> {
183185
return this.runMessageCommand(
184186
async () => {
185-
const { appCommands } = await import('./app');
186-
await appCommands.createApp({
187+
const { getAppCommands } = await import('./app');
188+
await getAppCommands().createApp({
187189
options: {
188190
name,
189191
platform,

tests/app.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { afterEach, describe, expect, spyOn, test } from 'bun:test';
22
import fs from 'fs';
33
import * as api from '../src/api';
4-
import { appCommands, assertPlatform, getSelectedApp } from '../src/app';
4+
import { assertPlatform, getAppCommands, getSelectedApp } from '../src/app';
55

66
describe('assertPlatform', () => {
77
test('accepts ios', () => {
@@ -133,7 +133,7 @@ describe('appCommands.createApp', () => {
133133
writeFileSpy = spyOn(fs.promises, 'writeFile').mockResolvedValue();
134134
consoleLogSpy = spyOn(console, 'log').mockImplementation(() => {});
135135

136-
const createApp = appCommands.createApp;
136+
const createApp = getAppCommands().createApp;
137137
await createApp({
138138
options: {
139139
name: 'SmallWOD',

tests/command-handlers.test.ts

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,6 @@ function findThisUsagesInCommandMaps(filePath: string): string[] {
2424
const errors: string[] = [];
2525

2626
function visitCommandMap(node: ts.Node): void {
27-
if (!ts.isVariableDeclaration(node)) {
28-
ts.forEachChild(node, visitCommandMap);
29-
return;
30-
}
31-
32-
if (!ts.isIdentifier(node.name) || !node.name.text.endsWith('Commands')) {
33-
return;
34-
}
35-
3627
function scanForThis(child: ts.Node): void {
3728
if (child.kind === ts.SyntaxKind.ThisKeyword) {
3829
const { line, character } = sourceFile.getLineAndCharacterOfPosition(
@@ -43,9 +34,27 @@ function findThisUsagesInCommandMaps(filePath: string): string[] {
4334
ts.forEachChild(child, scanForThis);
4435
}
4536

46-
if (node.initializer) {
37+
if (
38+
ts.isVariableDeclaration(node) &&
39+
ts.isIdentifier(node.name) &&
40+
node.name.text.endsWith('Commands') &&
41+
node.initializer
42+
) {
4743
scanForThis(node.initializer);
44+
return;
4845
}
46+
47+
if (
48+
ts.isFunctionDeclaration(node) &&
49+
node.name?.text.startsWith('get') &&
50+
node.name.text.endsWith('Commands') &&
51+
node.body
52+
) {
53+
scanForThis(node.body);
54+
return;
55+
}
56+
57+
ts.forEachChild(node, visitCommandMap);
4958
}
5059

5160
visitCommandMap(sourceFile);

0 commit comments

Comments
 (0)