-
-
Notifications
You must be signed in to change notification settings - Fork 197
/
Copy pathtest.ts
104 lines (88 loc) · 4.1 KB
/
test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
abstract class TestCommandBase {
public allowedParameters: ICommandParameter[] = [];
protected abstract platform: string;
protected abstract $projectData: IProjectData;
protected abstract $testExecutionService: ITestExecutionService;
protected abstract $analyticsService: IAnalyticsService;
protected abstract $options: IOptions;
protected abstract $platformEnvironmentRequirements: IPlatformEnvironmentRequirements;
protected abstract $errors: IErrors;
protected abstract $cleanupService: ICleanupService;
protected abstract $liveSyncCommandHelper: ILiveSyncCommandHelper;
protected abstract $devicesService: Mobile.IDevicesService;
async execute(args: string[]): Promise<void> {
let devices = [];
if (this.$options.debugBrk) {
const selectedDeviceForDebug = await this.$devicesService.pickSingleDevice({
onlyEmulators: this.$options.emulator,
onlyDevices: this.$options.forDevice,
deviceId: this.$options.device
});
devices = [selectedDeviceForDebug];
// const debugData = this.getDebugData(platform, projectData, deployOptions, { device: selectedDeviceForDebug.deviceInfo.identifier });
// await this.$debugService.debug(debugData, this.$options);
} else {
devices = await this.$liveSyncCommandHelper.getDeviceInstances(this.platform);
}
if (!this.$options.env) { this.$options.env = { }; }
this.$options.env.unitTesting = true;
const liveSyncInfo = this.$liveSyncCommandHelper.getLiveSyncData(this.$projectData.projectDir);
const deviceDebugMap: IDictionary<boolean> = {};
devices.forEach(device => deviceDebugMap[device.deviceInfo.identifier] = this.$options.debugBrk);
const deviceDescriptors = await this.$liveSyncCommandHelper.createDeviceDescriptors(devices, this.platform, <any>{ deviceDebugMap });
await this.$testExecutionService.startKarmaServer(this.platform, liveSyncInfo, deviceDescriptors);
}
async canExecute(args: string[]): Promise<boolean | ICanExecuteCommandOutput> {
this.$projectData.initializeProjectData();
this.$analyticsService.setShouldDispose(this.$options.justlaunch || !this.$options.watch);
this.$cleanupService.setShouldDispose(this.$options.justlaunch || !this.$options.watch);
const output = await this.$platformEnvironmentRequirements.checkEnvironmentRequirements({
platform: this.platform,
projectDir: this.$projectData.projectDir,
options: this.$options,
notConfiguredEnvOptions: {
hideSyncToPreviewAppOption: true,
hideCloudBuildOption: true
}
});
const canStartKarmaServer = await this.$testExecutionService.canStartKarmaServer(this.$projectData);
if (!canStartKarmaServer) {
this.$errors.fail({
formatStr: "Error: In order to run unit tests, your project must already be configured by running $ tns test init.",
suppressCommandHelp: true,
errorCode: ErrorCodes.TESTS_INIT_REQUIRED
});
}
return output.canExecute && canStartKarmaServer;
}
}
class TestAndroidCommand extends TestCommandBase implements ICommand {
protected platform = "android";
constructor(protected $projectData: IProjectData,
protected $testExecutionService: ITestExecutionService,
protected $analyticsService: IAnalyticsService,
protected $options: IOptions,
protected $platformEnvironmentRequirements: IPlatformEnvironmentRequirements,
protected $errors: IErrors,
protected $cleanupService: ICleanupService,
protected $liveSyncCommandHelper: ILiveSyncCommandHelper,
protected $devicesService: Mobile.IDevicesService) {
super();
}
}
class TestIosCommand extends TestCommandBase implements ICommand {
protected platform = "iOS";
constructor(protected $projectData: IProjectData,
protected $testExecutionService: ITestExecutionService,
protected $analyticsService: IAnalyticsService,
protected $options: IOptions,
protected $platformEnvironmentRequirements: IPlatformEnvironmentRequirements,
protected $errors: IErrors,
protected $cleanupService: ICleanupService,
protected $liveSyncCommandHelper: ILiveSyncCommandHelper,
protected $devicesService: Mobile.IDevicesService) {
super();
}
}
$injector.registerCommand("test|android", TestAndroidCommand);
$injector.registerCommand("test|ios", TestIosCommand);