Repository navigation
Expand file tree
/
Copy pathoptions.spec.ts
More file actions
178 lines (158 loc) · 5.17 KB
/
Copy pathoptions.spec.ts
File metadata and controls
178 lines (158 loc) · 5.17 KB
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
import { describe, expect, it } from 'vitest';
import {
normalizeNativeScriptPlatform,
resolveNativeScriptPluginOptions,
withNativeScriptCoverageLaunchCommand,
} from './options.js';
describe('resolveNativeScriptPluginOptions', () => {
it('builds a supported local NativeScript CLI command', () => {
const options = resolveNativeScriptPluginOptions(
{
platform: 'ios',
appPath: 'demo',
workers: 2,
device: 'test-simulator',
},
'/workspace',
8,
);
expect(options.appPath).toBe('/workspace/demo');
expect(options.device).toBe('test-simulator');
expect(options.launchCommand).toEqual({
command: 'npx',
args: [
'ns',
'run',
'ios',
'--no-hmr',
'--env.unitTesting',
'--env.testRunnerPort=17878',
'--device',
'test-simulator',
],
});
});
it('runs on the main thread with no worker runtimes by default', () => {
const options = resolveNativeScriptPluginOptions(
{ platform: 'android' },
'/workspace',
8,
);
expect(options.slots).toEqual({ main: true, workers: 0 });
expect(options.host).toBe('127.0.0.1');
expect(options.launch).toBe(true);
expect(options.connectTimeout).toBe(120_000);
});
it('adds worker slots on top of the main thread', () => {
expect(
resolveNativeScriptPluginOptions(
{ platform: 'ios', workers: 2 },
'/workspace',
8,
).slots,
).toEqual({ main: true, workers: 2 });
expect(
resolveNativeScriptPluginOptions(
{ platform: 'ios', mainThread: false, workers: 'auto' },
'/workspace',
8,
).slots,
).toEqual({ main: false, workers: 4 });
});
it('requires at least one execution context', () => {
expect(() =>
resolveNativeScriptPluginOptions({
platform: 'android',
mainThread: false,
}),
).toThrow(RangeError);
});
it('targets visionOS with an ns run visionos launch command', () => {
const options = resolveNativeScriptPluginOptions(
{ platform: 'visionos' },
'/workspace',
8,
);
expect(options.platform).toBe('visionos');
expect(options.adbReverse).toBe(false);
expect(options.launchCommand.args).toEqual([
'ns',
'run',
'visionos',
'--no-hmr',
'--env.unitTesting',
'--env.testRunnerPort=17878',
]);
});
it('normalizes loose platform spellings from NS_PLATFORM and the CLI', () => {
expect(normalizeNativeScriptPlatform('iOS')).toBe('ios');
expect(normalizeNativeScriptPlatform('Android')).toBe('android');
expect(normalizeNativeScriptPlatform('visionOS')).toBe('visionos');
expect(normalizeNativeScriptPlatform('vision')).toBe('visionos');
expect(
resolveNativeScriptPluginOptions({ platform: 'visionOS' }, '/workspace', 8)
.platform,
).toBe('visionos');
});
it('rejects unsupported platforms with the supported list', () => {
expect(() =>
resolveNativeScriptPluginOptions({ platform: 'windows' }),
).toThrow(/Supported platforms: android, ios, visionos/);
});
it('reverses the runner port over adb for Android only', () => {
expect(
resolveNativeScriptPluginOptions({ platform: 'android' }),
).toMatchObject({ adbReverse: true, adbPath: 'adb' });
expect(resolveNativeScriptPluginOptions({ platform: 'ios' })).toMatchObject(
{ adbReverse: false },
);
expect(
resolveNativeScriptPluginOptions({
platform: 'android',
adbReverse: false,
adbPath: '/opt/android/platform-tools/adb',
}),
).toMatchObject({
adbReverse: false,
adbPath: '/opt/android/platform-tools/adb',
});
});
it('threads a custom port through the launch command', () => {
expect(
resolveNativeScriptPluginOptions(
{ platform: 'android', port: 19_100 },
'/workspace',
8,
).launchCommand.args,
).toContain('--env.testRunnerPort=19100');
});
it('validates the WebSocket port', () => {
expect(() =>
resolveNativeScriptPluginOptions({ platform: 'android', port: 0 }),
).toThrow(RangeError);
expect(() =>
resolveNativeScriptPluginOptions({ platform: 'android', port: 70_000 }),
).toThrow(RangeError);
});
it('adds the coverage build flag without changing the original command', () => {
const command = { command: 'npx', args: ['ns', 'run', 'ios'] };
const coverageCommand = withNativeScriptCoverageLaunchCommand(command);
expect(coverageCommand).toEqual({
command: 'npx',
args: ['ns', 'run', 'ios', '--env.codeCoverage'],
});
expect(command.args).toEqual(['ns', 'run', 'ios']);
expect(withNativeScriptCoverageLaunchCommand(coverageCommand)).toBe(
coverageCommand,
);
});
});
describe('tvOS', () => {
it('accepts CLI casing and launches the tvOS platform without adb', () => {
const options = resolveNativeScriptPluginOptions({ platform: 'tvOS', device: 'apple-tv' });
expect(options.platform).toBe('tvos');
expect(options.launchCommand.args).toContain('tvos');
expect(options.launchCommand.args).toContain('apple-tv');
expect(options.adbReverse).toBe(false);
});
});