|
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,36 @@ describe("androidToolsInfo", () => { |
154 | 157 | assert.deepEqual(supportedTargets, expectedTargets); |
155 | 158 | }; |
156 | 159 |
|
| 160 | + it.each(["catalog:", "catalog:mobile"])( |
| 161 | + "reads the installed Android runtime for %s", |
| 162 | + (specifier) => { |
| 163 | + const projectDir = mkdtempSync(join(tmpdir(), "doctor-catalog-")); |
| 164 | + try { |
| 165 | + const runtimeDir = join(projectDir, "node_modules", "@nativescript", "android"); |
| 166 | + mkdirSync(runtimeDir, { recursive: true }); |
| 167 | + writeFileSync( |
| 168 | + join(projectDir, "package.json"), |
| 169 | + JSON.stringify({ devDependencies: { "@nativescript/android": specifier } }), |
| 170 | + ); |
| 171 | + writeFileSync(join(runtimeDir, "package.json"), JSON.stringify({ version: "8.1.0" })); |
| 172 | + const childProcess = new ChildProcess(); |
| 173 | + const distTags = vi.spyOn(childProcess, "execSync").mockReturnValue("{}"); |
| 174 | + const hostInfo = new HostInfo(new WinReg()); |
| 175 | + const info = new AndroidToolsInfo( |
| 176 | + childProcess, |
| 177 | + new FileSystem(), |
| 178 | + hostInfo, |
| 179 | + new Helpers(hostInfo), |
| 180 | + ); |
| 181 | + const targets = info.getSupportedTargets(projectDir); |
| 182 | + assert.equal(targets[targets.length - 1], "android-30"); |
| 183 | + assert.lengthOf(distTags.mock.calls, 0); |
| 184 | + } finally { |
| 185 | + rmSync(projectDir, { recursive: true, force: true }); |
| 186 | + } |
| 187 | + }, |
| 188 | + ); |
| 189 | + |
157 | 190 | it("runtime 6.0.0 should support android-17 - android-28", () => { |
158 | 191 | assertSupportedTargets( |
159 | 192 | "6.0.0", |
|
0 commit comments