Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/man_pages/project/testing/run-ios.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Start an emulator with specified device identifier and sdk | `$ ns run ios [--de
* `--emulator` - If set, runs the app in all available and configured ios simulators. It will start a simulator if none are already running.
* `--sdk` - Specifies the target simulator's sdk.
* `--justlaunch` - If set, does not print the application output in the console.
* `--log <Level>` - Also controls how much of the application output is printed. By default only its JavaScript output is shown. `debug` adds everything else the app logs - its native code and the system frameworks it uses, like Xcode's console - and `trace` adds debug level entries as well.
* `--log <Level>` - Also controls how much of the application output is printed. By default only its JavaScript output is shown. `debug` adds everything else the app logs - its native code, `print()` output and the system frameworks it uses, like Xcode's console - and `trace` adds debug level entries as well.
* `--clean` - If set, forces the complete rebuild of the native application.
* `--no-watch` - If set, changes in your code will not be reflected during the execution of this command.
* `--release` - If set, produces a release build by running webpack in production mode and native build in release mode. Otherwise, produces a debug build.
Expand Down
2 changes: 2 additions & 0 deletions lib/common/definitions/mobile.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ declare global {
image: string;
level: string;
message: string;
subsystem?: string;
category?: string;
}

interface IiOSLogStreamOptions {
Expand Down
12 changes: 10 additions & 2 deletions lib/common/mobile/ios/ios-log-entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ export function isIOSRuntimeLogEntry(entry: Mobile.IiOSLogEntry): boolean {
return path.basename(entry.image || "") === "NativeScript";
}

// The runtime forwards the app's stdout and stderr under this subsystem, when
// the CLI asks for it through the forwardStdio key of the app's package.json.
const STDIO_SUBSYSTEM = "org.nativescript.stdio";

// Logged by the runtime itself on every launch, not by the app.
const RUNTIME_NOISE = ["NativeScript loaded bundle"];

Expand All @@ -57,6 +61,10 @@ export function getIOSLogEntryText(
return null;
}

if (entry.subsystem === STDIO_SUBSYSTEM) {
return options.includeNative ? `${entry.category}: ${entry.message}` : null;
}

const imageName = path.basename(entry.image || "");
if (isIOSRuntimeLogEntry(entry)) {
return RUNTIME_NOISE.some((noise) => entry.message.includes(noise))
Expand All @@ -78,7 +86,7 @@ export function getIOSLogEntryText(
// asks for it, through the logChunkMarkers key of the app's package.json.
const CHUNK_JOIN_MARKER = "\u2060";
const CHUNK_LINE_MARKER = "\u2061";
const CONSOLE_PREFIX = /^CONSOLE [A-Z]+: /;
const REPEATED_PREFIX = /^(?:CONSOLE [A-Z]+|stdout|stderr): /;

// Long enough to ride out a backlog of chunks, while the rest of a message that
// never arrives, because the app crashed, still gets printed.
Expand Down Expand Up @@ -109,7 +117,7 @@ export class IOSLogChunkStitcher {

const message = this.pending.get(key) ?? {
text: "",
prefix: chunk.match(CONSOLE_PREFIX)?.[0] ?? "",
prefix: chunk.match(REPEATED_PREFIX)?.[0] ?? "",
separator: "",
timer: null,
};
Expand Down
2 changes: 2 additions & 0 deletions lib/common/mobile/ios/simulator/ios-simulator-log-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ export class IOSSimulatorLogProvider
image: event.senderImagePath,
level: (event.messageType || "").toLowerCase(),
message: event.eventMessage,
subsystem: event.subsystem,
category: event.category,
},
this.$devicePlatformsConstants.iOS,
deviceId,
Expand Down
30 changes: 30 additions & 0 deletions lib/common/test/unit-tests/mobile/ios-log-entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,31 @@ describe("getIOSLogEntryText", () => {
});
});

describe("getIOSLogEntryText for forwarded stdio", () => {
const entry = {
process: "/var/containers/Bundle/Application/X/app.app/app",
image: "/private/Frameworks/NativeScript.framework/NativeScript",
level: "default",
message: "printed",
subsystem: "org.nativescript.stdio",
category: "stdout",
};

it("is hidden by default, unlike the runtime's console output", () => {
assert.isNull(getIOSLogEntryText(entry, { processName: "app" }));
});

it("is labeled with its stream along with native output", () => {
assert.equal(
getIOSLogEntryText(
{ ...entry, category: "stderr" },
{ processName: "app", includeNative: true },
),
"stderr: printed",
);
});
});

describe("getIOSLogScope", () => {
it("maps the CLI log level to the app logs that are shown", () => {
assert.deepEqual(getIOSLogScope("INFO", false), {
Expand Down Expand Up @@ -159,6 +184,11 @@ describe("IOSLogChunkStitcher", () => {
});

it("restores the line break a chunk was cut at", () => {
add(`stdout: one${JOIN}`);
add("stdout: two");
assert.deepEqual(messages, ["stdout: onetwo"]);
messages.length = 0;

add(`CONSOLE ERROR: first${LINE}`);
add("CONSOLE ERROR: second");
assert.deepEqual(messages, ["CONSOLE ERROR: first\nsecond"]);
Expand Down
1 change: 1 addition & 0 deletions lib/controllers/prepare-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,7 @@ export class PrepareController
}
if (prepareData && !prepareData.release) {
packageData.logChunkMarkers = true;
packageData.forwardStdio = true;
}
if (packageData.ios && packageData.ios.discardUncaughtJsExceptions) {
packageData.discardUncaughtJsExceptions =
Expand Down
2 changes: 2 additions & 0 deletions test/controllers/prepare-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,8 @@ describe("prepareController", () => {
it("asks for log chunk markers in iOS debug builds only", async () => {
assert.isTrue((await writePackageJson("ios", false)).logChunkMarkers);
assert.isUndefined((await writePackageJson("ios", true)).logChunkMarkers);
assert.isTrue((await writePackageJson("ios", false)).forwardStdio);
assert.isUndefined((await writePackageJson("ios", true)).forwardStdio);
assert.isUndefined(
(await writePackageJson("android", false)).logChunkMarkers,
);
Expand Down
Loading