|
1 | 1 | import { AndroidToolsInfo } from "../src/android-tools-info"; |
2 | | -import { EOL } from "os"; |
| 2 | +import { EOL, tmpdir } from "os"; |
| 3 | +import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "fs"; |
| 4 | +import { join } from "path"; |
3 | 5 | import { assert } from "chai"; |
4 | 6 | import { ChildProcess } from "../src/wrappers/child-process"; |
5 | 7 | import { FileSystem } from "../src/wrappers/file-system"; |
6 | 8 | import { HostInfo } from "../src/host-info"; |
7 | 9 | import { Helpers } from "../src/helpers"; |
8 | 10 | import { Constants } from "../src/constants"; |
| 11 | +import { WinReg } from "../src/winreg"; |
9 | 12 |
|
10 | 13 | interface ITestData { |
11 | 14 | javacVersion: string; |
@@ -154,6 +157,51 @@ describe("androidToolsInfo", () => { |
154 | 157 | assert.deepEqual(supportedTargets, expectedTargets); |
155 | 158 | }; |
156 | 159 |
|
| 160 | + it.each([ |
| 161 | + "catalog:", |
| 162 | + "catalog:mobile", |
| 163 | + "workspace:*", |
| 164 | + "file:../android", |
| 165 | + "^8.0.0", |
| 166 | + ])("reads the installed Android runtime for %s", (specifier) => { |
| 167 | + const projectDir = mkdtempSync(join(tmpdir(), "doctor-runtime-")); |
| 168 | + try { |
| 169 | + const runtimeDir = join( |
| 170 | + projectDir, |
| 171 | + "node_modules", |
| 172 | + "@nativescript", |
| 173 | + "android", |
| 174 | + ); |
| 175 | + mkdirSync(runtimeDir, { recursive: true }); |
| 176 | + writeFileSync( |
| 177 | + join(projectDir, "package.json"), |
| 178 | + JSON.stringify({ |
| 179 | + devDependencies: { "@nativescript/android": specifier }, |
| 180 | + }), |
| 181 | + ); |
| 182 | + writeFileSync( |
| 183 | + join(runtimeDir, "package.json"), |
| 184 | + JSON.stringify({ version: "8.1.0" }), |
| 185 | + ); |
| 186 | + const childProcess = new ChildProcess(); |
| 187 | + const distTags = vi |
| 188 | + .spyOn(childProcess, "execSync") |
| 189 | + .mockReturnValue("{}"); |
| 190 | + const hostInfo = new HostInfo(new WinReg()); |
| 191 | + const info = new AndroidToolsInfo( |
| 192 | + childProcess, |
| 193 | + new FileSystem(), |
| 194 | + hostInfo, |
| 195 | + new Helpers(hostInfo), |
| 196 | + ); |
| 197 | + const targets = info.getSupportedTargets(projectDir); |
| 198 | + assert.equal(targets[targets.length - 1], "android-30"); |
| 199 | + assert.lengthOf(distTags.mock.calls, 0); |
| 200 | + } finally { |
| 201 | + rmSync(projectDir, { recursive: true, force: true }); |
| 202 | + } |
| 203 | + }); |
| 204 | + |
157 | 205 | it("runtime 6.0.0 should support android-17 - android-28", () => { |
158 | 206 | assertSupportedTargets( |
159 | 207 | "6.0.0", |
|
0 commit comments