Skip to content
Merged
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 bin/pos-cli-logs.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ program
if (message == null) message = '';
if (typeof(message) != 'string') message = JSON.stringify(message);

const text = `[${created_at.replace('T', ' ')}] - ${error_type}: ${message.replace(/\n$/, '')}`;
const text = `[${created_at.replace('T', ' ')}] - ${error_type}: ${message.replace(/\r?\n$/, '')}`;
const options = { exit: false, hideTimestamp: true };

if (isError(message)) {
Expand Down
6 changes: 5 additions & 1 deletion lib/apiRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,18 @@ const buildFormData = (formData) => {
return form;
};

const apiRequest = async ({ method = 'GET', uri, body, headers = {}, formData, json = true, forever }) => {
const apiRequest = async ({ method = 'GET', uri, body, headers = {}, formData, json = true, forever, signal }) => {
logger.Debug(`[${method}] ${uri}`);

const fetchOptions = {
method,
headers: { ...headers }
};

if (signal) {
fetchOptions.signal = signal;
}

if (formData) {
const form = buildFormData(formData);
fetchOptions.body = form;
Expand Down
4 changes: 2 additions & 2 deletions lib/proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ class Gateway {
return apiRequest({ uri: `${this.api_url}/logs`, headers: this.defaultHeaders });
}

logs(json) {
return apiRequest({ uri: `${this.api_url}/logs?last_id=${json.lastId}`, json: true, forever: true, headers: this.defaultHeaders });
logs(json, { signal } = {}) {
return apiRequest({ uri: `${this.api_url}/logs?last_id=${json.lastId}`, json: true, forever: true, headers: this.defaultHeaders, signal });
}

logsv2(params) {
Expand Down
2 changes: 1 addition & 1 deletion lib/test-runner/formatters.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const formatTestLog = (logRow, isTestLog) => {
const message = logRow.message || '';
const logType = logRow.error_type || '';
const fullMessage = typeof message === 'string' ? message : JSON.stringify(message);
const cleanMessage = fullMessage.replace(/\n$/, '');
const cleanMessage = fullMessage.replace(/\r?\n$/, '');

const hasTestPath = /app\/lib\/test\/|modules\/.*\/test\/|\.liquid/.test(cleanMessage);

Expand Down
17 changes: 13 additions & 4 deletions lib/test-runner/logStream.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ class TestLogStream extends EventEmitter {
this.lastId = 0;
this.intervalId = null;
this.timeoutId = null;
this.abortController = null;
}

isValidTestSummaryJson(message) {
try {
const obj = JSON.parse(message);
const obj = JSON.parse(message.trim());

const hasTestsArray = Array.isArray(obj.tests);
const hasSuccessField = typeof obj.success === 'boolean';
Expand All @@ -37,6 +38,7 @@ class TestLogStream extends EventEmitter {
}

start() {
this.abortController = new AbortController();
this.intervalId = setInterval(() => this.fetchLogs(), POLL_INTERVAL_MS);
this.timeoutId = setTimeout(() => {
this.emit('timeout');
Expand All @@ -47,6 +49,10 @@ class TestLogStream extends EventEmitter {
}

stop() {
if (this.abortController) {
this.abortController.abort();
this.abortController = null;
}
if (this.intervalId) {
clearInterval(this.intervalId);
this.intervalId = null;
Expand All @@ -58,8 +64,10 @@ class TestLogStream extends EventEmitter {
}

async fetchLogs() {
if (!this.abortController) return;

try {
const response = await this.gateway.logs({ lastId: this.lastId || 0 });
const response = await this.gateway.logs({ lastId: this.lastId || 0 }, { signal: this.abortController.signal });
const logs = response && response.logs;
if (!logs) return;

Expand All @@ -73,6 +81,7 @@ class TestLogStream extends EventEmitter {
this.processLogMessage(row);
}
} catch (error) {
if (error.name === 'AbortError') return;
logger.Debug(`Error fetching logs: ${error.message}`);
}
}
Expand All @@ -83,7 +92,7 @@ class TestLogStream extends EventEmitter {
const fullMessage = typeof message === 'string' ? message : JSON.stringify(message);
const summaryType = this.testName ? `${this.testName} SUMMARY` : null;

const cleanMessage = fullMessage.replace(/\n$/, '');
const cleanMessage = fullMessage.replace(/\r?\n$/, '');
const hasTestPath = /app\/lib\/test\/|modules\/.*\/test\/|\.liquid/.test(cleanMessage);

if (this.testName) {
Expand Down Expand Up @@ -136,7 +145,7 @@ class TestLogStream extends EventEmitter {

parseJsonSummary(message) {
try {
const summary = JSON.parse(message);
const summary = JSON.parse(message.trim());
return transformTestResponse(summary);
} catch (error) {
logger.Debug(`[DEBUG] Failed to parse JSON summary: ${error.message}`);
Expand Down
7 changes: 0 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.