Skip to content
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

fix: test cases having non-deterministic behaviour #302

Merged
merged 1 commit into from
Oct 6, 2021
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
54 changes: 20 additions & 34 deletions test/services/hyperlink-utility.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ const testThisConfig = ({ platform, env, argv, stream }) => {
env: { value: env },
argv: { value: [process.argv[0], ...argv] },
});

const result = supportsHyperlink(stream);
// restore the original env
Object.defineProperties(process, {
Expand Down Expand Up @@ -76,45 +75,36 @@ describe('supportsHyperlink', () => {
}),
).to.be.false;
});
test.it('testing convertToHyperlink, supported iTerm.app 3.1, tty stream', () => {
});

describe('test for iTerm terminals', () => {
beforeEach(flush);
afterEach(() => {
process.env = ORIG_ENV;
});
test.it('testing convertToHyperlink, supported iTerm.app 3.1, tty stream', (done) => {
const result = testThisConfig({
argv: ['--hyperlink=true'],
env: {
TERM_PROGRAM: 'iTerm.app',
TERM_PROGRAM_VERSION: '3.1.0',
},
stream: {
isTTY: true,
},
});
if ('CI' in process.env) {
expect(result).to.be.false;
expect(convertToHyperlink('MORE INFO', 'https://twilio.com/docs/dummyCmd').isSupported).to.be.false;
} else {
expect(result).to.be.true;
expect(convertToHyperlink('MORE INFO', 'https://twilio.com/docs/dummyCmd').isSupported).to.be.true;
}
});
});

describe('test for iTerm terminals', () => {
afterEach(() => {
flush();
expect(result).to.be.true;
expect(convertToHyperlink('MORE INFO', 'https://twilio.com/docs/dummyCmd').isSupported).to.be.true;
});
test.it('supported in iTerm.app 3.1, tty stream', () => {
const result = testThisConfig({
env: {
FORCE_HYPERLINK: '1',
TERM_PROGRAM: 'iTerm.app',
TERM_PROGRAM_VERSION: '3.1.0',
},
stream: {
isTTY: true,
},
});
if ('CI' in process.env) {
expect(result).to.be.false;
} else {
expect(result).to.be.true;
}
expect(result).to.be.true;
});
});

Expand All @@ -139,25 +129,21 @@ describe('supportsHyperlink', () => {
});

describe('convertToHyperlink', () => {
describe('test hyperlink generation for dummyURL and dummyText on macOS', () => {
describe('test for iTerm', () => {
describe('test for iTerm', () => {
describe('test hyperlink generation for dummyURL and dummyText on macOS', () => {
beforeEach(() => {
flush();
process.env.TERM_PROGRAM = 'iTerm.app';
process.env.TERM_PROGRAM_VERSION = '3.1.0';
process.argv = ['--hyperlink=true'];
});
afterEach(() => {
flush();
process.argv = [];
process.env = ORIG_ENV;
});
testLink.cmdTestLink([]).it('test', (ctx) => {
testLink.cmdTestLink([]).it('verify the contents of dummy Command', (ctx) => {
const result = convertToHyperlink('MORE INFO', 'https://twilio.com/docs/dummyCmd').isSupported;
if ('CI' in process.env) {
Copy link
Contributor Author

@shrutiburman shrutiburman Oct 4, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the hyperlink flag --hyperlink is set to true, it'll be honoured in CI environments too. Reference.

expect(result).to.be.false;
} else {
expect(result).to.be.true;
}
expect(ctx.cmdTestLink).to.contain('MORE INFO');
expect(ctx.cmdTestLink).to.contain('https://twilio.com/docs/dummyCmd');
expect(result).to.be.true;
});
});
});
Expand Down
38 changes: 33 additions & 5 deletions test/services/twilio-api.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,32 +201,60 @@ describe('services', () => {
});

describe('getFlagConfig : checking for hyperlink in markdowns', () => {
beforeEach(flush);
afterEach(() => {
flush();
process.env = ORIG_ENV;
delete process.env.FORCE_HYPERLINK;
});

test.it('handles a description on a non-supported terminal : MAC', () => {
test.it('handles a description on a supported terminal : iTerm', () => {
process.env.TERM_PROGRAM = 'iTerm.app';
process.env.TERM_PROGRAM_VERSION = '3.1.0';
process.env.FORCE_HYPERLINK = 1;
const desc = getFlagConfig(
{
name: 'DummyCmd',
schema: {
description:
"The SID of the [Account](https://www.twilio.com/docs/iam/api/account) to which the Sim resource should belong. Account or that of a [Subaccount](https://www.twilio.com/docs/iam/api/subaccounts) of the requesting Account. Only valid when the Sim resource's status is `new`. For more information, see the [Move SIMs between Subaccounts documentation](https://www.twilio.com/docs/wireless/api/sim-resource#move-sims-between-subaccounts).",
type: 'string',
},
in: 'query',
required: false,
description:
"The SID of the [Account](https://www.twilio.com/docs/iam/api/account) to which the Sim resource should belong. Account or that of a [Subaccount](https://www.twilio.com/docs/iam/api/subaccounts) of the requesting Account. Only valid when the Sim resource's status is `new`. For more information, see the [Move SIMs between Subaccounts documentation](https://www.twilio.com/docs/wireless/api/sim-resource#move-sims-between-subaccounts).",
},
{
domainName: 'foo',
path: '/v1/Bars',
},
).description;
expect(desc).to.contain('\u001b]8;;https:');
});

test.it('handles a description which doesnt match the regex, on a supported terminal : iTerm', () => {
process.env.TERM_PROGRAM = 'iTerm.app';
process.env.TERM_PROGRAM_VERSION = '3.1.0';
expect(
getFlagConfig(
{
name: 'DummyCmd',
schema: {
description:
"The SID of the [Account](https://www.twilio.com/docs/iam/api/account) to which the Sim resource should belong. Account or that of a [Subaccount](https://www.twilio.com/docs/iam/api/subaccounts) of the requesting Account. Only valid when the Sim resource's status is `new`. For more information, see the [Move SIMs between Subaccounts documentation](https://www.twilio.com/docs/wireless/api/sim-resource#move-sims-between-subaccounts).",
'The SID of the [Account](https://www.twi lio.com/docs/iam/api/account) to which the Sim resource should belong. ',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the gap twi lio is intentional ?

Copy link
Contributor Author

@shrutiburman shrutiburman Oct 4, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's to verify the markdown regex. With space it would be an invalid markdown. This is a useful reference to verify markdowns.

type: 'string',
},
in: 'query',
required: false,
description:
"The SID of the [Account](https://www.twilio.com/docs/iam/api/account) to which the Sim resource should belong. Account or that of a [Subaccount](https://www.twilio.com/docs/iam/api/subaccounts) of the requesting Account. Only valid when the Sim resource's status is `new`. For more information, see the [Move SIMs between Subaccounts documentation](https://www.twilio.com/docs/wireless/api/sim-resource#move-sims-between-subaccounts).",
'The SID of the [Account](https://www.twi lio.com/docs/iam/api/account) to which the Sim resource should belong. ',
},
{
domainName: 'foo',
path: '/v1/Bars',
},
).description,
).to.contain('[Account](https://www.twilio.com/docs/iam/api/account)');
).to.not.contain('\u001b]8;;https:');
});

test.it('handles a description on a non-supported terminal : MAC', () => {
Expand Down