Skip to content

Support cypress network logs #533

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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
3 changes: 3 additions & 0 deletions bin/commands/runs.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ module.exports = function run(args, rawArgs) {
//accept the local from env variable if provided
utils.setLocal(bsConfig, args);

//set network logs
utils.setNetworkLogs(bsConfig);

// set Local Mode (on-demand/ always-on)
utils.setLocalMode(bsConfig, args);

Expand Down
9 changes: 9 additions & 0 deletions bin/helpers/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -1045,6 +1045,15 @@ exports.getNetworkErrorMessage = (dashboard_url) => {
return chalk.red(message)
}

exports.setNetworkLogs = (bsConfig) => {
if(bsConfig.run_settings.networkLogs == 'true' || bsConfig.run_settings.networkLogs == true) {
bsConfig.run_settings.networkLogs = 'true'
} else {
bsConfig.run_settings.networkLogs = 'false'
}
logger.debug(`Networks logs value: ${bsConfig.run_settings.networkLogs}`);
}

exports.versionChangedMessage = (preferredVersion, actualVersion, frameworkUpgradeMessage = '') => {
let message = Constants.userMessages.CYPRESS_VERSION_CHANGED.replace("<preferredVersion>", preferredVersion);
message = message.replace("<actualVersion>", actualVersion);
Expand Down
26 changes: 20 additions & 6 deletions test/unit/bin/commands/runs.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ describe("runs", () => {
setRecordCapsStub = sandbox.stub().returns(undefined);
setNodeVersionStub = sandbox.stub();
setBuildTagsStub = sandbox.stub();
setNetworkLogsStub = sandbox.stub();
});

afterEach(() => {
Expand Down Expand Up @@ -170,7 +171,8 @@ describe("runs", () => {
setRecordCaps: setRecordCapsStub,
setDebugMode: setDebugModeStub,
setNodeVersion: setNodeVersionStub,
setBuildTags: setBuildTagsStub
setBuildTags: setBuildTagsStub,
setNetworkLogs: setNetworkLogsStub
},
'../helpers/capabilityHelper': {
validate: capabilityValidatorStub
Expand Down Expand Up @@ -221,6 +223,7 @@ describe("runs", () => {
sinon.assert.calledOnce(setRecordCapsStub);
sinon.assert.calledOnce(setNodeVersionStub);
sinon.assert.calledOnce(setBuildTagsStub);
sinon.assert.calledOnce(setNetworkLogsStub);
sinon.assert.calledOnceWithExactly(
sendUsageReportStub,
bsConfig,
Expand Down Expand Up @@ -284,6 +287,7 @@ describe("runs", () => {
setRecordCapsStub = sandbox.stub().returns(undefined);
setNodeVersionStub = sandbox.stub();
setBuildTagsStub = sandbox.stub();
setNetworkLogsStub = sandbox.stub();
});

afterEach(() => {
Expand Down Expand Up @@ -333,7 +337,8 @@ describe("runs", () => {
setRecordCaps: setRecordCapsStub,
setDebugMode: setDebugModeStub,
setNodeVersion: setNodeVersionStub,
setBuildTags: setBuildTagsStub
setBuildTags: setBuildTagsStub,
setNetworkLogs: setNetworkLogsStub
},
'../helpers/capabilityHelper': {
validate: capabilityValidatorStub,
Expand Down Expand Up @@ -403,6 +408,7 @@ describe("runs", () => {
sinon.assert.calledOnce(setRecordCapsStub);
sinon.assert.calledOnce(setNodeVersionStub);
sinon.assert.calledOnce(setBuildTagsStub);
sinon.assert.calledOnce(setNetworkLogsStub);
sinon.assert.calledOnceWithExactly(
sendUsageReportStub,
bsConfig,
Expand Down Expand Up @@ -468,6 +474,7 @@ describe("runs", () => {
setRecordCapsStub = sandbox.stub().returns(undefined);
setNodeVersionStub = sandbox.stub();
setBuildTagsStub = sandbox.stub();
setNetworkLogsStub = sandbox.stub();
});

afterEach(() => {
Expand Down Expand Up @@ -518,7 +525,8 @@ describe("runs", () => {
setRecordCaps: setRecordCapsStub,
setDebugMode: setDebugModeStub,
setNodeVersion: setNodeVersionStub,
setBuildTags: setBuildTagsStub
setBuildTags: setBuildTagsStub,
setNetworkLogs: setNetworkLogsStub
},
'../helpers/capabilityHelper': {
validate: capabilityValidatorStub,
Expand Down Expand Up @@ -590,6 +598,7 @@ describe("runs", () => {
sinon.assert.calledOnce(setRecordCapsStub);
sinon.assert.calledOnce(setNodeVersionStub);
sinon.assert.calledOnce(setBuildTagsStub);
sinon.assert.calledOnce(setNetworkLogsStub);
sinon.assert.calledOnceWithExactly(
sendUsageReportStub,
bsConfig,
Expand Down Expand Up @@ -660,6 +669,7 @@ describe("runs", () => {
setRecordCapsStub = sandbox.stub().returns(undefined);
setNodeVersionStub = sandbox.stub();
setBuildTagsStub = sandbox.stub();
setNetworkLogsStub = sandbox.stub();
});

afterEach(() => {
Expand Down Expand Up @@ -711,7 +721,8 @@ describe("runs", () => {
setRecordCaps: setRecordCapsStub,
setDebugMode: setDebugModeStub,
setNodeVersion: setNodeVersionStub,
setBuildTags: setBuildTagsStub
setBuildTags: setBuildTagsStub,
setNetworkLogs: setNetworkLogsStub
},
'../helpers/capabilityHelper': {
validate: capabilityValidatorStub,
Expand Down Expand Up @@ -793,7 +804,7 @@ describe("runs", () => {
sinon.assert.calledOnce(setRecordCapsStub);
sinon.assert.calledOnce(setNodeVersionStub);
sinon.assert.calledOnce(setBuildTagsStub);

sinon.assert.calledOnce(setNetworkLogsStub);
sinon.assert.calledOnceWithExactly(
sendUsageReportStub,
bsConfig,
Expand Down Expand Up @@ -877,6 +888,7 @@ describe("runs", () => {
setRecordCapsStub = sandbox.stub().returns(undefined);
setNodeVersionStub = sandbox.stub();
setBuildTagsStub = sandbox.stub();
setNetworkLogsStub = sandbox.stub();
});

afterEach(() => {
Expand Down Expand Up @@ -936,7 +948,8 @@ describe("runs", () => {
setRecordCaps: setRecordCapsStub,
setDebugMode: setDebugModeStub,
setNodeVersion: setNodeVersionStub,
setBuildTags: setBuildTagsStub
setBuildTags: setBuildTagsStub,
setNetworkLogs: setNetworkLogsStub
},
'../helpers/capabilityHelper': {
validate: capabilityValidatorStub,
Expand Down Expand Up @@ -1035,6 +1048,7 @@ describe("runs", () => {
sinon.assert.calledOnce(setRecordCapsStub);
sinon.assert.calledOnce(setNodeVersionStub);
sinon.assert.calledOnce(setBuildTagsStub);
sinon.assert.calledOnce(setNetworkLogsStub);
sinon.assert.match(
sendUsageReportStub.getCall(0).args,
[
Expand Down
46 changes: 46 additions & 0 deletions test/unit/bin/helpers/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3148,6 +3148,52 @@ describe('utils', () => {
});
});

describe('setNetworkLogs', () => {
it('should return true if networkLogs is passed as boolean true', () => {
let bsConfig = {
run_settings: { networkLogs: true }
};
let expectResult = {
run_settings: { networkLogs: 'true' }
}
utils.setNetworkLogs(bsConfig);
expect(bsConfig).to.be.eql(expectResult);
});

it('should return true if networkLogs is passed as string true', () => {
let bsConfig = {
run_settings: { networkLogs: "true" }
};
let expectResult = {
run_settings: { networkLogs: "true" }
}
utils.setNetworkLogs(bsConfig);
expect(bsConfig).to.be.eql(expectResult);
});

it('should return false if networkLogs is passed as any other non true value', () => {
let bsConfig = {
run_settings: { networkLogs: "abc" }
};
let expectResult = {
run_settings: { networkLogs: "false" }
}
utils.setNetworkLogs(bsConfig);
expect(bsConfig).to.be.eql(expectResult);
});

it('should return false if networkLogs is not passed', () => {
let bsConfig = {
run_settings: { }
};
let expectResult = {
run_settings: { networkLogs: "false" }
}
utils.setNetworkLogs(bsConfig);
expect(bsConfig).to.be.eql(expectResult);
});
});

describe('isSpecTimeoutArgPassed', () => {
let searchForOptionStub;
beforeEach(() => {
Expand Down